1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef CLASSCOMPILER_H
4 #define CLASSCOMPILER_H
25 enum FieldAccessorType
36 FieldAccessorType Type;
40 FieldAccessor(FieldAccessorType type, std::string accessor, bool pure)
41 : Type(type), Accessor(std::move(accessor)), Pure(pure)
45 /* keep this in sync with lib/base/type.hpp */
55 FALoadDependency = 128,
58 FANoUserModify = 1024,
63 FAActivationPriority = 32768
72 inline std::string GetRealType() const
83 inline std::string GetArgumentType() const
85 std::string realType = GetRealType();
87 if (realType == "bool" || realType == "double" || realType == "int")
90 return "const " + realType + "&";
99 std::string AlternativeName;
100 std::string GetAccessor;
101 bool PureGetAccessor{false};
102 std::string SetAccessor;
103 bool PureSetAccessor{false};
104 std::string DefaultAccessor;
105 std::string TrackAccessor;
106 std::string NavigationName;
107 std::string NavigateAccessor;
108 bool PureNavigateAccessor{false};
111 inline std::string GetFriendlyName() const
113 if (!AlternativeName.empty())
114 return AlternativeName;
117 std::string name = Name;
119 for (char& ch : name) {
132 std::remove(name.begin(), name.end(), '_'),
136 /* TODO: figure out name */
144 TAVarArgConstructor = 2
151 std::string TypeBase;
153 std::vector<Field> Fields;
154 std::vector<std::string> LoadDependencies;
155 int ActivationPriority{0};
170 std::vector<Rule> Rules;
183 std::vector<Rule> Rules;
189 ClassCompiler(std::string path, std::istream& input, std::ostream& oimpl, std::ostream& oheader);
194 std::string GetPath() const;
196 void InitializeScanner();
197 void DestroyScanner();
201 size_t ReadInput(char *buffer, size_t max_size);
203 void HandleInclude(const std::string& path, const ClassDebugInfo& locp);
204 void HandleAngleInclude(const std::string& path, const ClassDebugInfo& locp);
205 void HandleImplInclude(const std::string& path, const ClassDebugInfo& locp);
206 void HandleAngleImplInclude(const std::string& path, const ClassDebugInfo& locp);
207 void HandleClass(const Klass& klass, const ClassDebugInfo& locp);
208 void HandleValidator(const Validator& validator, const ClassDebugInfo& locp);
209 void HandleNamespaceBegin(const std::string& name, const ClassDebugInfo& locp);
210 void HandleNamespaceEnd(const ClassDebugInfo& locp);
211 void HandleCode(const std::string& code, const ClassDebugInfo& locp);
212 void HandleLibrary(const std::string& library, const ClassDebugInfo& locp);
213 void HandleMissingValidators();
215 void CodeGenValidator(const std::string& name, const std::string& klass, const std::vector<Rule>& rules, const std::string& field, const FieldType& fieldType, ValidatorType validatorType);
216 void CodeGenValidatorSubrules(const std::string& name, const std::string& klass, const std::vector<Rule>& rules);
218 static void CompileFile(const std::string& inputpath, const std::string& implpath,
219 const std::string& headerpath);
220 static void CompileStream(const std::string& path, std::istream& input,
221 std::ostream& oimpl, std::ostream& oheader);
223 static void OptimizeStructLayout(std::vector<Field>& fields);
227 std::istream& m_Input;
228 std::ostream& m_Impl;
229 std::ostream& m_Header;
232 std::string m_Library;
234 std::map<std::pair<std::string, std::string>, Field> m_MissingValidators;
236 static unsigned long SDBM(const std::string& str, size_t len);
237 static std::string BaseName(const std::string& path);
238 static std::string FileNameToGuardName(const std::string& path);
243 #endif /* CLASSCOMPILER_H */