donet_core/dconfig.rs
1/*
2 This file is part of Donet.
3
4 Copyright © 2024 Max Rodriguez
5
6 Donet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Affero General Public License,
8 as published by the Free Software Foundation, either version 3
9 of the License, or (at your option) any later version.
10
11 Donet is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with Donet. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Global configuration variables for the DC parser pipeline.
21
22/// Stored in the [`crate::dcfile::DCFile`] structure.
23///
24/// Configuration variables to how the DC parser pipeline
25/// handles the semantics of the DC file(s) being read.
26#[derive(Debug, Clone)]
27pub struct DCFileConfig {
28 /// Set this true to support multiple inheritance in the dc
29 /// file. If this is false, the old way, multiple inheritance
30 /// is not supported, but field numbers will be numbered
31 /// sequentially, which may be required to support old code
32 /// that assumed this.
33 pub dc_multiple_inheritance: bool,
34 /// This is a temporary hack. This should be true if you are
35 /// using version 1.42 of the otp_server.exe binary, which
36 /// sorted inherited fields based on the order of the classes
37 /// within the DC file, rather than based on the order in
38 /// which the references are made within the class.
39 pub dc_sort_inheritance_by_file: bool,
40 /// Set this true to support proper virtual inheritance in
41 /// the dc file, so that diamond-of-death type constructs can
42 /// be used. This also enables shadowing (overloading) of
43 /// inherited method names from a base class.
44 pub dc_virtual_inheritance: bool,
45}
46
47/// Creates the config struct with Panda's defaults.
48impl Default for DCFileConfig {
49 fn default() -> Self {
50 Self {
51 dc_multiple_inheritance: true,
52 dc_sort_inheritance_by_file: true,
53 dc_virtual_inheritance: true,
54 }
55 }
56}
57
58impl std::fmt::Display for DCFileConfig {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 writeln!(f, "/*")?;
61 writeln!(f, "DC_MULTIPLE_INHERITANCE = {}", self.dc_multiple_inheritance)?;
62 writeln!(
63 f,
64 "DC_SORT_INHERITANCE_BY_FILE = {}",
65 self.dc_sort_inheritance_by_file,
66 )?;
67 writeln!(f, "DC_VIRTUAL_INHERITANCE = {}", self.dc_virtual_inheritance)?;
68 writeln!(f, "*/\n")
69 }
70}
71
72/// All DC element structures with a pointer to the
73/// DC file configuration struct should implement this.
74pub trait DCFileConfigAccessor {
75 fn get_dc_config(&self) -> &DCFileConfig;
76}