Implemented additional parts of the config compiler.

This commit is contained in:
Gunnar Beutner 2012-06-05 15:05:15 +02:00
parent 9c3e57c858
commit 9b8fd9755b
25 changed files with 716 additions and 615 deletions

View File

@ -27,6 +27,7 @@ using namespace icinga;
Application::Ptr I2_EXPORT Application::m_Instance; Application::Ptr I2_EXPORT Application::m_Instance;
bool I2_EXPORT Application::m_ShuttingDown = false; bool I2_EXPORT Application::m_ShuttingDown = false;
bool I2_EXPORT Application::m_Debugging = false;
/** /**
* Constructor for the Application class. * Constructor for the Application class.
@ -416,7 +417,7 @@ void Application::AddComponentSearchDir(const string& componentDirectory)
* *
* @returns true if the application is being debugged, false otherwise * @returns true if the application is being debugged, false otherwise
*/ */
bool Application::IsDebugging(void) const bool Application::IsDebugging(void)
{ {
return m_Debugging; return m_Debugging;
} }

View File

@ -56,7 +56,7 @@ public:
shared_ptr<Component> GetComponent(const string& name) const; shared_ptr<Component> GetComponent(const string& name) const;
void AddComponentSearchDir(const string& componentDirectory); void AddComponentSearchDir(const string& componentDirectory);
bool IsDebugging(void) const; static bool IsDebugging(void);
protected: protected:
void RunEventLoop(void); void RunEventLoop(void);
@ -71,7 +71,7 @@ private:
map< string, shared_ptr<Component> > m_Components; /**< Components that map< string, shared_ptr<Component> > m_Components; /**< Components that
were loaded by the application. */ were loaded by the application. */
vector<string> m_Arguments; /**< Command-line arguments */ vector<string> m_Arguments; /**< Command-line arguments */
bool m_Debugging; /**< Whether debugging is enabled. */ static bool m_Debugging; /**< Whether debugging is enabled. */
#ifndef _WIN32 #ifndef _WIN32
static void SigIntHandler(int signum); static void SigIntHandler(int signum);

View File

@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*yy_cp = '\0'; \ *yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp; yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 27 #define YY_NUM_RULES 30
#define YY_END_OF_BUFFER 28 #define YY_END_OF_BUFFER 31
/* This struct is not used in this scanner, /* This struct is not used in this scanner,
but its presence is necessary. */ but its presence is necessary. */
struct yy_trans_info struct yy_trans_info
@ -379,16 +379,16 @@ struct yy_trans_info
flex_int32_t yy_verify; flex_int32_t yy_verify;
flex_int32_t yy_nxt; flex_int32_t yy_nxt;
}; };
static yyconst flex_int16_t yy_accept[76] = static yyconst flex_int16_t yy_accept[79] =
{ 0, { 0,
0, 0, 0, 0, 28, 27, 26, 27, 27, 27, 0, 0, 0, 0, 31, 29, 28, 28, 29, 29,
27, 14, 7, 27, 9, 15, 7, 12, 13, 7, 10, 11, 29, 29, 16, 7, 29, 9, 17, 7,
7, 7, 7, 7, 10, 11, 22, 23, 26, 0, 14, 15, 7, 7, 7, 7, 7, 12, 13, 24,
25, 18, 16, 7, 17, 20, 0, 19, 9, 7, 25, 28, 0, 27, 20, 18, 7, 19, 22, 0,
7, 7, 7, 7, 22, 21, 8, 24, 7, 7, 21, 9, 7, 7, 7, 7, 7, 24, 23, 8,
7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 26, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 2, 7, 7, 7, 7, 3, 7, 7, 6, 7, 7, 7, 7, 2, 7, 7, 7,
4, 7, 1, 5, 0 7, 3, 7, 4, 7, 1, 5, 0
} ; } ;
static yyconst flex_int32_t yy_ec[256] = static yyconst flex_int32_t yy_ec[256] =
@ -396,17 +396,17 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 4, 5, 1, 1, 1, 1, 1, 1, 2, 1, 4, 5, 1, 1, 1, 1, 6,
1, 6, 7, 8, 9, 1, 10, 11, 11, 11, 7, 8, 9, 10, 11, 1, 12, 13, 13, 13,
11, 11, 11, 11, 11, 11, 11, 1, 1, 1, 13, 13, 13, 13, 13, 13, 13, 1, 1, 1,
12, 1, 1, 1, 13, 13, 13, 13, 13, 13, 14, 1, 1, 1, 15, 15, 15, 15, 15, 15,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
14, 1, 15, 1, 13, 1, 16, 17, 18, 19, 16, 1, 17, 1, 15, 1, 18, 19, 20, 21,
20, 13, 13, 21, 22, 23, 13, 24, 13, 25, 22, 15, 15, 23, 24, 25, 15, 26, 15, 27,
26, 13, 13, 27, 28, 29, 30, 13, 13, 13, 28, 15, 15, 29, 30, 31, 32, 15, 15, 15,
13, 13, 31, 1, 32, 1, 1, 1, 1, 1, 15, 15, 33, 1, 34, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -423,91 +423,91 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static yyconst flex_int32_t yy_meta[33] = static yyconst flex_int32_t yy_meta[35] =
{ 0, { 0,
1, 1, 2, 3, 1, 4, 1, 1, 5, 1, 1, 1, 2, 3, 1, 1, 1, 4, 1, 1,
5, 5, 5, 1, 1, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 1, 1, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1, 1 5, 5, 1, 1
} ; } ;
static yyconst flex_int16_t yy_base[82] = static yyconst flex_int16_t yy_base[85] =
{ 0, { 0,
0, 0, 134, 133, 138, 141, 31, 0, 0, 122, 0, 0, 136, 135, 142, 145, 33, 35, 0, 0,
119, 141, 112, 29, 109, 141, 97, 141, 141, 25, 145, 145, 124, 121, 145, 114, 31, 111, 145, 99,
24, 26, 28, 31, 141, 141, 0, 98, 42, 103, 145, 145, 27, 26, 28, 30, 33, 145, 145, 0,
0, 141, 141, 94, 141, 141, 0, 141, 94, 34, 100, 46, 107, 0, 145, 145, 96, 145, 145, 0,
35, 39, 42, 38, 0, 141, 141, 0, 43, 47, 145, 96, 36, 37, 41, 44, 40, 0, 145, 145,
48, 51, 52, 53, 57, 58, 62, 63, 92, 65, 0, 45, 49, 50, 53, 54, 55, 59, 60, 64,
66, 67, 68, 91, 69, 73, 80, 81, 90, 82, 65, 94, 67, 68, 69, 70, 93, 71, 75, 82,
89, 84, 87, 85, 141, 112, 117, 122, 90, 127, 83, 92, 84, 91, 86, 89, 87, 145, 116, 121,
132 126, 94, 131, 136
} ; } ;
static yyconst flex_int16_t yy_def[82] = static yyconst flex_int16_t yy_def[85] =
{ 0, { 0,
75, 1, 76, 76, 75, 75, 75, 77, 78, 75, 78, 1, 79, 79, 78, 78, 78, 78, 80, 81,
75, 75, 79, 75, 75, 75, 79, 75, 75, 79, 78, 78, 78, 78, 78, 82, 78, 78, 78, 82,
79, 79, 79, 79, 75, 75, 80, 75, 75, 77, 78, 78, 82, 82, 82, 82, 82, 78, 78, 83,
78, 75, 75, 79, 75, 75, 81, 75, 75, 79, 78, 78, 80, 81, 78, 78, 82, 78, 78, 84,
79, 79, 79, 79, 80, 75, 75, 81, 79, 79, 78, 78, 82, 82, 82, 82, 82, 83, 78, 78,
79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 84, 82, 82, 82, 82, 82, 82, 82, 82, 82,
79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
79, 79, 79, 79, 0, 75, 75, 75, 75, 75, 82, 82, 82, 82, 82, 82, 82, 0, 78, 78,
75 78, 78, 78, 78
} ; } ;
static yyconst flex_int16_t yy_nxt[174] = static yyconst flex_int16_t yy_nxt[180] =
{ 0, { 0,
6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
15, 16, 17, 18, 19, 20, 17, 17, 17, 17, 16, 17, 18, 19, 20, 21, 22, 23, 20, 20,
17, 21, 17, 22, 23, 24, 17, 17, 17, 17, 20, 20, 20, 24, 20, 25, 26, 27, 20, 20,
25, 26, 29, 29, 36, 75, 75, 75, 37, 75, 20, 20, 28, 29, 32, 32, 32, 32, 39, 78,
38, 40, 75, 29, 29, 75, 75, 44, 41, 75, 78, 78, 40, 78, 41, 43, 78, 32, 32, 78,
75, 42, 50, 75, 75, 51, 52, 43, 75, 75, 78, 47, 44, 78, 78, 45, 53, 78, 78, 54,
54, 49, 75, 75, 75, 53, 58, 57, 75, 75, 55, 46, 78, 78, 57, 52, 78, 78, 78, 56,
56, 55, 60, 75, 75, 59, 75, 75, 75, 75, 61, 60, 78, 78, 59, 58, 63, 78, 78, 62,
75, 66, 65, 61, 75, 67, 64, 62, 63, 68, 78, 78, 78, 78, 78, 69, 68, 64, 78, 70,
70, 75, 75, 75, 34, 75, 75, 69, 75, 71, 67, 65, 66, 71, 73, 78, 78, 78, 37, 78,
75, 75, 75, 75, 39, 75, 47, 46, 75, 72, 78, 72, 78, 74, 78, 78, 78, 78, 42, 78,
73, 74, 27, 27, 27, 27, 27, 30, 30, 39, 50, 49, 78, 75, 76, 77, 30, 30, 30, 30,
30, 30, 31, 35, 31, 31, 31, 45, 45, 45, 30, 33, 33, 42, 33, 33, 34, 38, 34, 34,
33, 45, 48, 32, 48, 48, 48, 75, 28, 28, 34, 48, 48, 48, 36, 48, 51, 35, 51, 51,
5, 75, 75, 75, 75, 75, 75, 75, 75, 75, 51, 78, 31, 31, 5, 78, 78, 78, 78, 78,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
75, 75, 75 78, 78, 78, 78, 78, 78, 78, 78, 78
} ; } ;
static yyconst flex_int16_t yy_chk[174] = static yyconst flex_int16_t yy_chk[180] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 7, 7, 14, 21, 20, 22, 14, 23, 1, 1, 1, 1, 7, 7, 8, 8, 17, 24,
14, 20, 24, 29, 29, 40, 41, 24, 21, 44, 23, 25, 17, 26, 17, 23, 27, 32, 32, 43,
42, 22, 41, 43, 49, 41, 42, 23, 50, 51, 44, 27, 24, 47, 45, 25, 44, 46, 52, 44,
44, 40, 52, 53, 54, 43, 52, 51, 55, 56, 45, 26, 53, 54, 47, 43, 55, 56, 57, 46,
50, 49, 54, 57, 58, 53, 60, 61, 62, 63, 55, 54, 58, 59, 53, 52, 57, 60, 61, 56,
65, 61, 60, 55, 66, 62, 58, 56, 57, 63, 63, 64, 65, 66, 68, 64, 63, 58, 69, 65,
66, 67, 68, 70, 79, 72, 74, 65, 73, 67, 61, 59, 60, 66, 69, 70, 71, 73, 82, 75,
71, 69, 64, 59, 39, 34, 30, 28, 17, 68, 77, 68, 76, 70, 74, 72, 67, 62, 42, 37,
70, 72, 76, 76, 76, 76, 76, 77, 77, 15, 33, 31, 20, 71, 73, 75, 79, 79, 79, 79,
77, 77, 78, 13, 78, 78, 78, 80, 80, 80, 79, 80, 80, 18, 80, 80, 81, 16, 81, 81,
11, 80, 81, 10, 81, 81, 81, 5, 4, 3, 81, 83, 83, 83, 14, 83, 84, 13, 84, 84,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 84, 5, 4, 3, 78, 78, 78, 78, 78, 78,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
75, 75, 75 78, 78, 78, 78, 78, 78, 78, 78, 78
} ; } ;
/* Table of booleans, true if rule could match eol. */ /* Table of booleans, true if rule could match eol. */
static yyconst flex_int32_t yy_rule_can_match_eol[28] = static yyconst flex_int32_t yy_rule_can_match_eol[31] =
{ 0, { 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0, }; 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, };
/* The intent behind this definition is that it'll catch /* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed. * any uses of REJECT which flex missed.
@ -857,13 +857,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 76 ) if ( yy_current_state >= 79 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_current_state != 75 ); while ( yy_current_state != 78 );
yy_cp = yyg->yy_last_accepting_cpos; yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state; yy_current_state = yyg->yy_last_accepting_state;
@ -944,100 +944,115 @@ YY_RULE_SETUP
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 51 "config_lexer.ll" #line 51 "config_lexer.ll"
return T_OPEN_BRACE; return T_OPEN_PARENTHESIS;
YY_BREAK YY_BREAK
case 11: case 11:
YY_RULE_SETUP YY_RULE_SETUP
#line 52 "config_lexer.ll" #line 52 "config_lexer.ll"
return T_CLOSE_BRACE; return T_CLOSE_PARENTHESIS;
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 53 "config_lexer.ll" #line 53 "config_lexer.ll"
return T_OPEN_BRACKET; return T_OPEN_BRACE;
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 54 "config_lexer.ll" #line 54 "config_lexer.ll"
return T_CLOSE_BRACKET; return T_CLOSE_BRACE;
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 55 "config_lexer.ll" #line 55 "config_lexer.ll"
return T_COMMA; return T_OPEN_BRACKET;
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 56 "config_lexer.ll" #line 56 "config_lexer.ll"
{ yylval->op = OperatorSet; return T_EQUAL; } return T_CLOSE_BRACKET;
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 57 "config_lexer.ll" #line 57 "config_lexer.ll"
{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; } return T_COMMA;
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 58 "config_lexer.ll" #line 58 "config_lexer.ll"
{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; } { yylval->op = OperatorSet; return T_EQUAL; }
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
#line 59 "config_lexer.ll" #line 59 "config_lexer.ll"
{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; } { yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 60 "config_lexer.ll" #line 60 "config_lexer.ll"
{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
YY_BREAK
case 20:
YY_RULE_SETUP
#line 61 "config_lexer.ll"
{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
YY_BREAK
case 21:
YY_RULE_SETUP
#line 62 "config_lexer.ll"
{ yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; } { yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
YY_BREAK YY_BREAK
case 20: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 63 "config_lexer.ll" #line 65 "config_lexer.ll"
BEGIN(IN_C_COMMENT); BEGIN(IN_C_COMMENT);
YY_BREAK YY_BREAK
case 21:
YY_RULE_SETUP
#line 67 "config_lexer.ll"
BEGIN(INITIAL);
YY_BREAK
case 22:
/* rule 22 can match eol */
YY_RULE_SETUP
#line 68 "config_lexer.ll"
/* ignore comment */
YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 69 "config_lexer.ll" #line 69 "config_lexer.ll"
/* ignore star */ BEGIN(INITIAL);
YY_BREAK YY_BREAK
case 24: case 24:
/* rule 24 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 72 "config_lexer.ll" #line 70 "config_lexer.ll"
/* ignore C++-style comments */ /* ignore comment */
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 73 "config_lexer.ll" #line 71 "config_lexer.ll"
/* ignore shell-style comments */ /* ignore star */
YY_BREAK YY_BREAK
case 26: case 26:
/* rule 26 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 74 "config_lexer.ll" #line 74 "config_lexer.ll"
/* ignore whitespace */ /* ignore C++-style comments */
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 75 "config_lexer.ll" #line 75 "config_lexer.ll"
/* ignore shell-style comments */
YY_BREAK
case 28:
/* rule 28 can match eol */
YY_RULE_SETUP
#line 76 "config_lexer.ll"
/* ignore whitespace */
YY_BREAK
case 29:
YY_RULE_SETUP
#line 78 "config_lexer.ll"
return yytext[0];
YY_BREAK
case 30:
YY_RULE_SETUP
#line 79 "config_lexer.ll"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 1041 "config_lexer.cc" #line 1056 "config_lexer.cc"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(IN_C_COMMENT): case YY_STATE_EOF(IN_C_COMMENT):
yyterminate(); yyterminate();
@ -1333,7 +1348,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 76 ) if ( yy_current_state >= 79 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1362,11 +1377,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 76 ) if ( yy_current_state >= 79 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 75); yy_is_jam = (yy_current_state == 78);
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
@ -2225,7 +2240,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
#line 75 "config_lexer.ll" #line 79 "config_lexer.ll"

