Semi-working implementation of the config compiler.

This commit is contained in:
Gunnar Beutner 2012-06-01 16:49:33 +02:00
parent f5a817e62e
commit 99e5eef7c1
16 changed files with 790 additions and 408 deletions

View File

@ -14,8 +14,12 @@ libdyn_la_SOURCES = \
config_lexer.ll \
config_parser.yy \
i2-dyn.h \
dynamicdictionary.cpp \
dynamicdictionary.h \
dconfigobject.cpp \
dconfigobject.h \
expression.cpp \
expression.h \
expressionlist.cpp \
expressionlist.h \
dynamicobject.cpp \
dynamicobject.h \
objectset.cpp \

View File

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

View File

@ -44,6 +44,7 @@ local return T_LOCAL;
object return T_OBJECT;
include return T_INCLUDE;
inherits return T_INHERITS;
null return T_NULL;
[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; }
[0-9]+ { yylval->num = atoi(yytext); return T_NUMBER; }

View File

@ -91,11 +91,10 @@
using namespace icinga;
Variant *z;
/* Line 268 of yacc.c */
#line 99 "config_parser.cc"
#line 98 "config_parser.cc"
/* Enabling traces. */
#ifndef YYDEBUG
@ -124,43 +123,45 @@ Variant *z;
enum yytokentype {
T_STRING = 258,
T_NUMBER = 259,
T_IDENTIFIER = 260,
T_OPEN_BRACE = 261,
T_CLOSE_BRACE = 262,
T_OPEN_BRACKET = 263,
T_CLOSE_BRACKET = 264,
T_EQUAL = 265,
T_PLUS_EQUAL = 266,
T_MINUS_EQUAL = 267,
T_MULTIPLY_EQUAL = 268,
T_DIVIDE_EQUAL = 269,
T_COMMA = 270,
T_ABSTRACT = 271,
T_LOCAL = 272,
T_OBJECT = 273,
T_INCLUDE = 274,
T_INHERITS = 275
T_NULL = 260,
T_IDENTIFIER = 261,
T_OPEN_BRACE = 262,
T_CLOSE_BRACE = 263,
T_OPEN_BRACKET = 264,
T_CLOSE_BRACKET = 265,
T_EQUAL = 266,
T_PLUS_EQUAL = 267,
T_MINUS_EQUAL = 268,
T_MULTIPLY_EQUAL = 269,
T_DIVIDE_EQUAL = 270,
T_COMMA = 271,
T_ABSTRACT = 272,
T_LOCAL = 273,
T_OBJECT = 274,
T_INCLUDE = 275,
T_INHERITS = 276
};
#endif
/* Tokens. */
#define T_STRING 258
#define T_NUMBER 259
#define T_IDENTIFIER 260
#define T_OPEN_BRACE 261
#define T_CLOSE_BRACE 262
#define T_OPEN_BRACKET 263
#define T_CLOSE_BRACKET 264
#define T_EQUAL 265
#define T_PLUS_EQUAL 266
#define T_MINUS_EQUAL 267
#define T_MULTIPLY_EQUAL 268
#define T_DIVIDE_EQUAL 269
#define T_COMMA 270
#define T_ABSTRACT 271
#define T_LOCAL 272
#define T_OBJECT 273
#define T_INCLUDE 274
#define T_INHERITS 275
#define T_NULL 260
#define T_IDENTIFIER 261
#define T_OPEN_BRACE 262
#define T_CLOSE_BRACE 263
#define T_OPEN_BRACKET 264
#define T_CLOSE_BRACKET 265
#define T_EQUAL 266
#define T_PLUS_EQUAL 267
#define T_MINUS_EQUAL 268
#define T_MULTIPLY_EQUAL 269
#define T_DIVIDE_EQUAL 270
#define T_COMMA 271
#define T_ABSTRACT 272
#define T_LOCAL 273
#define T_OBJECT 274
#define T_INCLUDE 275
#define T_INHERITS 276
@ -170,17 +171,17 @@ typedef union YYSTYPE
{
/* Line 293 of yacc.c */
#line 37 "config_parser.yy"
#line 36 "config_parser.yy"
char *text;
int num;
icinga::Variant *variant;
icinga::DynamicDictionaryOperator op;
icinga::ExpressionOperator op;
/* Line 293 of yacc.c */
#line 184 "config_parser.cc"
#line 185 "config_parser.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -204,7 +205,7 @@ typedef struct YYLTYPE
/* Copy the second part of user declarations. */
/* Line 343 of yacc.c */
#line 68 "config_parser.yy"
#line 69 "config_parser.yy"
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
@ -230,12 +231,18 @@ void ConfigContext::Compile(void)
#define scanner (context->GetScanner())
static stack<DynamicDictionary::Ptr> m_Dictionaries;
static stack<ExpressionList::Ptr> m_ExpressionLists;
static map<pair<string, string>, DConfigObject::Ptr> m_Objects;
static DConfigObject::Ptr m_Object;
static string m_Name;
static string m_Type;
static bool m_Abstract;
static bool m_Local;
static Dictionary::Ptr m_Array;
/* Line 343 of yacc.c */
#line 239 "config_parser.cc"
#line 246 "config_parser.cc"
#ifdef short
# undef short
@ -456,20 +463,20 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 2
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 39
#define YYLAST 46
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 25
#define YYNTOKENS 26
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 19
#define YYNNTS 22
/* YYNRULES -- Number of rules. */
#define YYNRULES 37
#define YYNRULES 42
/* YYNRULES -- Number of states. */
#define YYNSTATES 51
#define YYNSTATES 59
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
#define YYMAXUTOK 275
#define YYMAXUTOK 276
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@ -481,7 +488,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, 23, 21, 2, 22, 2, 24, 2, 2,
2, 2, 24, 22, 2, 23, 2, 25, 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,
@ -504,7 +511,7 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20
15, 16, 17, 18, 19, 20, 21
};
#if YYDEBUG
@ -512,34 +519,37 @@ static const yytype_uint8 yytranslate[] =
YYRHS. */
static const yytype_uint8 yyprhs[] =
{
0, 0, 3, 4, 7, 9, 11, 14, 17, 19,
25, 28, 30, 32, 34, 36, 40, 41, 44, 45,
50, 51, 53, 57, 61, 63, 65, 67, 69, 71,
73, 75, 77, 79, 80, 85, 86, 88
0, 0, 3, 4, 7, 9, 11, 14, 15, 16,
25, 26, 29, 31, 33, 35, 39, 41, 42, 45,
46, 51, 52, 54, 58, 62, 69, 71, 73, 75,
77, 79, 81, 83, 85, 87, 89, 91, 93, 94,
99, 100, 102
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
26, 0, -1, -1, 26, 27, -1, 29, -1, 28,
-1, 19, 3, -1, 31, 30, -1, 30, -1, 18,
5, 3, 34, 35, -1, 31, 32, -1, 32, -1,
16, -1, 17, -1, 3, -1, 33, 15, 3, -1,
-1, 20, 33, -1, -1, 6, 36, 37, 7, -1,
-1, 38, -1, 37, 15, 38, -1, 5, 39, 40,
-1, 10, -1, 11, -1, 12, -1, 13, -1, 14,
-1, 3, -1, 4, -1, 41, -1, 35, -1, -1,
8, 42, 43, 9, -1, -1, 40, -1, 43, 15,
40, -1
27, 0, -1, -1, 27, 28, -1, 30, -1, 29,
-1, 20, 3, -1, -1, -1, 31, 33, 19, 6,
3, 32, 37, 38, -1, -1, 33, 34, -1, 17,
-1, 18, -1, 36, -1, 35, 16, 36, -1, 3,
-1, -1, 21, 35, -1, -1, 7, 39, 40, 8,
-1, -1, 41, -1, 40, 16, 41, -1, 6, 42,
44, -1, 6, 9, 3, 10, 42, 44, -1, 3,
-1, 11, -1, 12, -1, 13, -1, 14, -1, 15,
-1, 3, -1, 4, -1, 5, -1, 43, -1, 45,
-1, 38, -1, -1, 9, 46, 47, 10, -1, -1,
43, -1, 47, 16, 43, -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
static const yytype_uint16 yyrline[] =
{
0, 98, 98, 99, 102, 102, 105, 108, 109, 112,
115, 116, 119, 120, 123, 124, 127, 128, 132, 131,
146, 147, 148, 151, 160, 161, 162, 163, 164, 170,
174, 178, 179, 186, 185, 200, 202, 208
0, 105, 105, 106, 112, 112, 115, 119, 125, 119,
159, 160, 163, 167, 173, 174, 177, 183, 184, 188,
187, 199, 200, 201, 204, 212, 225, 234, 235, 236,
237, 238, 244, 248, 252, 258, 259, 260, 267, 266,
278, 280, 285
};
#endif
@ -548,15 +558,16 @@ static const yytype_uint8 yyrline[] =
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "T_STRING", "T_NUMBER", "T_IDENTIFIER",
"T_OPEN_BRACE", "T_CLOSE_BRACE", "T_OPEN_BRACKET", "T_CLOSE_BRACKET",
"T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL", "T_MULTIPLY_EQUAL",
"T_DIVIDE_EQUAL", "T_COMMA", "T_ABSTRACT", "T_LOCAL", "T_OBJECT",
"T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'", "$accept",
"statements", "statement", "include", "object", "object_declaration",
"attributes_list", "attribute", "inherits_list", "inherits_specifier",
"dictionary", "$@1", "nvpairs", "nvpair", "operator", "value", "array",
"$@2", "arrayitems", 0
"$end", "error", "$undefined", "T_STRING", "T_NUMBER", "T_NULL",
"T_IDENTIFIER", "T_OPEN_BRACE", "T_CLOSE_BRACE", "T_OPEN_BRACKET",
"T_CLOSE_BRACKET", "T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL",
"T_MULTIPLY_EQUAL", "T_DIVIDE_EQUAL", "T_COMMA", "T_ABSTRACT", "T_LOCAL",
"T_OBJECT", "T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'",
"$accept", "statements", "statement", "include", "object", "$@1", "$@2",
"attributes", "attribute", "inherits_list", "inherits_item",
"inherits_specifier", "expressionlist", "$@3", "expressions",
"expression", "operator", "simplevalue", "value", "array", "$@4",
"arrayitems", 0
};
#endif
@ -567,26 +578,28 @@ static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 43, 45, 42, 47
275, 276, 43, 45, 42, 47
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 25, 26, 26, 27, 27, 28, 29, 29, 30,
31, 31, 32, 32, 33, 33, 34, 34, 36, 35,
37, 37, 37, 38, 39, 39, 39, 39, 39, 40,
40, 40, 40, 42, 41, 43, 43, 43
0, 26, 27, 27, 28, 28, 29, 31, 32, 30,
33, 33, 34, 34, 35, 35, 36, 37, 37, 39,
38, 40, 40, 40, 41, 41, 41, 42, 42, 42,
42, 42, 43, 43, 43, 44, 44, 44, 46, 45,
47, 47, 47
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
0, 2, 0, 2, 1, 1, 2, 2, 1, 5,
2, 1, 1, 1, 1, 3, 0, 2, 0, 4,
0, 1, 3, 3, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 4, 0, 1, 3
0, 2, 0, 2, 1, 1, 2, 0, 0, 8,
0, 2, 1, 1, 1, 3, 1, 0, 2, 0,
4, 0, 1, 3, 3, 6, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 4,
0, 1, 3
};
/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
@ -594,39 +607,41 @@ static const yytype_uint8 yyr2[] =
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
2, 0, 1, 12, 13, 0, 0, 3, 5, 4,
8, 0, 11, 0, 6, 7, 10, 16, 0, 0,
14, 17, 18, 9, 0, 20, 15, 0, 0, 21,
24, 25, 26, 27, 28, 0, 19, 0, 29, 30,
33, 32, 23, 31, 22, 35, 36, 0, 34, 0,
37
2, 7, 1, 0, 3, 5, 4, 10, 6, 0,
12, 13, 0, 11, 0, 8, 17, 0, 0, 16,
18, 14, 19, 9, 0, 21, 15, 26, 0, 0,
22, 0, 27, 28, 29, 30, 31, 0, 20, 0,
0, 32, 33, 34, 38, 37, 35, 24, 36, 23,
0, 40, 0, 41, 0, 25, 39, 0, 42
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
-1, 1, 7, 8, 9, 10, 11, 12, 21, 19,
41, 25, 28, 29, 35, 42, 43, 45, 47
-1, 1, 4, 5, 6, 7, 16, 9, 13, 20,
21, 18, 45, 25, 29, 30, 37, 46, 47, 48,
51, 54
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF -43
#define YYPACT_NINF -30
static const yytype_int8 yypact[] =
{
-43, 0, -43, -43, -43, 9, 22, -43, -43, -43,
-43, -12, -43, 23, -43, -43, -43, -8, 24, 25,
-43, 13, -43, -43, 26, 27, -43, 10, -6, -43,
-43, -43, -43, -43, -43, 7, -43, 27, -43, -43,
-43, -43, -43, -43, -43, 7, -43, -7, -43, 7,
-43
-30, 0, -30, 4, -30, -30, -30, -30, -30, 13,
-30, -30, 19, -30, 24, -30, 15, 26, 31, -30,
21, -30, -30, -30, 26, 20, -30, -30, -1, -7,
-30, 36, -30, -30, -30, -30, -30, 12, -30, 20,
32, -30, -30, -30, -30, -30, -30, -30, -30, -30,
-9, 30, 12, -30, 8, -30, -30, 30, -30
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-43, -43, -43, -43, -43, 19, -43, 28, -43, -43,
14, -43, -43, -3, -43, -42, -43, -43, -43
-30, -30, -30, -30, -30, -30, -30, -30, -30, -30,
16, -30, 23, -30, -30, 5, -5, -29, -6, -30,
-30, -30
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@ -635,36 +650,38 @@ static const yytype_int8 yypgoto[] =
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
2, 36, 48, 46, 3, 4, 5, 50, 49, 37,
38, 39, 18, 22, 13, 40, 3, 4, 5, 6,
30, 31, 32, 33, 34, 14, 17, 20, 24, 26,
15, 22, 27, 23, 44, 0, 0, 0, 0, 16
2, 38, 32, 33, 34, 35, 36, 8, 31, 39,
32, 33, 34, 35, 36, 41, 42, 43, 56, 22,
3, 44, 53, 27, 57, 14, 28, 15, 58, 19,
10, 11, 12, 41, 42, 43, 17, 24, 22, 40,
26, 23, 50, 0, 49, 52, 55
};
#define yypact_value_is_default(yystate) \
((yystate) == (-43))
((yystate) == (-30))
#define yytable_value_is_error(yytable_value) \
YYID (0)
static const yytype_int8 yycheck[] =
{
0, 7, 9, 45, 16, 17, 18, 49, 15, 15,
3, 4, 20, 6, 5, 8, 16, 17, 18, 19,
10, 11, 12, 13, 14, 3, 3, 3, 15, 3,
11, 6, 5, 19, 37, -1, -1, -1, -1, 11
0, 8, 11, 12, 13, 14, 15, 3, 9, 16,
11, 12, 13, 14, 15, 3, 4, 5, 10, 7,
20, 9, 51, 3, 16, 6, 6, 3, 57, 3,
17, 18, 19, 3, 4, 5, 21, 16, 7, 3,
24, 18, 10, -1, 39, 50, 52
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
0, 26, 0, 16, 17, 18, 19, 27, 28, 29,
30, 31, 32, 5, 3, 30, 32, 3, 20, 34,
3, 33, 6, 35, 15, 36, 3, 5, 37, 38,
10, 11, 12, 13, 14, 39, 7, 15, 3, 4,
8, 35, 40, 41, 38, 42, 40, 43, 9, 15,
40
0, 27, 0, 20, 28, 29, 30, 31, 3, 33,
17, 18, 19, 34, 6, 3, 32, 21, 37, 3,
35, 36, 7, 38, 16, 39, 36, 3, 6, 40,
41, 9, 11, 12, 13, 14, 15, 42, 8, 16,
3, 3, 4, 5, 9, 38, 43, 44, 45, 41,
10, 46, 42, 43, 47, 44, 10, 16, 43
};
#define yyerrok (yyerrstatus = 0)
@ -1547,116 +1564,238 @@ yyreduce:
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 18:
case 3:
/* Line 1806 of yacc.c */
#line 132 "config_parser.yy"
#line 107 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = make_shared<DynamicDictionary>();
m_Dictionaries.push(dictionary);
context->SetResult(m_Objects);
}
break;
case 7:
/* Line 1806 of yacc.c */
#line 119 "config_parser.yy"
{
m_Object = make_shared<DConfigObject>();
m_Abstract = false;
m_Local = false;
}
break;
case 8:
/* Line 1806 of yacc.c */
#line 125 "config_parser.yy"
{
m_Type = (yyvsp[(4) - (5)].text);
free((yyvsp[(4) - (5)].text));
m_Name = (yyvsp[(5) - (5)].text);
free((yyvsp[(5) - (5)].text));
}
break;
case 9:
/* Line 1806 of yacc.c */
#line 133 "config_parser.yy"
{
Object::Ptr exprl_object = *(yyvsp[(8) - (8)].variant);
delete (yyvsp[(8) - (8)].variant);
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
Expression typeexpr("__type", OperatorSet, m_Type);
exprl->AddExpression(typeexpr);
Expression nameexpr("__name", OperatorSet, m_Name);
exprl->AddExpression(nameexpr);
Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0);
exprl->AddExpression(abstractexpr);
Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0);
exprl->AddExpression(localexpr);
m_Object->SetExpressionList(exprl);
m_Objects[pair<string, string>(m_Type, m_Name)] = m_Object;
free((yyvsp[(4) - (8)].text));
free((yyvsp[(5) - (8)].text));
}
break;
case 12:
/* Line 1806 of yacc.c */
#line 164 "config_parser.yy"
{
m_Abstract = true;
}
break;
case 13:
/* Line 1806 of yacc.c */
#line 168 "config_parser.yy"
{
m_Local = true;
}
break;
case 16:
/* Line 1806 of yacc.c */
#line 178 "config_parser.yy"
{
m_Object->AddParent((yyvsp[(1) - (1)].text));
}
break;
case 19:
/* Line 1806 of yacc.c */
#line 138 "config_parser.yy"
#line 188 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
(yyval.variant) = new Variant(dictionary);
m_Dictionaries.pop();
m_ExpressionLists.push(make_shared<ExpressionList>());
}
break;
case 23:
case 20:
/* Line 1806 of yacc.c */
#line 152 "config_parser.yy"
#line 193 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
dictionary->SetProperty((yyvsp[(1) - (3)].text), *(yyvsp[(3) - (3)].variant), (yyvsp[(2) - (3)].op));
(yyval.variant) = new Variant(m_ExpressionLists.top());
m_ExpressionLists.pop();
}
break;
case 24:
/* Line 1806 of yacc.c */
#line 205 "config_parser.yy"
{
Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant));
free((yyvsp[(1) - (3)].text));
delete (yyvsp[(3) - (3)].variant);
m_ExpressionLists.top()->AddExpression(expr);
}
break;
case 28:
case 25:
/* Line 1806 of yacc.c */
#line 165 "config_parser.yy"
#line 213 "config_parser.yy"
{
Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant));
free((yyvsp[(3) - (6)].text));
delete (yyvsp[(6) - (6)].variant);
ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
subexprl->AddExpression(subexpr);
Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl);
m_ExpressionLists.top()->AddExpression(expr);
}
break;
case 26:
/* Line 1806 of yacc.c */
#line 226 "config_parser.yy"
{
Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text));
free((yyvsp[(1) - (1)].text));
m_ExpressionLists.top()->AddExpression(expr);
}
break;
case 31:
/* Line 1806 of yacc.c */
#line 239 "config_parser.yy"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
}
break;
case 29:
/* Line 1806 of yacc.c */
#line 171 "config_parser.yy"
{
(yyval.variant) = new Variant((yyvsp[(1) - (1)].text));
}
break;
case 30:
/* Line 1806 of yacc.c */
#line 175 "config_parser.yy"
{
(yyval.variant) = new Variant((yyvsp[(1) - (1)].num));
}
break;
case 32:
/* Line 1806 of yacc.c */
#line 180 "config_parser.yy"
#line 245 "config_parser.yy"
{
(yyval.variant) = (yyvsp[(1) - (1)].variant);
(yyval.variant) = new Variant((yyvsp[(1) - (1)].text));
}
break;
case 33:
/* Line 1806 of yacc.c */
#line 186 "config_parser.yy"
#line 249 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = make_shared<DynamicDictionary>();
m_Dictionaries.push(dictionary);
(yyval.variant) = new Variant((yyvsp[(1) - (1)].num));
}
break;
case 34:
/* Line 1806 of yacc.c */
#line 192 "config_parser.yy"
#line 253 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
(yyval.variant) = new Variant(dictionary);
m_Dictionaries.pop();
}
break;
case 36:
/* Line 1806 of yacc.c */
#line 203 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
//dictionary->AddUnnamedProperty(*$1);
delete (yyvsp[(1) - (1)].variant);
(yyval.variant) = new Variant();
}
break;
case 37:
/* Line 1806 of yacc.c */
#line 209 "config_parser.yy"
#line 261 "config_parser.yy"
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
//dictionary->AddUnnamedProperty(*$3);
(yyval.variant) = (yyvsp[(1) - (1)].variant);
}
break;
case 38:
/* Line 1806 of yacc.c */
#line 267 "config_parser.yy"
{
m_Array = make_shared<Dictionary>();
}
break;
case 39:
/* Line 1806 of yacc.c */
#line 272 "config_parser.yy"
{
(yyval.variant) = new Variant(m_Array);
m_Array.reset();
}
break;
case 41:
/* Line 1806 of yacc.c */
#line 281 "config_parser.yy"
{
m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant));
delete (yyvsp[(1) - (1)].variant);
}
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;
@ -1664,7 +1803,7 @@ yyreduce:
/* Line 1806 of yacc.c */
#line 1668 "config_parser.cc"
#line 1807 "config_parser.cc"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@ -1902,6 +2041,6 @@ yyreturn:
/* Line 2067 of yacc.c */
#line 215 "config_parser.yy"
#line 291 "config_parser.yy"

