1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef CONFIGCOMPILER_H
4 #define CONFIGCOMPILER_H
6 #include "config/i2-config.hpp"
7 #include "config/expression.hpp"
8 #include "base/debuginfo.hpp"
9 #include "base/registry.hpp"
10 #include "base/initialize.hpp"
11 #include "base/singleton.hpp"
16 typedef union YYSTYPE YYSTYPE;
17 typedef void *yyscan_t;
22 struct CompilerDebugInfo
32 operator DebugInfo() const
36 di.FirstLine = FirstLine;
37 di.FirstColumn = FirstColumn;
38 di.LastLine = LastLine;
39 di.LastColumn = LastColumn;
47 CompilerDebugInfo DebugInfo;
52 FlowControlReturn = 1,
53 FlowControlContinue = 2,
64 * The configuration compiler can be used to compile a configuration file
65 * into a number of configuration items.
72 explicit ConfigCompiler(String path, std::istream *input,
73 String zone = String(), String package = String());
74 virtual ~ConfigCompiler();
76 std::unique_ptr<Expression> Compile();
78 static std::unique_ptr<Expression>CompileStream(const String& path, std::istream *stream,
79 const String& zone = String(), const String& package = String());
80 static std::unique_ptr<Expression>CompileFile(const String& path, const String& zone = String(),
81 const String& package = String());
82 static std::unique_ptr<Expression>CompileText(const String& path, const String& text,
83 const String& zone = String(), const String& package = String());
85 static void AddIncludeSearchDir(const String& dir);
87 const char *GetPath() const;
89 void SetZone(const String& zone);
90 String GetZone() const;
92 void SetPackage(const String& package);
93 String GetPackage() const;
95 void AddImport(const std::shared_ptr<Expression>& import);
96 std::vector<std::shared_ptr<Expression> > GetImports() const;
98 static void CollectIncludes(std::vector<std::unique_ptr<Expression> >& expressions,
99 const String& file, const String& zone, const String& package);
101 static std::unique_ptr<Expression> HandleInclude(const String& relativeBase, const String& path, bool search,
102 const String& zone, const String& package, const DebugInfo& debuginfo = DebugInfo());
103 static std::unique_ptr<Expression> HandleIncludeRecursive(const String& relativeBase, const String& path,
104 const String& pattern, const String& zone, const String& package, const DebugInfo& debuginfo = DebugInfo());
105 static std::unique_ptr<Expression> HandleIncludeZones(const String& relativeBase, const String& tag,
106 const String& path, const String& pattern, const String& package, const DebugInfo& debuginfo = DebugInfo());
108 size_t ReadInput(char *buffer, size_t max_bytes);
109 void *GetScanner() const;
111 static std::vector<ZoneFragment> GetZoneDirs(const String& zone);
112 static void RegisterZoneDir(const String& tag, const String& ppath, const String& zoneName);
114 static bool HasZoneConfigAuthority(const String& zoneName);
117 std::promise<std::shared_ptr<Expression> > m_Promise;
120 std::istream *m_Input;
123 std::vector<std::shared_ptr<Expression> > m_Imports;
127 static std::vector<String> m_IncludeSearchDirs;
128 static boost::mutex m_ZoneDirsMutex;
129 static std::map<String, std::vector<ZoneFragment> > m_ZoneDirs;
131 void InitializeScanner();
132 void DestroyScanner();
134 static void HandleIncludeZone(const String& relativeBase, const String& tag, const String& path, const String& pattern, const String& package, std::vector<std::unique_ptr<Expression> >& expressions);
136 static bool IsAbsolutePath(const String& path);
142 std::ostringstream m_LexBuffer;
143 CompilerDebugInfo m_LocationBegin;
145 std::stack<bool> m_IgnoreNewlines;
146 std::stack<bool> m_Apply;
147 std::stack<bool> m_ObjectAssign;
148 std::stack<bool> m_SeenAssign;
149 std::stack<bool> m_SeenIgnore;
150 std::stack<Expression *> m_Assign;
151 std::stack<Expression *> m_Ignore;
152 std::stack<String> m_FKVar;
153 std::stack<String> m_FVVar;
154 std::stack<Expression *> m_FTerm;
155 std::stack<int> m_FlowControlInfo;
160 #endif /* CONFIGCOMPILER_H */