View File

@ -48,6 +48,8 @@ null return T_NULL;
[a-zA-Z\-_][a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; } [a-zA-Z\-_][a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
\"[^\"]+\" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; } \"[^\"]+\" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; }
[0-9]+ { yylval->num = atoi(yytext); return T_NUMBER; } [0-9]+ { yylval->num = atoi(yytext); return T_NUMBER; }
\( return T_OPEN_PARENTHESIS;
\) return T_CLOSE_PARENTHESIS;
\{ return T_OPEN_BRACE; \{ return T_OPEN_BRACE;
\} return T_CLOSE_BRACE; \} return T_CLOSE_BRACE;
\[ return T_OPEN_BRACKET; \[ return T_OPEN_BRACKET;
@ -72,6 +74,8 @@ null return T_NULL;
\/\/[^\n]+ /* ignore C++-style comments */ \/\/[^\n]+ /* ignore C++-style comments */
#[^\n]+ /* ignore shell-style comments */ #[^\n]+ /* ignore shell-style comments */
[ \t\n]+ /* ignore whitespace */ [ \t\n]+ /* ignore whitespace */
. return yytext[0];
%% %%

View File

@ -125,21 +125,23 @@ using namespace icinga;
T_NUMBER = 259, T_NUMBER = 259,
T_NULL = 260, T_NULL = 260,
T_IDENTIFIER = 261, T_IDENTIFIER = 261,
T_OPEN_BRACE = 262, T_OPEN_PARENTHESIS = 262,
T_CLOSE_BRACE = 263, T_CLOSE_PARENTHESIS = 263,
T_OPEN_BRACKET = 264, T_OPEN_BRACE = 264,
T_CLOSE_BRACKET = 265, T_CLOSE_BRACE = 265,
T_EQUAL = 266, T_OPEN_BRACKET = 266,
T_PLUS_EQUAL = 267, T_CLOSE_BRACKET = 267,
T_MINUS_EQUAL = 268, T_EQUAL = 268,
T_MULTIPLY_EQUAL = 269, T_PLUS_EQUAL = 269,
T_DIVIDE_EQUAL = 270, T_MINUS_EQUAL = 270,
T_COMMA = 271, T_MULTIPLY_EQUAL = 271,
T_ABSTRACT = 272, T_DIVIDE_EQUAL = 272,
T_LOCAL = 273, T_COMMA = 273,
T_OBJECT = 274, T_ABSTRACT = 274,
T_INCLUDE = 275, T_LOCAL = 275,
T_INHERITS = 276 T_OBJECT = 276,
T_INCLUDE = 277,
T_INHERITS = 278
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
@ -147,21 +149,23 @@ using namespace icinga;
#define T_NUMBER 259 #define T_NUMBER 259
#define T_NULL 260 #define T_NULL 260
#define T_IDENTIFIER 261 #define T_IDENTIFIER 261
#define T_OPEN_BRACE 262 #define T_OPEN_PARENTHESIS 262
#define T_CLOSE_BRACE 263 #define T_CLOSE_PARENTHESIS 263
#define T_OPEN_BRACKET 264 #define T_OPEN_BRACE 264
#define T_CLOSE_BRACKET 265 #define T_CLOSE_BRACE 265
#define T_EQUAL 266 #define T_OPEN_BRACKET 266
#define T_PLUS_EQUAL 267 #define T_CLOSE_BRACKET 267
#define T_MINUS_EQUAL 268 #define T_EQUAL 268
#define T_MULTIPLY_EQUAL 269 #define T_PLUS_EQUAL 269
#define T_DIVIDE_EQUAL 270 #define T_MINUS_EQUAL 270
#define T_COMMA 271 #define T_MULTIPLY_EQUAL 271
#define T_ABSTRACT 272 #define T_DIVIDE_EQUAL 272
#define T_LOCAL 273 #define T_COMMA 273
#define T_OBJECT 274 #define T_ABSTRACT 274
#define T_INCLUDE 275 #define T_LOCAL 275
#define T_INHERITS 276 #define T_OBJECT 276
#define T_INCLUDE 277
#define T_INHERITS 278
@ -181,7 +185,7 @@ typedef union YYSTYPE
/* Line 293 of yacc.c */ /* Line 293 of yacc.c */
#line 185 "config_parser.cc" #line 189 "config_parser.cc"
} YYSTYPE; } YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -205,7 +209,7 @@ typedef struct YYLTYPE
/* Copy the second part of user declarations. */ /* Copy the second part of user declarations. */
/* Line 343 of yacc.c */ /* Line 343 of yacc.c */
#line 69 "config_parser.yy" #line 71 "config_parser.yy"
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
@ -232,17 +236,15 @@ void ConfigContext::Compile(void)
#define scanner (context->GetScanner()) #define scanner (context->GetScanner())
static stack<ExpressionList::Ptr> m_ExpressionLists; static stack<ExpressionList::Ptr> m_ExpressionLists;
static map<pair<string, string>, DConfigObject::Ptr> m_Objects; static set<DConfigObject::Ptr> m_Objects;
static DConfigObject::Ptr m_Object; static DConfigObject::Ptr m_Object;
static string m_Name;
static string m_Type;
static bool m_Abstract; static bool m_Abstract;
static bool m_Local; static bool m_Local;
static Dictionary::Ptr m_Array; static Dictionary::Ptr m_Array;
/* Line 343 of yacc.c */ /* Line 343 of yacc.c */
#line 246 "config_parser.cc" #line 248 "config_parser.cc"
#ifdef short #ifdef short
# undef short # undef short
@ -466,17 +468,17 @@ union yyalloc
#define YYLAST 46 #define YYLAST 46
/* YYNTOKENS -- Number of terminals. */ /* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 26 #define YYNTOKENS 28
/* YYNNTS -- Number of nonterminals. */ /* YYNNTS -- Number of nonterminals. */
#define YYNNTS 22 #define YYNNTS 23
/* YYNRULES -- Number of rules. */ /* YYNRULES -- Number of rules. */
#define YYNRULES 42 #define YYNRULES 43
/* YYNRULES -- Number of states. */ /* YYNRULES -- Number of states. */
#define YYNSTATES 59 #define YYNSTATES 60
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2 #define YYUNDEFTOK 2
#define YYMAXUTOK 276 #define YYMAXUTOK 278
#define YYTRANSLATE(YYX) \ #define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@ -488,7 +490,7 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 24, 22, 2, 23, 2, 25, 2, 2, 2, 2, 26, 24, 2, 25, 2, 27, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@ -511,7 +513,7 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21 15, 16, 17, 18, 19, 20, 21, 22, 23
}; };
#if YYDEBUG #if YYDEBUG
@ -523,33 +525,33 @@ static const yytype_uint8 yyprhs[] =
25, 26, 29, 31, 33, 35, 39, 41, 42, 45, 25, 26, 29, 31, 33, 35, 39, 41, 42, 45,
46, 51, 52, 54, 58, 62, 69, 71, 73, 75, 46, 51, 52, 54, 58, 62, 69, 71, 73, 75,
77, 79, 81, 83, 85, 87, 89, 91, 93, 94, 77, 79, 81, 83, 85, 87, 89, 91, 93, 94,
99, 100, 102 99, 101, 102, 104
}; };
/* YYRHS -- A `-1'-separated list of the rules' RHS. */ /* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] = static const yytype_int8 yyrhs[] =
{ {
27, 0, -1, -1, 27, 28, -1, 30, -1, 29, 29, 0, -1, -1, 29, 30, -1, 32, -1, 31,
-1, 20, 3, -1, -1, -1, 31, 33, 19, 6, -1, 22, 3, -1, -1, -1, 33, 35, 21, 6,
3, 32, 37, 38, -1, -1, 33, 34, -1, 17, 3, 34, 39, 40, -1, -1, 35, 36, -1, 19,
-1, 18, -1, 36, -1, 35, 16, 36, -1, 3, -1, 20, -1, 38, -1, 37, 18, 38, -1, 3,
-1, -1, 21, 35, -1, -1, 7, 39, 40, 8, -1, -1, 23, 37, -1, -1, 9, 41, 42, 10,
-1, -1, 41, -1, 40, 16, 41, -1, 6, 42, -1, -1, 43, -1, 43, 18, 42, -1, 6, 44,
44, -1, 6, 9, 3, 10, 42, 44, -1, 3, 46, -1, 6, 11, 3, 12, 44, 46, -1, 3,
-1, 11, -1, 12, -1, 13, -1, 14, -1, 15, -1, 13, -1, 14, -1, 15, -1, 16, -1, 17,
-1, 3, -1, 4, -1, 5, -1, 43, -1, 45, -1, 3, -1, 4, -1, 5, -1, 45, -1, 47,
-1, 38, -1, -1, 9, 46, 47, 10, -1, -1, -1, 40, -1, -1, 7, 48, 50, 8, -1, 45,
43, -1, 47, 16, 43, -1 -1, -1, 49, -1, 49, 18, 50, -1
}; };
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] = static const yytype_uint16 yyrline[] =
{ {
0, 105, 105, 106, 112, 112, 115, 119, 125, 119, 0, 105, 105, 106, 112, 112, 115, 119, 124, 119,
159, 160, 163, 167, 173, 174, 177, 183, 184, 188, 155, 156, 159, 163, 169, 170, 173, 179, 180, 184,
187, 199, 200, 201, 204, 212, 225, 234, 235, 236, 183, 195, 196, 197, 200, 208, 221, 230, 231, 232,
237, 238, 244, 248, 252, 258, 259, 260, 267, 266, 233, 234, 240, 244, 248, 254, 255, 256, 263, 262,
278, 280, 285 274, 280, 282, 283
}; };
#endif #endif
@ -559,15 +561,16 @@ static const yytype_uint16 yyrline[] =
static const char *const yytname[] = static const char *const yytname[] =
{ {
"$end", "error", "$undefined", "T_STRING", "T_NUMBER", "T_NULL", "$end", "error", "$undefined", "T_STRING", "T_NUMBER", "T_NULL",
"T_IDENTIFIER", "T_OPEN_BRACE", "T_CLOSE_BRACE", "T_OPEN_BRACKET", "T_IDENTIFIER", "T_OPEN_PARENTHESIS", "T_CLOSE_PARENTHESIS",
"T_CLOSE_BRACKET", "T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL", "T_OPEN_BRACE", "T_CLOSE_BRACE", "T_OPEN_BRACKET", "T_CLOSE_BRACKET",
"T_MULTIPLY_EQUAL", "T_DIVIDE_EQUAL", "T_COMMA", "T_ABSTRACT", "T_LOCAL", "T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL", "T_MULTIPLY_EQUAL",
"T_OBJECT", "T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'", "T_DIVIDE_EQUAL", "T_COMMA", "T_ABSTRACT", "T_LOCAL", "T_OBJECT",
"$accept", "statements", "statement", "include", "object", "$@1", "$@2", "T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'", "$accept",
"statements", "statement", "include", "object", "$@1", "$@2",
"attributes", "attribute", "inherits_list", "inherits_item", "attributes", "attribute", "inherits_list", "inherits_item",
"inherits_specifier", "expressionlist", "$@3", "expressions", "inherits_specifier", "expressionlist", "$@3", "expressions",
"expression", "operator", "simplevalue", "value", "array", "$@4", "expression", "operator", "simplevalue", "value", "tuple", "$@4",
"arrayitems", 0 "tupleitem", "tupleitems", 0
}; };
#endif #endif
@ -578,18 +581,18 @@ static const yytype_uint16 yytoknum[] =
{ {
0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 43, 45, 42, 47 275, 276, 277, 278, 43, 45, 42, 47
}; };
# endif # endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] = static const yytype_uint8 yyr1[] =
{ {
0, 26, 27, 27, 28, 28, 29, 31, 32, 30, 0, 28, 29, 29, 30, 30, 31, 33, 34, 32,
33, 33, 34, 34, 35, 35, 36, 37, 37, 39, 35, 35, 36, 36, 37, 37, 38, 39, 39, 41,
38, 40, 40, 40, 41, 41, 41, 42, 42, 42, 40, 42, 42, 42, 43, 43, 43, 44, 44, 44,
42, 42, 43, 43, 43, 44, 44, 44, 46, 45, 44, 44, 45, 45, 45, 46, 46, 46, 48, 47,
47, 47, 47 49, 50, 50, 50
}; };
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
@ -599,7 +602,7 @@ static const yytype_uint8 yyr2[] =
0, 2, 1, 1, 1, 3, 1, 0, 2, 0, 0, 2, 1, 1, 1, 3, 1, 0, 2, 0,
4, 0, 1, 3, 3, 6, 1, 1, 1, 1, 4, 0, 1, 3, 3, 6, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 4, 1, 1, 1, 1, 1, 1, 1, 1, 0, 4,
0, 1, 3 1, 0, 1, 3
}; };
/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
@ -610,9 +613,9 @@ static const yytype_uint8 yydefact[] =
2, 7, 1, 0, 3, 5, 4, 10, 6, 0, 2, 7, 1, 0, 3, 5, 4, 10, 6, 0,
12, 13, 0, 11, 0, 8, 17, 0, 0, 16, 12, 13, 0, 11, 0, 8, 17, 0, 0, 16,
18, 14, 19, 9, 0, 21, 15, 26, 0, 0, 18, 14, 19, 9, 0, 21, 15, 26, 0, 0,
22, 0, 27, 28, 29, 30, 31, 0, 20, 0, 22, 0, 27, 28, 29, 30, 31, 0, 20, 21,
0, 32, 33, 34, 38, 37, 35, 24, 36, 23, 0, 32, 33, 34, 38, 37, 35, 24, 36, 23,
0, 40, 0, 41, 0, 25, 39, 0, 42 0, 41, 0, 40, 42, 0, 25, 41, 39, 43
}; };
/* YYDEFGOTO[NTERM-NUM]. */ /* YYDEFGOTO[NTERM-NUM]. */
@ -620,28 +623,28 @@ static const yytype_int8 yydefgoto[] =
{ {
-1, 1, 4, 5, 6, 7, 16, 9, 13, 20, -1, 1, 4, 5, 6, 7, 16, 9, 13, 20,
21, 18, 45, 25, 29, 30, 37, 46, 47, 48, 21, 18, 45, 25, 29, 30, 37, 46, 47, 48,
51, 54 51, 54, 55
}; };
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */ STATE-NUM. */
#define YYPACT_NINF -30 #define YYPACT_NINF -41
static const yytype_int8 yypact[] = static const yytype_int8 yypact[] =
{ {
-30, 0, -30, 4, -30, -30, -30, -30, -30, 13, -41, 0, -41, -1, -41, -41, -41, -41, -41, 9,
-30, -30, 19, -30, 24, -30, 15, 26, 31, -30, -41, -41, 7, -41, 13, -41, 8, 29, 24, -41,
21, -30, -30, -30, 26, 20, -30, -30, -1, -7, 17, -41, -41, -41, 29, 12, -41, -41, -10, 26,
-30, 36, -30, -30, -30, -30, -30, 12, -30, 20, 19, 31, -41, -41, -41, -41, -41, 5, -41, 12,
32, -30, -30, -30, -30, -30, -30, -30, -30, -30, 27, -41, -41, -41, -41, -41, -41, -41, -41, -41,
-9, 30, 12, -30, 8, -30, -30, 30, -30 10, 16, 5, -41, 20, 32, -41, 16, -41, -41
}; };
/* YYPGOTO[NTERM-NUM]. */ /* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] = static const yytype_int8 yypgoto[] =
{ {
-30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41,
16, -30, 23, -30, -30, 5, -5, -29, -6, -30, 18, -41, 23, -41, 4, -41, -6, -40, -7, -41,
-30, -30 -41, -41, -11
}; };
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@ -650,38 +653,38 @@ static const yytype_int8 yypgoto[] =
#define YYTABLE_NINF -1 #define YYTABLE_NINF -1
static const yytype_uint8 yytable[] = static const yytype_uint8 yytable[] =
{ {
2, 38, 32, 33, 34, 35, 36, 8, 31, 39, 2, 31, 8, 32, 33, 34, 35, 36, 41, 42,
32, 33, 34, 35, 36, 41, 42, 43, 56, 22, 43, 53, 44, 14, 22, 27, 15, 53, 28, 41,
3, 44, 53, 27, 57, 14, 28, 15, 58, 19, 42, 43, 3, 32, 33, 34, 35, 36, 10, 11,
10, 11, 12, 41, 42, 43, 17, 24, 22, 40, 12, 17, 19, 22, 40, 24, 38, 39, 57, 50,
26, 23, 50, 0, 49, 52, 55 58, 23, 26, 49, 52, 56, 59
}; };
#define yypact_value_is_default(yystate) \ #define yypact_value_is_default(yystate) \
((yystate) == (-30)) ((yystate) == (-41))
#define yytable_value_is_error(yytable_value) \ #define yytable_value_is_error(yytable_value) \
YYID (0) YYID (0)
static const yytype_int8 yycheck[] = static const yytype_uint8 yycheck[] =
{ {
0, 8, 11, 12, 13, 14, 15, 3, 9, 16, 0, 11, 3, 13, 14, 15, 16, 17, 3, 4,
11, 12, 13, 14, 15, 3, 4, 5, 10, 7, 5, 51, 7, 6, 9, 3, 3, 57, 6, 3,
20, 9, 51, 3, 16, 6, 6, 3, 57, 3, 4, 5, 22, 13, 14, 15, 16, 17, 19, 20,
17, 18, 19, 3, 4, 5, 21, 16, 7, 3, 21, 23, 3, 9, 3, 18, 10, 18, 18, 12,
24, 18, 10, -1, 39, 50, 52 8, 18, 24, 39, 50, 52, 57
}; };
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */ symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] = static const yytype_uint8 yystos[] =
{ {
0, 27, 0, 20, 28, 29, 30, 31, 3, 33, 0, 29, 0, 22, 30, 31, 32, 33, 3, 35,
17, 18, 19, 34, 6, 3, 32, 21, 37, 3, 19, 20, 21, 36, 6, 3, 34, 23, 39, 3,
35, 36, 7, 38, 16, 39, 36, 3, 6, 40, 37, 38, 9, 40, 18, 41, 38, 3, 6, 42,
41, 9, 11, 12, 13, 14, 15, 42, 8, 16, 43, 11, 13, 14, 15, 16, 17, 44, 10, 18,
3, 3, 4, 5, 9, 38, 43, 44, 45, 41, 3, 3, 4, 5, 7, 40, 45, 46, 47, 42,
10, 46, 42, 43, 47, 44, 10, 16, 43 12, 48, 44, 45, 49, 50, 46, 18, 8, 50
}; };
#define yyerrok (yyerrstatus = 0) #define yyerrok (yyerrstatus = 0)
@ -1578,7 +1581,6 @@ yyreduce:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 119 "config_parser.yy" #line 119 "config_parser.yy"
{ {
m_Object = make_shared<DConfigObject>();
m_Abstract = false; m_Abstract = false;
m_Local = false; m_Local = false;
} }
@ -1587,12 +1589,10 @@ yyreduce:
case 8: case 8:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 125 "config_parser.yy" #line 124 "config_parser.yy"
{ {
m_Type = (yyvsp[(4) - (5)].text); m_Object = make_shared<DConfigObject>((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc.first_line);
free((yyvsp[(4) - (5)].text)); free((yyvsp[(4) - (5)].text));
m_Name = (yyvsp[(5) - (5)].text);
free((yyvsp[(5) - (5)].text)); free((yyvsp[(5) - (5)].text));
} }
break; break;
@ -1600,37 +1600,36 @@ yyreduce:
case 9: case 9:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 133 "config_parser.yy" #line 130 "config_parser.yy"
{ {
Object::Ptr exprl_object = *(yyvsp[(8) - (8)].variant); Object::Ptr exprl_object = *(yyvsp[(8) - (8)].variant);
delete (yyvsp[(8) - (8)].variant); delete (yyvsp[(8) - (8)].variant);
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object); ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
Expression typeexpr("__type", OperatorSet, m_Type); Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc.first_line);
exprl->AddExpression(typeexpr); exprl->AddExpression(typeexpr);
Expression nameexpr("__name", OperatorSet, m_Name); Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc.first_line);
exprl->AddExpression(nameexpr); exprl->AddExpression(nameexpr);
Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0); Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc.first_line);
exprl->AddExpression(abstractexpr); exprl->AddExpression(abstractexpr);
Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0); Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc.first_line);
exprl->AddExpression(localexpr); exprl->AddExpression(localexpr);
m_Object->SetExpressionList(exprl); m_Object->SetExpressionList(exprl);
m_Objects[pair<string, string>(m_Type, m_Name)] = m_Object; DConfigObject::AddObject(m_Object);
m_Objects.insert(m_Object);
free((yyvsp[(4) - (8)].text)); m_Object.reset();
free((yyvsp[(5) - (8)].text));
} }
break; break;
case 12: case 12:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 164 "config_parser.yy" #line 160 "config_parser.yy"
{ {
m_Abstract = true; m_Abstract = true;
} }
@ -1639,7 +1638,7 @@ yyreduce:
case 13: case 13:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 168 "config_parser.yy" #line 164 "config_parser.yy"
{ {
m_Local = true; m_Local = true;
} }
@ -1648,7 +1647,7 @@ yyreduce:
case 16: case 16:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 178 "config_parser.yy" #line 174 "config_parser.yy"
{ {
m_Object->AddParent((yyvsp[(1) - (1)].text)); m_Object->AddParent((yyvsp[(1) - (1)].text));
} }
@ -1657,7 +1656,7 @@ yyreduce:
case 19: case 19:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 188 "config_parser.yy" #line 184 "config_parser.yy"
{ {
m_ExpressionLists.push(make_shared<ExpressionList>()); m_ExpressionLists.push(make_shared<ExpressionList>());
} }
@ -1666,7 +1665,7 @@ yyreduce:
case 20: case 20:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 193 "config_parser.yy" #line 189 "config_parser.yy"
{ {
(yyval.variant) = new Variant(m_ExpressionLists.top()); (yyval.variant) = new Variant(m_ExpressionLists.top());
m_ExpressionLists.pop(); m_ExpressionLists.pop();
@ -1676,9 +1675,9 @@ yyreduce:
case 24: case 24:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 205 "config_parser.yy" #line 201 "config_parser.yy"
{ {
Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant)); Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc.first_line);
free((yyvsp[(1) - (3)].text)); free((yyvsp[(1) - (3)].text));
delete (yyvsp[(3) - (3)].variant); delete (yyvsp[(3) - (3)].variant);
@ -1689,16 +1688,16 @@ yyreduce:
case 25: case 25:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 213 "config_parser.yy" #line 209 "config_parser.yy"
{ {
Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant)); Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc.first_line);
free((yyvsp[(3) - (6)].text)); free((yyvsp[(3) - (6)].text));
delete (yyvsp[(6) - (6)].variant); delete (yyvsp[(6) - (6)].variant);
ExpressionList::Ptr subexprl = make_shared<ExpressionList>(); ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
subexprl->AddExpression(subexpr); subexprl->AddExpression(subexpr);
Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl); Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl, yylloc.first_line);
m_ExpressionLists.top()->AddExpression(expr); m_ExpressionLists.top()->AddExpression(expr);
} }
@ -1707,9 +1706,9 @@ yyreduce:
case 26: case 26:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 226 "config_parser.yy" #line 222 "config_parser.yy"
{ {
Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text)); Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc.first_line);
free((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text));
m_ExpressionLists.top()->AddExpression(expr); m_ExpressionLists.top()->AddExpression(expr);
@ -1719,7 +1718,7 @@ yyreduce:
case 31: case 31:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 239 "config_parser.yy" #line 235 "config_parser.yy"
{ {
(yyval.op) = (yyvsp[(1) - (1)].op); (yyval.op) = (yyvsp[(1) - (1)].op);
} }
@ -1728,7 +1727,7 @@ yyreduce:
case 32: case 32:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 245 "config_parser.yy" #line 241 "config_parser.yy"
{ {
(yyval.variant) = new Variant((yyvsp[(1) - (1)].text)); (yyval.variant) = new Variant((yyvsp[(1) - (1)].text));
} }
@ -1737,7 +1736,7 @@ yyreduce:
case 33: case 33:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 249 "config_parser.yy" #line 245 "config_parser.yy"
{ {
(yyval.variant) = new Variant((yyvsp[(1) - (1)].num)); (yyval.variant) = new Variant((yyvsp[(1) - (1)].num));
} }
@ -1746,7 +1745,7 @@ yyreduce:
case 34: case 34:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 253 "config_parser.yy" #line 249 "config_parser.yy"
{ {
(yyval.variant) = new Variant(); (yyval.variant) = new Variant();
} }
@ -1755,7 +1754,7 @@ yyreduce:
case 37: case 37:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 261 "config_parser.yy" #line 257 "config_parser.yy"
{ {
(yyval.variant) = (yyvsp[(1) - (1)].variant); (yyval.variant) = (yyvsp[(1) - (1)].variant);
} }
@ -1764,7 +1763,7 @@ yyreduce:
case 38: case 38:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 267 "config_parser.yy" #line 263 "config_parser.yy"
{ {
m_Array = make_shared<Dictionary>(); m_Array = make_shared<Dictionary>();
} }
@ -1773,37 +1772,27 @@ yyreduce:
case 39: case 39:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 272 "config_parser.yy" #line 268 "config_parser.yy"
{ {
(yyval.variant) = new Variant(m_Array); (yyval.variant) = new Variant(m_Array);
m_Array.reset(); m_Array.reset();
} }
break; break;
case 41: case 40:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 281 "config_parser.yy" #line 275 "config_parser.yy"
{ {
m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant)); m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant));
delete (yyvsp[(1) - (1)].variant); delete (yyvsp[(1) - (1)].variant);
} }
break; break;
case 42:
/* Line 1806 of yacc.c */
#line 286 "config_parser.yy"
{
m_Array->AddUnnamedProperty(*(yyvsp[(3) - (3)].variant));
delete (yyvsp[(3) - (3)].variant);
}
break;
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 1807 "config_parser.cc" #line 1796 "config_parser.cc"
default: break; default: break;
} }
/* User semantic actions sometimes alter yychar, and that requires /* User semantic actions sometimes alter yychar, and that requires
@ -2041,6 +2030,6 @@ yyreturn:
/* Line 2067 of yacc.c */ /* Line 2067 of yacc.c */
#line 291 "config_parser.yy" #line 285 "config_parser.yy"

