codegen/codegen.cpp

Thu, 29 Mar 2018 12:09:03 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 29 Mar 2018 12:09:03 +0300
branch
experimental
changeset 1354
2c013e1d604b
parent 861
83426c5fa732
child 968
4b93b7963456
permissions
-rw-r--r--

Branch close bfc

845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013, 2014 Teemu Piippo
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <sstream>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <fstream>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <string>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <cstring>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <iostream>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <vector>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <algorithm>
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 using std::string;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 using std::vector;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 using std::ifstream;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 using std::size_t;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 using std::strncmp;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 using std::getline;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 using std::cout;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 using std::endl;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
36 struct EntryType
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 string name;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 string type;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 string defvalue;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
42 inline bool operator< (EntryType const& other) const
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 return name < other.name;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
47 inline bool operator== (EntryType const& other) const
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 return name == other.name and type == other.type;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
52 inline bool operator!= (EntryType const& other) const
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 return not operator== (other);
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 };
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
58 char AdvancePointer (char const*& ptr)
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 char a = *ptr++;
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
61
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 if (*ptr == '\0')
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 throw false;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 return a;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
68 void ReadConfigEntries (string const& filename, vector<EntryType>& entries, const char* macroname)
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 ifstream is (filename.c_str());
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 string line;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 size_t const macrolen = strlen (macroname);
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 while (getline (is, line))
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 try
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 if (strncmp (line.c_str(), macroname, macrolen) != 0)
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 continue;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 char const* ptr = &line[macrolen];
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
82 EntryType entry;
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 // Skip to paren
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 while (*ptr != '(')
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
86 AdvancePointer (ptr);
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 // Skip whitespace
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 while (isspace (*ptr))
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
90 AdvancePointer (ptr);
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 // Skip paren
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
93 AdvancePointer (ptr);
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 // Read type
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 while (*ptr != ',')
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
97 entry.type += AdvancePointer (ptr);
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 // Skip comma and whitespace
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
100 for (AdvancePointer (ptr); isspace (*ptr); AdvancePointer (ptr))
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 ;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // Read name
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 while (*ptr != ',')
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
105 entry.name += AdvancePointer (ptr);
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 // Skip comma and whitespace
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
108 for (AdvancePointer (ptr); isspace (*ptr); AdvancePointer (ptr))
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 ;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // Read default
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 while (*ptr != ')')
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
113 entry.defvalue += AdvancePointer (ptr);
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 entries.push_back (entry);
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 catch (bool) {}
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
121 bool CheckEquality (vector<EntryType> a, vector<EntryType> b)
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 if (a.size() != b.size())
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 return false;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 std::sort (a.begin(), a.end());
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 std::sort (b.begin(), b.end());
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 for (size_t i = 0; i < a.size(); ++i)
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 if (a[i] != b[i])
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 return false;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 return true;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 int main (int argc, char* argv[])
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
140 vector<EntryType> entries;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
141 vector<EntryType> oldentries;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
142 ReadConfigEntries (argv[argc - 1], oldentries, "CODEGEN_CACHE");
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 for (int arg = 1; arg < argc - 1; ++arg)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
145 ReadConfigEntries (argv[arg], entries, "CFGENTRY");
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
147 if (CheckEquality (entries, oldentries))
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 {
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 cout << "Configuration options unchanged" << endl;
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
150 return 0;
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
153 std::ofstream os (argv[argc - 1]);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
154 os << "#pragma once" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
155 os << "#define CODEGEN_CACHE(A,B,C)" << endl;
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
157 for (vector<EntryType>::const_iterator it = entries.begin(); it != entries.end(); ++it)
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
158 {
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
159 os << "CODEGEN_CACHE (" << it->type << ", " << it->name << ", " <<
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
160 it->defvalue << ")" << endl;
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
163 os << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
164 for (vector<EntryType>::const_iterator it = entries.begin(); it != entries.end(); ++it)
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
165 os << "EXTERN_CFGENTRY (" << it->type << ", " << it->name << ")" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
166
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
167 os << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
168 os << "static void InitConfigurationEntry (AbstractConfigEntry* entry);" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
169 os << "static void SetupConfigurationLists()" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
170 os << "{" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
171
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
172 for (vector<EntryType>::const_iterator it = entries.begin(); it != entries.end(); ++it)
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
173 {
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
174 os << "\tInitConfigurationEntry (new " << it->type << "ConfigEntry (&cfg::" <<
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
175 it->name << ", \"" << it->name << "\", " << it->defvalue << "));" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
176 }
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
177
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
178 os << "}" << endl;
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
179 cout << "Wrote configuration options list to " << argv[argc - 1] << "." << endl;
845
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 return 0;
fec7023e91a7 - added a code generator to produce a configuration.inc which replaces the old, DIABOLIC configuration indexing mechanism
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 }

mercurial