2 /******************************************************************************
4 * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
6 * This program is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU General Public License *
8 * as published by the Free Software Foundation; either version 2 *
9 * of the License, or (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software Foundation *
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ******************************************************************************/
21 #include "classcompiler.hpp"
23 using namespace icinga;
25 #define YYLTYPE icinga::ClassDebugInfo
27 #include "class_parser.hh"
29 #define YY_EXTRA_TYPE ClassCompiler *
30 #define YY_USER_ACTION \
32 yylloc->path = yyextra->GetPath(); \
33 yylloc->first_line = yylineno; \
34 yylloc->first_column = yycolumn; \
35 yylloc->last_line = yylineno; \
36 yylloc->last_column = yycolumn + yyleng - 1; \
40 #define YY_INPUT(buf, result, max_size) \
42 result = yyextra->ReadInput(buf, max_size); \
50 static void lb_init(lex_buf *lb)
56 /*static void lb_cleanup(lex_buf *lb)
61 static void lb_append_char(lex_buf *lb, char new_char)
63 const size_t block_size = 64;
65 size_t old_blocks = (lb->size + (block_size - 1)) / block_size;
66 size_t new_blocks = ((lb->size + 1) + (block_size - 1)) / block_size;
68 if (old_blocks != new_blocks) {
69 char *new_buf = (char *)realloc(lb->buf, new_blocks * block_size);
71 if (new_buf == NULL && new_blocks > 0)
72 throw std::bad_alloc();
78 lb->buf[lb->size - 1] = new_char;
81 static char *lb_steal(lex_buf *lb)
83 lb_append_char(lb, '\0');
92 %option reentrant noyywrap yylineno
93 %option bison-bridge bison-locations
94 %option never-interactive nounistd
95 %option noinput nounput
103 \{\{\{ { lb_init(&string_buf); BEGIN(HEREDOC); }
108 lb_append_char(&string_buf, '\0');
110 yylval->text = lb_steal(&string_buf);
115 <HEREDOC>(.|\n) { lb_append_char(&string_buf, yytext[0]); }
117 "/*" { BEGIN(C_COMMENT); }
120 "*/" { BEGIN(INITIAL); }
121 [^*] /* ignore comment */
122 "*" /* ignore star */
126 fprintf(stderr, "End-of-file while in comment.\n");
129 \/\/[^\n]* /* ignore C++-style comments */
130 [ \t\r\n] /* ignore whitespace */
132 #include { return T_INCLUDE; }
133 #impl_include { return T_IMPL_INCLUDE; }
134 class { return T_CLASS; }
135 namespace { return T_NAMESPACE; }
136 code { return T_CODE; }
137 load_after { return T_LOAD_AFTER; }
138 library { return T_LIBRARY; }
139 abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
140 vararg_constructor { yylval->num = TAVarArgConstructor; return T_CLASS_ATTRIBUTE; }
141 config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; }
142 state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; }
143 enum { yylval->num = FAEnum; return T_FIELD_ATTRIBUTE; }
144 get_protected { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
145 set_protected { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; }
146 protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; }
147 no_storage { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
148 no_user_modify { yylval->num = FANoUserModify; return T_FIELD_ATTRIBUTE; }
149 no_user_view { yylval->num = FANoUserView; return T_FIELD_ATTRIBUTE; }
150 deprecated { yylval->num = FADeprecated; return T_FIELD_ATTRIBUTE; }
151 get_virtual { yylval->num = FAGetVirtual; return T_FIELD_ATTRIBUTE; }
152 set_virtual { yylval->num = FASetVirtual; return T_FIELD_ATTRIBUTE; }
153 virtual { yylval->num = FAGetVirtual | FASetVirtual; return T_FIELD_ATTRIBUTE; }
154 navigation { return T_NAVIGATION; }
155 validator { return T_VALIDATOR; }
156 required { return T_REQUIRED; }
157 name { return T_NAME; }
158 array { return T_ARRAY; }
159 default { yylval->num = FTDefault; return T_FIELD_ACCESSOR_TYPE; }
160 get { yylval->num = FTGet; return T_FIELD_ACCESSOR_TYPE; }
161 set { yylval->num = FTSet; return T_FIELD_ACCESSOR_TYPE; }
162 track { yylval->num = FTTrack; return T_FIELD_ACCESSOR_TYPE; }
163 navigate { yylval->num = FTNavigate; return T_FIELD_ACCESSOR_TYPE; }
164 \"[^\"]+\" { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_STRING; }
165 \<[^ \>]*\> { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_ANGLE_STRING; }
166 [a-zA-Z_][:a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
172 void ClassCompiler::InitializeScanner(void)
174 yylex_init(&m_Scanner);
175 yyset_extra(this, m_Scanner);
178 void ClassCompiler::DestroyScanner(void)
180 yylex_destroy(m_Scanner);