View File

@ -41,21 +41,23 @@
T_NUMBER = 259, T_NUMBER = 259,
T_NULL = 260, T_NULL = 260,
T_IDENTIFIER = 261, T_IDENTIFIER = 261,
T_OPEN_BRACE = 262, T_OPEN_PARENTHESIS = 262,
T_CLOSE_BRACE = 263, T_CLOSE_PARENTHESIS = 263,
T_OPEN_BRACKET = 264, T_OPEN_BRACE = 264,
T_CLOSE_BRACKET = 265, T_CLOSE_BRACE = 265,
T_EQUAL = 266, T_OPEN_BRACKET = 266,
T_PLUS_EQUAL = 267, T_CLOSE_BRACKET = 267,
T_MINUS_EQUAL = 268, T_EQUAL = 268,
T_MULTIPLY_EQUAL = 269, T_PLUS_EQUAL = 269,
T_DIVIDE_EQUAL = 270, T_MINUS_EQUAL = 270,
T_COMMA = 271, T_MULTIPLY_EQUAL = 271,
T_ABSTRACT = 272, T_DIVIDE_EQUAL = 272,
T_LOCAL = 273, T_COMMA = 273,
T_OBJECT = 274, T_ABSTRACT = 274,
T_INCLUDE = 275, T_LOCAL = 275,
T_INHERITS = 276 T_OBJECT = 276,
T_INCLUDE = 277,
T_INHERITS = 278
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
@ -63,21 +65,23 @@
#define T_NUMBER 259 #define T_NUMBER 259
#define T_NULL 260 #define T_NULL 260
#define T_IDENTIFIER 261 #define T_IDENTIFIER 261
#define T_OPEN_BRACE 262 #define T_OPEN_PARENTHESIS 262
#define T_CLOSE_BRACE 263 #define T_CLOSE_PARENTHESIS 263
#define T_OPEN_BRACKET 264 #define T_OPEN_BRACE 264
#define T_CLOSE_BRACKET 265 #define T_CLOSE_BRACE 265
#define T_EQUAL 266 #define T_OPEN_BRACKET 266
#define T_PLUS_EQUAL 267 #define T_CLOSE_BRACKET 267
#define T_MINUS_EQUAL 268 #define T_EQUAL 268
#define T_MULTIPLY_EQUAL 269 #define T_PLUS_EQUAL 269
#define T_DIVIDE_EQUAL 270 #define T_MINUS_EQUAL 270
#define T_COMMA 271 #define T_MULTIPLY_EQUAL 271
#define T_ABSTRACT 272 #define T_DIVIDE_EQUAL 272
#define T_LOCAL 273 #define T_COMMA 273
#define T_OBJECT 274 #define T_ABSTRACT 274
#define T_INCLUDE 275 #define T_LOCAL 275
#define T_INHERITS 276 #define T_OBJECT 276
#define T_INCLUDE 277
#define T_INHERITS 278
@ -97,7 +101,7 @@ typedef union YYSTYPE
/* Line 2068 of yacc.c */ /* Line 2068 of yacc.c */
#line 101 "config_parser.h" #line 105 "config_parser.h"
} YYSTYPE; } YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */

View File

@ -44,6 +44,8 @@ using namespace icinga;
%token <num> T_NUMBER %token <num> T_NUMBER
%token T_NULL %token T_NULL
%token <text> T_IDENTIFIER %token <text> T_IDENTIFIER
%token T_OPEN_PARENTHESIS
%token T_CLOSE_PARENTHESIS
%token T_OPEN_BRACE %token T_OPEN_BRACE
%token T_CLOSE_BRACE %token T_CLOSE_BRACE
%token T_OPEN_BRACKET %token T_OPEN_BRACKET
@ -61,7 +63,7 @@ using namespace icinga;
%token T_INHERITS %token T_INHERITS
%type <variant> simplevalue %type <variant> simplevalue
%type <variant> value %type <variant> value
%type <variant> array %type <variant> tuple
%type <variant> expressionlist %type <variant> expressionlist
%type <op> operator %type <op> operator
%left '+' '-' %left '+' '-'
@ -92,10 +94,8 @@ void ConfigContext::Compile(void)
#define scanner (context->GetScanner()) #define scanner (context->GetScanner())
static stack<ExpressionList::Ptr> m_ExpressionLists; static stack<ExpressionList::Ptr> m_ExpressionLists;
static map<pair<string, string>, DConfigObject::Ptr> m_Objects; static set<DConfigObject::Ptr> m_Objects;
static DConfigObject::Ptr m_Object; static DConfigObject::Ptr m_Object;
static string m_Name;
static string m_Type;
static bool m_Abstract; static bool m_Abstract;
static bool m_Local; static bool m_Local;
static Dictionary::Ptr m_Array; static Dictionary::Ptr m_Array;
@ -117,16 +117,13 @@ include: T_INCLUDE T_STRING
object: object:
{ {
m_Object = make_shared<DConfigObject>();
m_Abstract = false; m_Abstract = false;
m_Local = false; m_Local = false;
} }
attributes T_OBJECT T_IDENTIFIER T_STRING attributes T_OBJECT T_IDENTIFIER T_STRING
{ {
m_Type = $4; m_Object = make_shared<DConfigObject>($4, $5, yylloc.first_line);
free($4); free($4);
m_Name = $5;
free($5); free($5);
} }
inherits_specifier expressionlist inherits_specifier expressionlist
@ -135,24 +132,23 @@ inherits_specifier expressionlist
delete $8; delete $8;
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object); ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
Expression typeexpr("__type", OperatorSet, m_Type); Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc.first_line);
exprl->AddExpression(typeexpr); exprl->AddExpression(typeexpr);
Expression nameexpr("__name", OperatorSet, m_Name); Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc.first_line);
exprl->AddExpression(nameexpr); exprl->AddExpression(nameexpr);
Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0); Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc.first_line);
exprl->AddExpression(abstractexpr); exprl->AddExpression(abstractexpr);
Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0); Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc.first_line);
exprl->AddExpression(localexpr); exprl->AddExpression(localexpr);
m_Object->SetExpressionList(exprl); m_Object->SetExpressionList(exprl);
m_Objects[pair<string, string>(m_Type, m_Name)] = m_Object; DConfigObject::AddObject(m_Object);
m_Objects.insert(m_Object);
free($4); m_Object.reset();
free($5);
} }
; ;
@ -198,12 +194,12 @@ expressionlist: T_OPEN_BRACE
expressions: /* empty */ expressions: /* empty */
| expression | expression
| expressions T_COMMA expression | expression T_COMMA expressions
; ;
expression: T_IDENTIFIER operator value expression: T_IDENTIFIER operator value
{ {
Expression expr($1, $2, *$3); Expression expr($1, $2, *$3, yylloc.first_line);
free($1); free($1);
delete $3; delete $3;
@ -211,20 +207,20 @@ expression: T_IDENTIFIER operator value
} }
| T_IDENTIFIER T_OPEN_BRACKET T_STRING T_CLOSE_BRACKET operator value | T_IDENTIFIER T_OPEN_BRACKET T_STRING T_CLOSE_BRACKET operator value
{ {
Expression subexpr($3, $5, *$6); Expression subexpr($3, $5, *$6, yylloc.first_line);
free($3); free($3);
delete $6; delete $6;
ExpressionList::Ptr subexprl = make_shared<ExpressionList>(); ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
subexprl->AddExpression(subexpr); subexprl->AddExpression(subexpr);
Expression expr($1, OperatorPlus, subexprl); Expression expr($1, OperatorPlus, subexprl, yylloc.first_line);
m_ExpressionLists.top()->AddExpression(expr); m_ExpressionLists.top()->AddExpression(expr);
} }
| T_STRING | T_STRING
{ {
Expression expr($1, OperatorSet, $1); Expression expr($1, OperatorSet, $1, yylloc.first_line);
free($1); free($1);
m_ExpressionLists.top()->AddExpression(expr); m_ExpressionLists.top()->AddExpression(expr);
@ -256,36 +252,34 @@ simplevalue: T_STRING
; ;
value: simplevalue value: simplevalue
| array | tuple
| expressionlist | expressionlist
{ {
$$ = $1; $$ = $1;
} }
; ;
array: T_OPEN_BRACKET tuple: T_OPEN_PARENTHESIS
{ {
m_Array = make_shared<Dictionary>(); m_Array = make_shared<Dictionary>();
} }
arrayitems tupleitems
T_CLOSE_BRACKET T_CLOSE_PARENTHESIS
{ {
$$ = new Variant(m_Array); $$ = new Variant(m_Array);
m_Array.reset(); m_Array.reset();
} }
; ;
arrayitems: tupleitem: simplevalue
/* empty */
| simplevalue
{ {
m_Array->AddUnnamedProperty(*$1); m_Array->AddUnnamedProperty(*$1);
delete $1; delete $1;
} }
| arrayitems T_COMMA simplevalue
{ tupleitems:
m_Array->AddUnnamedProperty(*$3); /* empty */
delete $3; | tupleitem
} | tupleitem T_COMMA tupleitems
; ;
%% %%

View File

@ -24,12 +24,12 @@ void *ConfigContext::GetScanner(void) const
return m_Scanner; return m_Scanner;
} }
void ConfigContext::SetResult(map<pair<string, string>, DConfigObject::Ptr> result) void ConfigContext::SetResult(set<DConfigObject::Ptr> result)
{ {
m_Result = result; m_Result = result;
} }
map<pair<string, string>, DConfigObject::Ptr> ConfigContext::GetResult(void) const set<DConfigObject::Ptr> ConfigContext::GetResult(void) const
{ {
return m_Result; return m_Result;
} }