View File

@ -39,43 +39,45 @@
enum yytokentype {
T_STRING = 258,
T_NUMBER = 259,
T_IDENTIFIER = 260,
T_OPEN_BRACE = 261,
T_CLOSE_BRACE = 262,
T_OPEN_BRACKET = 263,
T_CLOSE_BRACKET = 264,
T_EQUAL = 265,
T_PLUS_EQUAL = 266,
T_MINUS_EQUAL = 267,
T_MULTIPLY_EQUAL = 268,
T_DIVIDE_EQUAL = 269,
T_COMMA = 270,
T_ABSTRACT = 271,
T_LOCAL = 272,
T_OBJECT = 273,
T_INCLUDE = 274,
T_INHERITS = 275
T_NULL = 260,
T_IDENTIFIER = 261,
T_OPEN_BRACE = 262,
T_CLOSE_BRACE = 263,
T_OPEN_BRACKET = 264,
T_CLOSE_BRACKET = 265,
T_EQUAL = 266,
T_PLUS_EQUAL = 267,
T_MINUS_EQUAL = 268,
T_MULTIPLY_EQUAL = 269,
T_DIVIDE_EQUAL = 270,
T_COMMA = 271,
T_ABSTRACT = 272,
T_LOCAL = 273,
T_OBJECT = 274,
T_INCLUDE = 275,
T_INHERITS = 276
};
#endif
/* Tokens. */
#define T_STRING 258
#define T_NUMBER 259
#define T_IDENTIFIER 260
#define T_OPEN_BRACE 261
#define T_CLOSE_BRACE 262
#define T_OPEN_BRACKET 263
#define T_CLOSE_BRACKET 264
#define T_EQUAL 265
#define T_PLUS_EQUAL 266
#define T_MINUS_EQUAL 267
#define T_MULTIPLY_EQUAL 268
#define T_DIVIDE_EQUAL 269
#define T_COMMA 270
#define T_ABSTRACT 271
#define T_LOCAL 272
#define T_OBJECT 273
#define T_INCLUDE 274
#define T_INHERITS 275
#define T_NULL 260
#define T_IDENTIFIER 261
#define T_OPEN_BRACE 262
#define T_CLOSE_BRACE 263
#define T_OPEN_BRACKET 264
#define T_CLOSE_BRACKET 265
#define T_EQUAL 266
#define T_PLUS_EQUAL 267
#define T_MINUS_EQUAL 268
#define T_MULTIPLY_EQUAL 269
#define T_DIVIDE_EQUAL 270
#define T_COMMA 271
#define T_ABSTRACT 272
#define T_LOCAL 273
#define T_OBJECT 274
#define T_INCLUDE 275
#define T_INHERITS 276
@ -85,17 +87,17 @@ typedef union YYSTYPE
{
/* Line 2068 of yacc.c */
#line 37 "config_parser.yy"
#line 36 "config_parser.yy"
char *text;
int num;
icinga::Variant *variant;
icinga::DynamicDictionaryOperator op;
icinga::ExpressionOperator op;
/* Line 2068 of yacc.c */
#line 99 "config_parser.h"
#line 101 "config_parser.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */

View File

@ -22,7 +22,6 @@
using namespace icinga;
Variant *z;
%}
%pure-parser
@ -38,11 +37,12 @@ Variant *z;
char *text;
int num;
icinga::Variant *variant;
icinga::DynamicDictionaryOperator op;
icinga::ExpressionOperator op;
}
%token <text> T_STRING
%token <num> T_NUMBER
%token T_NULL
%token <text> T_IDENTIFIER
%token T_OPEN_BRACE
%token T_CLOSE_BRACE
@ -59,9 +59,10 @@ Variant *z;
%token T_OBJECT
%token T_INCLUDE
%token T_INHERITS
%type <variant> simplevalue
%type <variant> value
%type <variant> array
%type <variant> dictionary
%type <variant> expressionlist
%type <op> operator
%left '+' '-'
%left '*' '/'
@ -90,13 +91,22 @@ void ConfigContext::Compile(void)
#define scanner (context->GetScanner())
static stack<DynamicDictionary::Ptr> m_Dictionaries;
static stack<ExpressionList::Ptr> m_ExpressionLists;
static map<pair<string, string>, DConfigObject::Ptr> m_Objects;
static DConfigObject::Ptr m_Object;
static string m_Name;
static string m_Type;
static bool m_Abstract;
static bool m_Local;
static Dictionary::Ptr m_Array;
%}
%%
statements: /* empty */
| statements statement
{
context->SetResult(m_Objects);
}
;
statement: object | include
@ -105,55 +115,119 @@ statement: object | include
include: T_INCLUDE T_STRING
;
object: attributes_list object_declaration
| object_declaration
object:
{
m_Object = make_shared<DConfigObject>();
m_Abstract = false;
m_Local = false;
}
attributes T_OBJECT T_IDENTIFIER T_STRING
{
m_Type = $4;
free($4);
m_Name = $5;
free($5);
}
inherits_specifier expressionlist
{
Object::Ptr exprl_object = *$8;
delete $8;
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
Expression typeexpr("__type", OperatorSet, m_Type);
exprl->AddExpression(typeexpr);
Expression nameexpr("__name", OperatorSet, m_Name);
exprl->AddExpression(nameexpr);
Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0);
exprl->AddExpression(abstractexpr);
Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0);
exprl->AddExpression(localexpr);
m_Object->SetExpressionList(exprl);
m_Objects[pair<string, string>(m_Type, m_Name)] = m_Object;
free($4);
free($5);
}
;
object_declaration: T_OBJECT T_IDENTIFIER T_STRING inherits_specifier dictionary
;
attributes_list: attributes_list attribute
| attribute
attributes: /* empty */
| attributes attribute
;
attribute: T_ABSTRACT
{
m_Abstract = true;
}
| T_LOCAL
{
m_Local = true;
}
;
inherits_list: T_STRING
| inherits_list T_COMMA T_STRING
inherits_list: inherits_item
| inherits_list T_COMMA inherits_item
;
inherits_item: T_STRING
{
m_Object->AddParent($1);
}
;
inherits_specifier: /* empty */
| T_INHERITS inherits_list
;
dictionary: T_OPEN_BRACE
expressionlist: T_OPEN_BRACE
{
DynamicDictionary::Ptr dictionary = make_shared<DynamicDictionary>();
m_Dictionaries.push(dictionary);
m_ExpressionLists.push(make_shared<ExpressionList>());
}
nvpairs
expressions
T_CLOSE_BRACE
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
$$ = new Variant(dictionary);
m_Dictionaries.pop();
$$ = new Variant(m_ExpressionLists.top());
m_ExpressionLists.pop();
}
;
nvpairs: /* empty */
| nvpair
| nvpairs T_COMMA nvpair
expressions: /* empty */
| expression
| expressions T_COMMA expression
;
nvpair: T_IDENTIFIER operator value
expression: T_IDENTIFIER operator value
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
dictionary->SetProperty($1, *$3, $2);
Expression expr($1, $2, *$3);
free($1);
delete $3;
m_ExpressionLists.top()->AddExpression(expr);
}
| T_IDENTIFIER T_OPEN_BRACKET T_STRING T_CLOSE_BRACKET operator value
{
Expression subexpr($3, $5, *$6);
free($3);
delete $6;
ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
subexprl->AddExpression(subexpr);
Expression expr($1, OperatorPlus, subexprl);
m_ExpressionLists.top()->AddExpression(expr);
}
| T_STRING
{
Expression expr($1, OperatorSet, $1);
free($1);
m_ExpressionLists.top()->AddExpression(expr);
}
;
@ -167,7 +241,7 @@ operator: T_EQUAL
}
;
value: T_STRING
simplevalue: T_STRING
{
$$ = new Variant($1);
}
@ -175,8 +249,15 @@ value: T_STRING
{
$$ = new Variant($1);
}
| T_NULL
{
$$ = new Variant();
}
;
value: simplevalue
| array
| dictionary
| expressionlist
{
$$ = $1;
}
@ -184,31 +265,26 @@ value: T_STRING
array: T_OPEN_BRACKET
{
DynamicDictionary::Ptr dictionary = make_shared<DynamicDictionary>();
m_Dictionaries.push(dictionary);
m_Array = make_shared<Dictionary>();
}
arrayitems
T_CLOSE_BRACKET
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
$$ = new Variant(dictionary);
m_Dictionaries.pop();
$$ = new Variant(m_Array);
m_Array.reset();
}
;
arrayitems:
/* empty */
| value
| simplevalue
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
//dictionary->AddUnnamedProperty(*$1);
m_Array->AddUnnamedProperty(*$1);
delete $1;
}
| arrayitems T_COMMA value
| arrayitems T_COMMA simplevalue
{
DynamicDictionary::Ptr dictionary = m_Dictionaries.top();
//dictionary->AddUnnamedProperty(*$3);
m_Array->AddUnnamedProperty(*$3);
delete $3;
}
;

