1 /******************************************************************************
3 * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #ifndef CONFIGCOMPILER_H
21 #define CONFIGCOMPILER_H
23 #include "config/i2-config.hpp"
24 #include "config/expression.hpp"
25 #include "base/debuginfo.hpp"
26 #include "base/registry.hpp"
27 #include "base/initialize.hpp"
28 #include "base/singleton.hpp"
29 #include <boost/function.hpp>
33 typedef union YYSTYPE YYSTYPE;
34 typedef void *yyscan_t;
39 struct CompilerDebugInfo
49 operator DebugInfo(void) const
53 di.FirstLine = FirstLine;
54 di.FirstColumn = FirstColumn;
55 di.LastLine = LastLine;
56 di.LastColumn = LastColumn;
64 CompilerDebugInfo DebugInfo;
74 * The configuration compiler can be used to compile a configuration file
75 * into a number of configuration items.
79 class I2_CONFIG_API ConfigCompiler
82 explicit ConfigCompiler(const String& path, std::istream *input,
83 const String& zone = String(), const String& module = String());
84 virtual ~ConfigCompiler(void);
86 Expression *Compile(void);
88 static Expression *CompileStream(const String& path, std::istream *stream,
89 bool async = true, const String& zone = String(), const String& module = String());
90 static Expression *CompileFile(const String& path, bool async = true,
91 const String& zone = String(), const String& module = String());
92 static Expression *CompileText(const String& path, const String& text,
93 bool async = true, const String& zone = String(), const String& module = String());
95 static void AddIncludeSearchDir(const String& dir);
97 const char *GetPath(void) const;
99 void SetZone(const String& zone);
100 String GetZone(void) const;
102 void SetModule(const String& module);
103 String GetModule(void) const;
105 static void CollectIncludes(std::vector<Expression *>& expressions,
106 const String& file, const String& zone, const String& module);
108 /* internally used methods */
109 Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
110 Expression *HandleIncludeRecursive(const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
111 Expression *HandleIncludeZones(const String& tag, const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
112 void HandleLibrary(const String& library);
114 size_t ReadInput(char *buffer, size_t max_bytes);
115 void *GetScanner(void) const;
117 static std::vector<ZoneFragment> GetZoneDirs(const String& zone);
118 static void RegisterZoneDir(const String& tag, const String& ppath, const String& zoneName);
120 static const std::vector<String>& GetKeywords(void);
123 boost::promise<boost::shared_ptr<Expression> > m_Promise;
126 std::istream *m_Input;
132 static std::vector<String> m_IncludeSearchDirs;
133 static std::map<String, std::vector<ZoneFragment> > m_ZoneDirs;
135 void InitializeScanner(void);
136 void DestroyScanner(void);
138 void HandleIncludeZone(const String& tag, const String& path, const String& pattern, std::vector<Expression *>& expressions);
144 int m_IgnoreNewlines;
145 std::ostringstream m_LexBuffer;
146 CompilerDebugInfo m_LocationBegin;
148 std::stack<bool> m_Apply;
149 std::stack<bool> m_ObjectAssign;
150 std::stack<bool> m_SeenAssign;
151 std::stack<bool> m_SeenIgnore;
152 std::stack<Expression *> m_Assign;
153 std::stack<Expression *> m_Ignore;
154 std::stack<String> m_FKVar;
155 std::stack<String> m_FVVar;
156 std::stack<Expression *> m_FTerm;
161 #endif /* CONFIGCOMPILER_H */