View File

@ -31,8 +31,8 @@ public:
void Compile(void); void Compile(void);
void SetResult(map<pair<string, string>, DConfigObject::Ptr> result); void SetResult(set<DConfigObject::Ptr> result);
map<pair<string, string>, DConfigObject::Ptr> GetResult(void) const; set<DConfigObject::Ptr> GetResult(void) const;
size_t ReadInput(char *buffer, size_t max_bytes); size_t ReadInput(char *buffer, size_t max_bytes);
void *GetScanner(void) const; void *GetScanner(void) const;
@ -40,7 +40,7 @@ public:
private: private:
istream *m_Input; istream *m_Input;
void *m_Scanner; void *m_Scanner;
map<pair<string, string>, DConfigObject::Ptr> m_Result; set<DConfigObject::Ptr> m_Result;
void InitializeScanner(void); void InitializeScanner(void);
void DestroyScanner(void); void DestroyScanner(void);

View File

@ -1,35 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#ifndef CONFIGOBJECT_H
#define CONFIGOBJECT_H
namespace icinga
{
class I2_DYN_API ConfigObject : public Object
{
public:
private:
DynamicObject::WeakPtr m_DynamicObject;
};
}
#endif /* CONFIGOBJECT_H */

View File

@ -2,6 +2,21 @@
using namespace icinga; using namespace icinga;
DConfigObject::DConfigObject(string type, string name, long debuginfo)
: m_Type(type), m_Name(name), m_DebugInfo(debuginfo)
{
}
string DConfigObject::GetType(void) const
{
return m_Type;
}
string DConfigObject::GetName(void) const
{
return m_Name;
}
ExpressionList::Ptr DConfigObject::GetExpressionList(void) const ExpressionList::Ptr DConfigObject::GetExpressionList(void) const
{ {
return m_ExpressionList; return m_ExpressionList;
@ -21,3 +36,79 @@ void DConfigObject::AddParent(string parent)
{ {
m_Parents.push_back(parent); m_Parents.push_back(parent);
} }
Dictionary::Ptr DConfigObject::CalculateProperties(void) const
{
Dictionary::Ptr result = make_shared<Dictionary>();
vector<string>::const_iterator it;
for (it = m_Parents.begin(); it != m_Parents.end(); it++) {
DConfigObject::Ptr parent = DConfigObject::GetObject(GetType(), *it);
if (!parent) {
stringstream message;
message << "Parent object '" << *it << "' does not exist (in line " << m_DebugInfo << ")";
throw domain_error(message.str());
}
parent->GetExpressionList()->Execute(result);
}
m_ExpressionList->Execute(result);
return result;
}
ObjectSet<DConfigObject::Ptr>::Ptr DConfigObject::GetAllObjects(void)
{
static ObjectSet<DConfigObject::Ptr>::Ptr allObjects;
if (!allObjects) {
allObjects = make_shared<ObjectSet<DConfigObject::Ptr> >();
allObjects->Start();
}
return allObjects;
}
bool DConfigObject::GetTypeAndName(const DConfigObject::Ptr& object, pair<string, string> *key)
{
*key = make_pair(object->GetType(), object->GetName());
return true;
}
ObjectMap<pair<string, string>, DConfigObject::Ptr>::Ptr DConfigObject::GetObjectsByTypeAndName(void)
{
static ObjectMap<pair<string, string>, DConfigObject::Ptr>::Ptr tnmap;
if (!tnmap) {
tnmap = make_shared<ObjectMap<pair<string, string>, DConfigObject::Ptr> >(GetAllObjects(), &DConfigObject::GetTypeAndName);
tnmap->Start();
}
return tnmap;
}
void DConfigObject::AddObject(DConfigObject::Ptr object)
{
GetAllObjects()->AddObject(object);
}
void DConfigObject::RemoveObject(DConfigObject::Ptr object)
{
throw logic_error("not implemented.");
}
DConfigObject::Ptr DConfigObject::GetObject(string type, string name)
{
ObjectMap<pair<string, string>, DConfigObject::Ptr>::Range range;
range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));
assert(distance(range.first, range.second) <= 1);
if (range.first == range.second)
return DConfigObject::Ptr();
else
return range.first->second;
}