View File

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

View File

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

23
dyn/dconfigobject.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "i2-dyn.h"
using namespace icinga;
ExpressionList::Ptr DConfigObject::GetExpressionList(void) const
{
return m_ExpressionList;
}
void DConfigObject::SetExpressionList(const ExpressionList::Ptr& exprl)
{
m_ExpressionList = exprl;
}
vector<string> DConfigObject::GetParents(void) const
{
return m_Parents;
}
void DConfigObject::AddParent(string parent)
{
m_Parents.push_back(parent);
}

29
dyn/dconfigobject.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef DCONFIGOBJECT_H
#define DCONFIGOBJECT_H
namespace icinga
{
class DConfigObject : public Object {
public:
typedef shared_ptr<DConfigObject> Ptr;
typedef weak_ptr<DConfigObject> WeakPtr;
vector<string> GetParents(void) const;
void AddParent(string parent);
ExpressionList::Ptr GetExpressionList(void) const;
void SetExpressionList(const ExpressionList::Ptr& exprl);
private:
string m_Type;
string m_Name;
vector<string> m_Parents;
ExpressionList::Ptr m_ExpressionList;
};
}
#endif /* DCONFIGOBJECT_H */

52
dyn/expression.cpp Normal file
View File

@ -0,0 +1,52 @@
/******************************************************************************
* 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. *
******************************************************************************/
#include "i2-dyn.h"
using namespace icinga;
Expression::Expression(string key, ExpressionOperator op, Variant value)
{
Key = key;
Operator = op;
Value = value;
}
void Expression::Execute(const Dictionary::Ptr& dictionary)
{
Variant oldValue, newValue;
dictionary->GetProperty(Key, &oldValue);
switch (Operator) {
case OperatorSet:
if (oldValue.GetType() == VariantObject) {
Object::Ptr object = oldValue;
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(object);
if (exprl)
newValue = exprl->Execute();
}
default:
assert(!"Not yet implemented.");
}
dictionary->SetProperty(Key, newValue);
}

