5 * Common Trace Formal Lexer
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-LEXER"
37 #define YY_FATAL_ERROR(_msg) BT_LOGF_STR(_msg)
39 #define PARSE_INTEGER_LITERAL(base) \
42 yylval->ull = strtoull(yytext, NULL, base); \
44 _BT_LOGE_LINENO(yylineno, \
45 "Cannot parser constant integer: " \
46 "base=%d, text=\"%s\"", base, yytext); \
52 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
54 static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
55 __attribute__((unused));
56 static int input (yyscan_t yyscanner) __attribute__((unused));
59 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
63 %x comment_ml comment_sl string_lit char_const
64 %option reentrant yylineno noyywrap bison-bridge
65 %option extra-type="struct ctf_scanner *"
67 INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
72 UCHARLOWERCASE \\u{HEXDIGIT}{4}
73 UCHARUPPERCASE \\U{HEXDIGIT}{8}
74 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
75 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
79 * Using start conditions to deal with comments
83 "/*" BEGIN(comment_ml);
84 <comment_ml>[^*\n]* /* eat anything that's not a '*' */
85 <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
87 <comment_ml>"*"+"/" BEGIN(INITIAL);
89 "//"[^\n]*\n /* skip comment */
91 L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return CTF_ERROR; else return CTF_STRING_LITERAL; }
92 L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return CTF_ERROR; else return CTF_CHARACTER_LITERAL; }
94 "[" return CTF_LSBRAC;
95 "]" return CTF_RSBRAC;
96 "(" return CTF_LPAREN;
97 ")" return CTF_RPAREN;
100 "->" return CTF_RARROW;
103 "-" return CTF_MINUS;
106 := return CTF_TYPEASSIGN;
108 ; return CTF_SEMICOLON;
109 "..." return CTF_DOTDOTDOT;
112 "," return CTF_COMMA;
113 align setstring(yyextra, yylval, yytext); return CTF_TOK_ALIGN;
114 const setstring(yyextra, yylval, yytext); return CTF_CONST;
115 char setstring(yyextra, yylval, yytext); return CTF_CHAR;
116 clock setstring(yyextra, yylval, yytext); return CTF_CLOCK;
117 double setstring(yyextra, yylval, yytext); return CTF_DOUBLE;
118 enum setstring(yyextra, yylval, yytext); return CTF_ENUM;
119 env setstring(yyextra, yylval, yytext); return CTF_ENV;
120 event setstring(yyextra, yylval, yytext); return CTF_EVENT;
121 floating_point setstring(yyextra, yylval, yytext); return CTF_FLOATING_POINT;
122 float setstring(yyextra, yylval, yytext); return CTF_FLOAT;
123 integer setstring(yyextra, yylval, yytext); return CTF_INTEGER;
124 int setstring(yyextra, yylval, yytext); return CTF_INT;
125 long setstring(yyextra, yylval, yytext); return CTF_LONG;
126 short setstring(yyextra, yylval, yytext); return CTF_SHORT;
127 signed setstring(yyextra, yylval, yytext); return CTF_SIGNED;
128 stream setstring(yyextra, yylval, yytext); return CTF_STREAM;
129 string setstring(yyextra, yylval, yytext); return CTF_STRING;
130 struct setstring(yyextra, yylval, yytext); return CTF_STRUCT;
131 trace setstring(yyextra, yylval, yytext); return CTF_TRACE;
132 callsite setstring(yyextra, yylval, yytext); return CTF_CALLSITE;
133 typealias setstring(yyextra, yylval, yytext); return CTF_TYPEALIAS;
134 typedef setstring(yyextra, yylval, yytext); return CTF_TYPEDEF;
135 unsigned setstring(yyextra, yylval, yytext); return CTF_UNSIGNED;
136 variant setstring(yyextra, yylval, yytext); return CTF_VARIANT;
137 void setstring(yyextra, yylval, yytext); return CTF_VOID;
138 _Bool setstring(yyextra, yylval, yytext); return CTF_BOOL;
139 _Complex setstring(yyextra, yylval, yytext); return CTF_COMPLEX;
140 _Imaginary setstring(yyextra, yylval, yytext); return CTF_IMAGINARY;
141 [1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return CTF_INTEGER_LITERAL;
142 0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return CTF_INTEGER_LITERAL;
143 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return CTF_INTEGER_LITERAL;
145 {IDENTIFIER} BT_LOGV("Got identifier: id=\"%s\"", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
146 [ \t\r\n] ; /* ignore */
147 . _BT_LOGE_LINENO(yylineno, "Invalid character: char=\"%c\", val=0x%02x", isprint(yytext[0]) ? yytext[0] : '\0', yytext[0]); return CTF_ERROR;