View File

@ -9,18 +9,33 @@ public:
typedef shared_ptr<DConfigObject> Ptr; typedef shared_ptr<DConfigObject> Ptr;
typedef weak_ptr<DConfigObject> WeakPtr; typedef weak_ptr<DConfigObject> WeakPtr;
DConfigObject(string type, string name, long debuginfo);
string GetType(void) const;
string GetName(void) const;
vector<string> GetParents(void) const; vector<string> GetParents(void) const;
void AddParent(string parent); void AddParent(string parent);
ExpressionList::Ptr GetExpressionList(void) const; ExpressionList::Ptr GetExpressionList(void) const;
void SetExpressionList(const ExpressionList::Ptr& exprl); void SetExpressionList(const ExpressionList::Ptr& exprl);
Dictionary::Ptr CalculateProperties(void) const;
static ObjectSet<DConfigObject::Ptr>::Ptr GetAllObjects(void);
static ObjectMap<pair<string, string>, DConfigObject::Ptr>::Ptr GetObjectsByTypeAndName(void);
static void AddObject(DConfigObject::Ptr object);
static void RemoveObject(DConfigObject::Ptr object);
static DConfigObject::Ptr GetObject(string type, string name);
private: private:
string m_Type; string m_Type;
string m_Name; string m_Name;
long m_DebugInfo;
vector<string> m_Parents; vector<string> m_Parents;
ExpressionList::Ptr m_ExpressionList; ExpressionList::Ptr m_ExpressionList;
static bool GetTypeAndName(const DConfigObject::Ptr& object, pair<string, string> *key);
}; };