View File

@ -17,13 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#ifndef DYNAMICDICTIONARY_H
#define DYNAMICDICTIONARY_H
#ifndef EXPRESSION_H
#define EXPRESSION_H
namespace icinga
{
enum DynamicDictionaryOperator
enum ExpressionOperator
{
OperatorSet,
OperatorPlus,
@ -32,56 +32,17 @@ enum DynamicDictionaryOperator
OperatorDivide
};
struct DynamicDictionaryValue
struct I2_DYN_API Expression
{
string Key;
ExpressionOperator Operator;
Variant Value;
DynamicDictionaryOperator Operator;
};
class I2_DYN_API DynamicDictionary : public Object
{
public:
typedef shared_ptr<DynamicDictionary> Ptr;
typedef weak_ptr<DynamicDictionary> WeakPtr;
Expression(string key, ExpressionOperator op, Variant value);
DynamicDictionary(void);
// DynamicDictionary(Dictionary::Ptr serializedDictionary);
// void AddParent(DynamicDictionary::Ptr parent);
// void ClearParents(void);
template<typename T>
bool GetProperty(string name, T *value, DynamicDictionaryOperator *op) const
{
map<string, DynamicDictionaryValue>::const_iterator di;
di = m_Values.find(name);
if (di == m_Values.end())
return false;
*value = di->second.Value;
*op = di->second.Operator;
return true;
}
template<typename T>
void SetProperty(string name, const T& value, DynamicDictionaryOperator op)
{
DynamicDictionaryValue ddv;
ddv.Value = value;
ddv.Operator = op;
m_Values[name] = ddv;
}
// Dictionary::Ptr ToFlatDictionary(void) const;
// Dictionary::Ptr Serialize(void);
private:
// set<DynamicDictionary::Ptr> m_Parents;
map<string, DynamicDictionaryValue> m_Values;
void Execute(const Dictionary::Ptr& dictionary);
};
}
#endif /* DYNAMICDICTIONARY_H */
#endif /* EXPRESSION_H */

