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