View File

@ -39,11 +39,23 @@ Dictionary::Ptr DynamicObject::GetTags(void) const
void DynamicObject::Commit(void) void DynamicObject::Commit(void)
{ {
DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this()); DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
ObjectSet::GetAllObjects()->CheckObject(self); DynamicObject::GetAllObjects()->CheckObject(self);
} }
void DynamicObject::Unregister(void) void DynamicObject::Unregister(void)
{ {
DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this()); DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
ObjectSet::GetAllObjects()->RemoveObject(self); DynamicObject::GetAllObjects()->RemoveObject(self);
}
ObjectSet<DynamicObject::Ptr>::Ptr DynamicObject::GetAllObjects(void)
{
static ObjectSet<DynamicObject::Ptr>::Ptr allObjects;
if (!allObjects) {
allObjects = make_shared<ObjectSet<DynamicObject::Ptr> >();
allObjects->Start();
}
return allObjects;
} }

View File

@ -37,6 +37,8 @@ public:
void Commit(void); void Commit(void);
void Unregister(void); void Unregister(void);
static ObjectSet<DynamicObject::Ptr>::Ptr GetAllObjects(void);
private: private:
Dictionary::Ptr m_Config; Dictionary::Ptr m_Config;
Dictionary::Ptr m_Tags; Dictionary::Ptr m_Tags;

View File

@ -21,31 +21,61 @@
using namespace icinga; using namespace icinga;
Expression::Expression(string key, ExpressionOperator op, Variant value) Expression::Expression(string key, ExpressionOperator op, Variant value, long debuginfo)
: Key(key), Operator(op), Value(value), DebugInfo(debuginfo)
{ {
Key = key;
Operator = op;
Value = value;
} }
void Expression::Execute(const Dictionary::Ptr& dictionary) void Expression::Execute(const Dictionary::Ptr& dictionary) const
{ {
Variant oldValue, newValue; Variant oldValue, newValue;
dictionary->GetProperty(Key, &oldValue); dictionary->GetProperty(Key, &oldValue);
ExpressionList::Ptr exprl;
if (Value.GetType() == VariantObject)
exprl = dynamic_pointer_cast<ExpressionList>(Value.GetObject());
newValue = Value;
switch (Operator) { switch (Operator) {
case OperatorSet: case OperatorSet:
if (oldValue.GetType() == VariantObject) { if (exprl) {
Object::Ptr object = oldValue; Dictionary::Ptr dict = make_shared<Dictionary>();
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(object); exprl->Execute(dict);
newValue = dict;
if (exprl)
newValue = exprl->Execute();
} }
default: break;
assert(!"Not yet implemented.");
case OperatorPlus:
if (exprl) {
Dictionary::Ptr dict;
if (oldValue.GetType() == VariantObject)
dict = dynamic_pointer_cast<Dictionary>(oldValue.GetObject());
if (!dict) {
if (!oldValue.IsEmpty()) {
stringstream message;
message << "Wrong argument types for += (non-dictionary and dictionary) (in line " << DebugInfo << ")";
throw domain_error(message.str());
}
dict = make_shared<Dictionary>();
}
exprl->Execute(dict);
newValue = dict;
} else {
stringstream message;
message << "+= only works for dictionaries (in line " << DebugInfo << ")";
throw domain_error(message.str());
}
break;
default:
break;
//assert(!"Not yet implemented.");
} }
dictionary->SetProperty(Key, newValue); dictionary->SetProperty(Key, newValue);

View File

@ -37,10 +37,11 @@ struct I2_DYN_API Expression
string Key; string Key;
ExpressionOperator Operator; ExpressionOperator Operator;
Variant Value; Variant Value;
long DebugInfo;
Expression(string key, ExpressionOperator op, Variant value); Expression(string key, ExpressionOperator op, Variant value, long debuginfo);
void Execute(const Dictionary::Ptr& dictionary); void Execute(const Dictionary::Ptr& dictionary) const;
}; };
} }

View File

@ -35,3 +35,11 @@ size_t ExpressionList::GetLength(void) const
return m_Expressions.size(); return m_Expressions.size();
} }
void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
{
vector<Expression>::const_iterator it;
for (it = m_Expressions.begin(); it != m_Expressions.end(); it++) {
it->Execute(dictionary);
}
}

View File

@ -34,8 +34,7 @@ public:
void AddExpression(const Expression& expression); void AddExpression(const Expression& expression);
Dictionary::Ptr Execute(void) const; void Execute(const Dictionary::Ptr& dictionary) const;
Dictionary::Ptr Execute(Dictionary::Ptr input) const;
size_t GetLength(void) const; size_t GetLength(void) const;

View File

@ -39,9 +39,9 @@
#include "expression.h" #include "expression.h"
#include "expressionlist.h" #include "expressionlist.h"
#include "dynamicobject.h"
#include "objectset.h" #include "objectset.h"
#include "objectmap.h" #include "objectmap.h"
#include "dynamicobject.h"
#include "dconfigobject.h" #include "dconfigobject.h"
#include "configcontext.h" #include "configcontext.h"

View File

@ -21,73 +21,3 @@
using namespace icinga; using namespace icinga;
ObjectMap::ObjectMap(const ObjectSet::Ptr& parent, ObjectKeyGetter keygetter)
: m_Parent(parent), m_KeyGetter(keygetter)
{
assert(m_Parent);
assert(m_KeyGetter);
}
void ObjectMap::Start(void)
{
m_Parent->OnObjectAdded += bind_weak(&ObjectMap::ObjectAddedHandler, shared_from_this());
m_Parent->OnObjectCommitted += bind_weak(&ObjectMap::ObjectCommittedHandler, shared_from_this());
m_Parent->OnObjectRemoved += bind_weak(&ObjectMap::ObjectRemovedHandler, shared_from_this());
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
AddObject(*it);
}
void ObjectMap::AddObject(const Object::Ptr& object)
{
string key;
if (!m_KeyGetter(object, &key))
return;
m_Objects.insert(pair<string, Object::Ptr>(key, object));
}
void ObjectMap::RemoveObject(const Object::Ptr& object)
{
string key;
if (!m_KeyGetter(object, &key))
return;
pair<Iterator, Iterator> range = GetRange(key);
for (Iterator i = range.first; i != range.second; i++) {
if (i->second == object) {
m_Objects.erase(i);
break;
}
}
}
void ObjectMap::CheckObject(const Object::Ptr& object)
{
RemoveObject(object);
AddObject(object);
}
ObjectMap::Range ObjectMap::GetRange(string key)
{
return m_Objects.equal_range(key);
}
int ObjectMap::ObjectAddedHandler(const ObjectSetEventArgs& ea)
{
AddObject(ea.Target);
return 0;
}
int ObjectMap::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
{
CheckObject(ea.Target);
return 0;
}
int ObjectMap::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
{
RemoveObject(ea.Target);
return 0;
}

View File

