Commit | Line | Data |
---|---|---|
e98a2d6e PP |
1 | %{ |
2 | /* | |
06a626b8 | 3 | * lexer.l |
e98a2d6e PP |
4 | * |
5 | * Common Trace Formal Lexer | |
6 | * | |
7 | * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
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: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
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 | |
25 | * SOFTWARE. | |
26 | */ | |
27 | ||
0746848c | 28 | #define BT_LOG_OUTPUT_LEVEL ctf_plugin_metadata_log_level |
f73367f8 PP |
29 | #define BT_LOG_TAG "PLUGIN-CTF-METADATA-LEXER" |
30 | #include "logging.h" | |
31 | ||
e98a2d6e PP |
32 | #include <stdio.h> |
33 | #include <ctype.h> | |
06a626b8 | 34 | #include "scanner.h" |
9103e903 | 35 | #include "parser-wrap.h" |
06a626b8 | 36 | #include "ast.h" |
e98a2d6e | 37 | |
f73367f8 PP |
38 | #define YY_FATAL_ERROR(_msg) BT_LOGF_STR(_msg) |
39 | ||
e98a2d6e PP |
40 | #define PARSE_INTEGER_LITERAL(base) \ |
41 | do { \ | |
42 | errno = 0; \ | |
43 | yylval->ull = strtoull(yytext, NULL, base); \ | |
44 | if (errno) { \ | |
f73367f8 PP |
45 | _BT_LOGE_LINENO(yylineno, \ |
46 | "Cannot parser constant integer: " \ | |
47 | "base=%d, text=\"%s\"", base, yytext); \ | |
48 | return CTF_ERROR; \ | |
e98a2d6e PP |
49 | } \ |
50 | } while (0) | |
e98a2d6e PP |
51 | %} |
52 | ||
53 | %x comment_ml comment_sl string_lit char_const | |
54 | %option reentrant yylineno noyywrap bison-bridge | |
55 | %option extra-type="struct ctf_scanner *" | |
56 | /* bison-locations */ | |
57 | INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) | |
58 | DIGIT [0-9] | |
59 | NONDIGIT [a-zA-Z_] | |
60 | HEXDIGIT [0-9A-Fa-f] | |
61 | OCTALDIGIT [0-7] | |
62 | UCHARLOWERCASE \\u{HEXDIGIT}{4} | |
63 | UCHARUPPERCASE \\U{HEXDIGIT}{8} | |
64 | ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE} | |
65 | IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})* | |
66 | %% | |
67 | ||
68 | /* | |
69 | * Using start conditions to deal with comments | |
70 | * and strings. | |
f73367f8 | 71 | */ |
e98a2d6e PP |
72 | |
73 | "/*" BEGIN(comment_ml); | |
74 | <comment_ml>[^*\n]* /* eat anything that's not a '*' */ | |
75 | <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ | |
76 | <comment_ml>\n | |
77 | <comment_ml>"*"+"/" BEGIN(INITIAL); | |
78 | ||
79 | "//"[^\n]*\n /* skip comment */ | |
80 | ||
d4c6eae5 MJ |
81 | L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return CTF_ERROR; else return CTF_STRING_LITERAL; } |
82 | L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return CTF_ERROR; else return CTF_CHARACTER_LITERAL; } | |
e98a2d6e | 83 | |
d4c6eae5 MJ |
84 | "[" return CTF_LSBRAC; |
85 | "]" return CTF_RSBRAC; | |
86 | "(" return CTF_LPAREN; | |
87 | ")" return CTF_RPAREN; | |
88 | "{" return CTF_LBRAC; | |
89 | "}" return CTF_RBRAC; | |
90 | "->" return CTF_RARROW; | |
91 | "*" return CTF_STAR; | |
92 | "+" return CTF_PLUS; | |
93 | "-" return CTF_MINUS; | |
94 | "<" return CTF_LT; | |
95 | ">" return CTF_GT; | |
96 | := return CTF_TYPEASSIGN; | |
97 | : return CTF_COLON; | |
98 | ; return CTF_SEMICOLON; | |
99 | "..." return CTF_DOTDOTDOT; | |
100 | "." return CTF_DOT; | |
101 | = return CTF_EQUAL; | |
102 | "," return CTF_COMMA; | |
103 | align setstring(yyextra, yylval, yytext); return CTF_TOK_ALIGN; | |
104 | const setstring(yyextra, yylval, yytext); return CTF_CONST; | |
105 | char setstring(yyextra, yylval, yytext); return CTF_CHAR; | |
106 | clock setstring(yyextra, yylval, yytext); return CTF_CLOCK; | |
107 | double setstring(yyextra, yylval, yytext); return CTF_DOUBLE; | |
108 | enum setstring(yyextra, yylval, yytext); return CTF_ENUM; | |
109 | env setstring(yyextra, yylval, yytext); return CTF_ENV; | |
110 | event setstring(yyextra, yylval, yytext); return CTF_EVENT; | |
111 | floating_point setstring(yyextra, yylval, yytext); return CTF_FLOATING_POINT; | |
112 | float setstring(yyextra, yylval, yytext); return CTF_FLOAT; | |
113 | integer setstring(yyextra, yylval, yytext); return CTF_INTEGER; | |
114 | int setstring(yyextra, yylval, yytext); return CTF_INT; | |
115 | long setstring(yyextra, yylval, yytext); return CTF_LONG; | |
116 | short setstring(yyextra, yylval, yytext); return CTF_SHORT; | |
117 | signed setstring(yyextra, yylval, yytext); return CTF_SIGNED; | |
118 | stream setstring(yyextra, yylval, yytext); return CTF_STREAM; | |
119 | string setstring(yyextra, yylval, yytext); return CTF_STRING; | |
120 | struct setstring(yyextra, yylval, yytext); return CTF_STRUCT; | |
121 | trace setstring(yyextra, yylval, yytext); return CTF_TRACE; | |
122 | callsite setstring(yyextra, yylval, yytext); return CTF_CALLSITE; | |
123 | typealias setstring(yyextra, yylval, yytext); return CTF_TYPEALIAS; | |
124 | typedef setstring(yyextra, yylval, yytext); return CTF_TYPEDEF; | |
125 | unsigned setstring(yyextra, yylval, yytext); return CTF_UNSIGNED; | |
126 | variant setstring(yyextra, yylval, yytext); return CTF_VARIANT; | |
127 | void setstring(yyextra, yylval, yytext); return CTF_VOID; | |
128 | _Bool setstring(yyextra, yylval, yytext); return CTF_BOOL; | |
129 | _Complex setstring(yyextra, yylval, yytext); return CTF_COMPLEX; | |
130 | _Imaginary setstring(yyextra, yylval, yytext); return CTF_IMAGINARY; | |
131 | [1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return CTF_INTEGER_LITERAL; | |
132 | 0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return CTF_INTEGER_LITERAL; | |
133 | 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return CTF_INTEGER_LITERAL; | |
e98a2d6e | 134 | |
ef267d12 | 135 | {IDENTIFIER} BT_LOGT("Got identifier: id=\"%s\"", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; |
e98a2d6e | 136 | [ \t\r\n] ; /* ignore */ |
f73367f8 | 137 | . _BT_LOGE_LINENO(yylineno, "Invalid character: char=\"%c\", val=0x%02x", isprint(yytext[0]) ? yytext[0] : '\0', yytext[0]); return CTF_ERROR; |
e98a2d6e | 138 | %% |