View File

@ -21,6 +21,17 @@
using namespace icinga;
DynamicDictionary::DynamicDictionary(void)
ExpressionList::ExpressionList(void)
{
}
void ExpressionList::AddExpression(const Expression& expression)
{
m_Expressions.push_back(expression);
}
size_t ExpressionList::GetLength(void) const
{
return m_Expressions.size();
}

50
dyn/expressionlist.h Normal file
View File

@ -0,0 +1,50 @@
/******************************************************************************
* 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 EXPRESSIONLIST_H
#define EXPRESSIONLIST_H
namespace icinga
{
class I2_DYN_API ExpressionList : public Object
{
public:
typedef shared_ptr<ExpressionList> Ptr;
typedef weak_ptr<ExpressionList> WeakPtr;
ExpressionList(void);
// ExpressionList(Dictionary::Ptr serializedDictionary);
void AddExpression(const Expression& expression);
Dictionary::Ptr Execute(void) const;
Dictionary::Ptr Execute(Dictionary::Ptr input) const;
size_t GetLength(void) const;
// Dictionary::Ptr Serialize(void);
private:
vector<Expression> m_Expressions;
};
}
#endif /* EXPRESSIONLIST_H */

View File

@ -37,10 +37,12 @@
# define I2_DYN_API I2_IMPORT
#endif /* I2_DYN_BUILD */
#include "configcontext.h"
#include "dynamicdictionary.h"
#include "expression.h"
#include "expressionlist.h"
#include "dynamicobject.h"
#include "objectset.h"
#include "objectmap.h"
#include "dconfigobject.h"
#include "configcontext.h"
#endif /* I2DYN_H */

View File

@ -6,5 +6,14 @@ int main(int argc, char **argv)
{
ConfigContext ctx;
ctx.Compile();
map<pair<string, string>, DConfigObject::Ptr> objects = ctx.GetResult();
for (auto it = objects.begin(); it != objects.end(); it++) {
DConfigObject::Ptr obj = it->second;
cout << "Object, name: " << it->first.second << ", type: " << it->first.first << endl;
cout << "\t" << obj->GetParents().size() << " parents" << endl;
cout << "\t" << obj->GetExpressionList()->GetLength() << " top-level exprs" << endl;
}
return 0;
}