@ -23,35 +23,95 @@
namespace icinga namespace icinga
{ {
typedef function<bool (const Object::Ptr&, string *key)> ObjectKeyGetter; template<typename TKey = string, typename TValue = Object::Ptr>
class I2_DYN_API ObjectMap : public Object class I2_DYN_API ObjectMap : public Object
{ {
public: public:
typedef shared_ptr<ObjectMap> Ptr; typedef shared_ptr<ObjectMap<TKey, TValue> > Ptr;
typedef weak_ptr<ObjectMap> WeakPtr; typedef weak_ptr<ObjectMap<TKey, TValue > > WeakPtr;
typedef multimap<string, Object::Ptr>::iterator Iterator; typedef typename multimap<TKey, TValue>::iterator Iterator;
typedef pair<Iterator, Iterator> Range; typedef pair<Iterator, Iterator> Range;
ObjectMap(const ObjectSet::Ptr& parent, ObjectKeyGetter keygetter); ObjectMap(const typename ObjectSet<TValue>::Ptr& parent,
function<bool (const TValue&, TKey *key)> keygetter)
: m_Parent(parent), m_KeyGetter(keygetter)
{
assert(m_Parent);
assert(m_KeyGetter);
}
void Start(void); void Start(void)
{
m_Parent->OnObjectAdded += bind_weak(&ObjectMap::ObjectAddedHandler, shared_from_this());
m_Parent->OnObjectCommitted += bind_weak(&ObjectMap::ObjectCommittedHandler, shared_from_this());
m_Parent->OnObjectRemoved += bind_weak(&ObjectMap::ObjectRemovedHandler, shared_from_this());
Range GetRange(string key); for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
AddObject(*it);
}
Range GetRange(TKey key)
{
return m_Objects.equal_range(key);
}
private: private:
multimap<string, Object::Ptr> m_Objects; multimap<TKey, TValue> m_Objects;
ObjectSet::Ptr m_Parent; typename ObjectSet<TValue>::Ptr m_Parent;
ObjectKeyGetter m_KeyGetter; function<bool (const TValue&, TKey *key)> m_KeyGetter;
void AddObject(const Object::Ptr& object); void AddObject(const TValue& object)
void RemoveObject(const Object::Ptr& object); {
void CheckObject(const Object::Ptr& object); TKey key;
if (!m_KeyGetter(object, &key))
return;
int ObjectAddedHandler(const ObjectSetEventArgs& ea); m_Objects.insert(make_pair(key, object));
int ObjectCommittedHandler(const ObjectSetEventArgs& ea); }
int ObjectRemovedHandler(const ObjectSetEventArgs& ea);
void RemoveObject(const TValue& object)
{
TKey key;
if (!m_KeyGetter(object, &key))
return;
pair<Iterator, Iterator> range = GetRange(key);
for (Iterator i = range.first; i != range.second; i++) {
if (i->second == object) {
m_Objects.erase(i);
break;
}
}
}
void CheckObject(const TValue& object)
{
RemoveObject(object);
AddObject(object);
}
int ObjectAddedHandler(const ObjectSetEventArgs<TValue>& ea)
{
AddObject(ea.Target);
return 0;
}
int ObjectCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
{
CheckObject(ea.Target);
return 0;
}
int ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
{
RemoveObject(ea.Target);
return 0;
}
}; };
} }

View File

@ -21,105 +21,3 @@
using namespace icinga; using namespace icinga;
ObjectSet::ObjectSet(void)
: m_Parent(), m_Filter()
{
}
ObjectSet::ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter)
: m_Parent(parent), m_Filter(filter)
{
}
void ObjectSet::Start(void)
{
if (m_Parent) {
m_Parent->OnObjectAdded += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this());
m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this());
m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this());
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
CheckObject(*it);
}
}
void ObjectSet::AddObject(const Object::Ptr& object)
{
m_Objects.insert(object);
ObjectSetEventArgs ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectAdded(ea);
}
void ObjectSet::RemoveObject(const Object::Ptr& object)
{
ObjectSet::Iterator it = m_Objects.find(object);
if (it != m_Objects.end()) {
m_Objects.erase(it);
ObjectSetEventArgs ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectRemoved(ea);
}
}
bool ObjectSet::Contains(const Object::Ptr& object) const
{
ObjectSet::Iterator it = m_Objects.find(object);
return !(it == m_Objects.end());
}
void ObjectSet::CheckObject(const Object::Ptr& object)
{
if (m_Filter && !m_Filter(object))
RemoveObject(object);
else {
if (!Contains(object))
AddObject(object);
else {
ObjectSetEventArgs ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectCommitted(ea);
}
}
}
int ObjectSet::ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea)
{
CheckObject(ea.Target);
return 0;
}
int ObjectSet::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
{
RemoveObject(ea.Target);
return 0;
}
ObjectSet::Iterator ObjectSet::Begin(void)
{
return m_Objects.begin();
}
ObjectSet::Iterator ObjectSet::End(void)
{
return m_Objects.end();
}
ObjectSet::Ptr ObjectSet::GetAllObjects(void)
{
static ObjectSet::Ptr allObjects;
if (!allObjects) {
allObjects = make_shared<ObjectSet>();
allObjects->Start();
}
return allObjects;
}

View File

@ -23,49 +23,123 @@
namespace icinga namespace icinga
{ {
template<typename TValue>
struct ObjectSetEventArgs : public EventArgs struct ObjectSetEventArgs : public EventArgs
{ {
Object::Ptr Target; TValue Target;
}; };
typedef function<bool (const Object::Ptr&)> ObjectPredicate; template<typename TValue>
class I2_DYN_API ObjectSet : public Object class I2_DYN_API ObjectSet : public Object
{ {
public: public:
typedef shared_ptr<ObjectSet> Ptr; typedef shared_ptr<ObjectSet<TValue> > Ptr;
typedef weak_ptr<ObjectSet> WeakPtr; typedef weak_ptr<ObjectSet<TValue> > WeakPtr;
typedef set<Object::Ptr>::iterator Iterator; typedef typename set<TValue>::iterator Iterator;
ObjectSet(void); ObjectSet(void)
ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter); : m_Parent(), m_Predicate()
{ }
void Start(void); ObjectSet(const typename ObjectSet<TValue>::Ptr& parent, function<bool(const TValue&)> predicate)
: m_Parent(parent), m_Predicate(predicate)
{ }
void AddObject(const Object::Ptr& object); void Start(void)
void RemoveObject(const Object::Ptr& object); {
bool Contains(const Object::Ptr& object) const; if (m_Parent) {
m_Parent->OnObjectAdded += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this());
m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this());
m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this());
void CheckObject(const Object::Ptr& object); for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
CheckObject(*it);
}
Observable<ObjectSetEventArgs> OnObjectAdded;
Observable<ObjectSetEventArgs> OnObjectCommitted;
Observable<ObjectSetEventArgs> OnObjectRemoved;
Iterator Begin(void); }
Iterator End(void);
static ObjectSet::Ptr GetAllObjects(void); void AddObject(const TValue& object)
{
m_Objects.insert(object);
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectAdded(ea);
}
void RemoveObject(const TValue& object)
{
ObjectSet::Iterator it = m_Objects.find(object);
if (it != m_Objects.end()) {
m_Objects.erase(it);
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectRemoved(ea);
}
}
bool Contains(const TValue& object) const
{
ObjectSet::Iterator it = m_Objects.find(object);
return !(it == m_Objects.end());
}
void CheckObject(const TValue& object)
{
if (m_Predicate && !m_Predicate(object)) {
RemoveObject(object);
} else {
if (!Contains(object)) {
AddObject(object);
} else {
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectCommitted(ea);
}
}
}
Observable<ObjectSetEventArgs<TValue> > OnObjectAdded;
Observable<ObjectSetEventArgs<TValue> > OnObjectCommitted;
Observable<ObjectSetEventArgs<TValue> > OnObjectRemoved;
Iterator Begin(void)
{
return m_Objects.begin();
}
Iterator End(void)
{
return m_Objects.end();
}
private: private:
set<Object::Ptr> m_Objects; set<TValue> m_Objects;
ObjectSet::Ptr m_Parent; ObjectSet::Ptr m_Parent;
ObjectPredicate m_Filter; function<bool (const TValue&)> m_Predicate;
int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea); int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
int ObjectRemovedHandler(const ObjectSetEventArgs& ea); {
CheckObject(ea.Target);
return 0;
}
int ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
{
RemoveObject(ea.Target);
return 0;
}
}; };
} }

View File

@ -12,6 +12,7 @@ dyntest_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \ -I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \
-I${top_srcdir} -I${top_srcdir}
dyntest_LDFLAGS = \ dyntest_LDFLAGS = \
@ -19,4 +20,5 @@ dyntest_LDFLAGS = \
dyntest_LDADD = \ dyntest_LDADD = \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la ${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la

View File

@ -1,4 +1,5 @@
#include <i2-dyn.h> #include <i2-dyn.h>
#include <i2-jsonrpc.h>
using namespace icinga; using namespace icinga;
@ -6,13 +7,19 @@ int main(int argc, char **argv)
{ {
ConfigContext ctx; ConfigContext ctx;
ctx.Compile(); ctx.Compile();
map<pair<string, string>, DConfigObject::Ptr> objects = ctx.GetResult(); set<DConfigObject::Ptr> objects = ctx.GetResult();
for (auto it = objects.begin(); it != objects.end(); it++) { for (auto it = objects.begin(); it != objects.end(); it++) {
DConfigObject::Ptr obj = it->second; DConfigObject::Ptr obj = *it;
cout << "Object, name: " << it->first.second << ", type: " << it->first.first << endl; cout << "Object, name: " << obj->GetName() << ", type: " << obj->GetType() << endl;
cout << "\t" << obj->GetParents().size() << " parents" << endl; cout << "\t" << obj->GetParents().size() << " parents" << endl;
cout << "\t" << obj->GetExpressionList()->GetLength() << " top-level exprs" << endl; cout << "\t" << obj->GetExpressionList()->GetLength() << " top-level exprs" << endl;
Dictionary::Ptr props = obj->CalculateProperties();
cout << "\t" << props->GetLength() << " top-level properties" << endl;
MessagePart mp(props);
cout << mp.ToJsonString() << endl;
} }
return 0; return 0;