ROSE  0.11.145.0
AstFromString.h
1 #ifndef __AST_FROM_STRING_H__
2 #define __AST_FROM_STRING_H__
3 
8 #include <iostream>
9 #include <vector>
10 
17 namespace AstFromString
18 {
19 
20  //--------------------------------------------------------------
22 
26  #define OFS_MAX_LEN 256
28 
31  ROSE_DLL_API extern const char* c_char;
32 
34  ROSE_DLL_API extern SgNode* c_sgnode;
35 
37  ROSE_DLL_API extern SgNode* c_parsed_node;
38 
40 
41 
43 
47  bool afs_is_digit();
49 
52 
54  bool afs_is_letter();
55 
57  bool afs_is_lower_letter();
58 
60  bool afs_is_upper_letter();
61 
63 
65 
71  ROSE_DLL_API bool afs_match_char(char c);
73 
86  ROSE_DLL_API bool afs_match_substr(const char* substr, bool checkTrail = true);
87 
89  ROSE_DLL_API bool afs_skip_whitespace();
90 
92  ROSE_DLL_API bool afs_match_identifier();
93 
95  ROSE_DLL_API bool afs_match_integer_const(int * result);
96 
98  ROSE_DLL_API bool afs_match_double_const(double * result);
99 
101  ROSE_DLL_API bool afs_match_translation_unit();
102 
104  ROSE_DLL_API bool afs_match_external_declaration();
105 
107  ROSE_DLL_API bool afs_match_function_definition();
108 
110  ROSE_DLL_API bool afs_match_declaration();
111 
113  ROSE_DLL_API bool afs_match_declaration_specifiers(SgType** tt);
114 
116  ROSE_DLL_API bool afs_match_init_declarator_list();
117 
119  ROSE_DLL_API bool afs_match_init_declarator(SgType* orig_type, SgType** mod_type, SgName** sname, SgExpression** initializer);
120 
122  ROSE_DLL_API bool afs_match_storage_class_specifier();
123 
127  ROSE_DLL_API bool afs_match_type_specifier(bool checkTrail = true);
128 
129  // type_id in ANTLR grammar
130  //struct_or_union_specifier
131  //struct_or_union
132  //struct_declaration_list
133  //struct_declaration
135  ROSE_DLL_API bool afs_match_specifier_qualifier_list(std::vector<SgNode*> &);
136  //struct_declarator_list
137  //struct_declarator
138  // enum_specifier
139  //enumerator_list
140  // enumerator
142  ROSE_DLL_API bool afs_match_type_qualifier();
143 
145  ROSE_DLL_API bool afs_match_declarator(SgType* orig_type, SgType** modified_type);
146 
148  ROSE_DLL_API bool afs_match_direct_declarator();
149  // declarator_suffix
150 
152  ROSE_DLL_API bool afs_match_pointer(SgType* orig_type);
153 
154  //parameter_type_list
155  // parameter_list
156  //parameter_declaration
157  // identifier_list
159  ROSE_DLL_API bool afs_match_type_name();
160  //abstract_declarator
161  //direct_abstract_declarator
162  //abstract_declarator_suffix
163  // initializer
164  bool afs_match_initializer();
165  // initializer_list
166 
167 
169 
172  //-----------------------------------------
174  ROSE_DLL_API bool afs_match_argument_expression_list();
175 
177  ROSE_DLL_API bool afs_match_additive_expression();
178 
180  ROSE_DLL_API bool afs_match_multiplicative_expression();
181 
183  ROSE_DLL_API bool afs_match_cast_expression();
184 
186  ROSE_DLL_API bool afs_match_unary_expression();
187 
189  ROSE_DLL_API bool afs_match_postfix_expression();
190 
192  ROSE_DLL_API bool afs_match_primary_expression();
193 
195  ROSE_DLL_API bool afs_match_constant();
196 
198  ROSE_DLL_API bool afs_match_expression();
199 
201  ROSE_DLL_API bool afs_match_constant_expression();
202 
204  ROSE_DLL_API bool afs_match_assignment_expression();
205 
207  ROSE_DLL_API bool afs_match_lvalue();
208  // assignment_operator, included in assignment_expression in this implementation
210  ROSE_DLL_API bool afs_match_conditional_expression();
211 
213  ROSE_DLL_API bool afs_match_logical_or_expression();
214 
216  ROSE_DLL_API bool afs_match_logical_and_expression();
217 
219  ROSE_DLL_API bool afs_match_inclusive_or_expression();
220 
222  ROSE_DLL_API bool afs_match_exclusive_or_expression();
223 
225  ROSE_DLL_API bool afs_match_and_expression();
226 
228  ROSE_DLL_API bool afs_match_equality_expression();
229 
231  ROSE_DLL_API bool afs_match_relational_expression();
232 
234  ROSE_DLL_API bool afs_match_shift_expression();
236 
237  //-----------------------------------------
239 
242  ROSE_DLL_API bool afs_match_statement();
244 
246  ROSE_DLL_API bool afs_match_labeled_statement();
248  ROSE_DLL_API bool afs_match_compound_statement();
250  ROSE_DLL_API bool afs_match_expression_statement();
252  ROSE_DLL_API bool afs_match_selection_statement();
254  ROSE_DLL_API bool afs_match_iteration_statement();
256  ROSE_DLL_API bool afs_match_jump_statement();
257 
259 }
260 
261 #endif /* __AST_FROM_STRING_H__ */
262 
ROSE_DLL_API bool afs_match_unary_expression()
unary_expression : postfix_expression | INC_OP unary_expression | DEC_OP unary_expression | unary_ope...
ROSE_DLL_API bool afs_match_function_definition()
Match a function definition. Not yet implemented.
ROSE_DLL_API bool afs_match_external_declaration()
Match an external declaration. Not yet implemented.
ROSE_DLL_API SgNode * c_sgnode
current anchor SgNode associated with parsing. It will serve as a start point to find enclosing scope...
ROSE_DLL_API bool afs_match_multiplicative_expression()
multiplicative_expression : (cast_expression) ('*' cast_expression | '/' cast_expression | '' cast_ex...
ROSE_DLL_API bool afs_match_equality_expression()
equality_expression : relational_expression (('=='|'!=') relational_expression)*
ROSE_DLL_API bool afs_match_storage_class_specifier()
Match a storage class specifier. Not yet implemented.
ROSE_DLL_API bool afs_skip_whitespace()
Match and skip whitespace.
ROSE_DLL_API bool afs_match_conditional_expression()
conditional_expression : logical_or_expression ('?' expression ':' conditional_expression)? '?' means 0 or 1 occurrence
ROSE_DLL_API bool afs_match_declaration()
Match a declaration. Only the simplest int i=9; style declaration is supported for now...
bool afs_match_initializer()
match a char, advance one position if successful.
bool afs_is_identifier_char()
Check if the current character is a legal identifier character, including letters, digits, '_' and '$' (For fortran). No side effect on the current position.
ROSE_DLL_API bool afs_match_lvalue()
lvalue: unary_expression
This class represents the base class for all types.
ROSE_DLL_API bool afs_match_selection_statement()
Match selection statement: IF '(' expression ')' statement | IF '(' expression ')' statement ELSE sta...
bool afs_is_letter()
Check if the current character is a letter. No side effect on the current position of the input strin...
ROSE_DLL_API bool afs_match_expression_statement()
Match expression statement: : ';' | expression ';'.
ROSE_DLL_API bool afs_match_substr(const char *substr, bool checkTrail=true)
Match a sub string: a given sub c string from the input c string, again skip heading space/tabs if an...
ROSE_DLL_API bool afs_match_relational_expression()
relational_expression : shift_expression (('<'|'>'|'<='|'>=') shift_expression)*
ROSE_DLL_API bool afs_match_postfix_expression()
postfix_expression : primary_expression ( '[' expression ']' | '(' ')' | '(' argument_expression_list...
ROSE_DLL_API bool afs_match_specifier_qualifier_list(std::vector< SgNode * > &)
Match a list of specifiers and qualifiers : : ( type_qualifier | type_specifier )+.
ROSE_DLL_API bool afs_match_shift_expression()
shift_expression : additive_expression (('<<'|'>>') additive_expression)*
ROSE_DLL_API bool afs_match_jump_statement()
Match a jump statement : 'goto' IDENTIFIER ';' | 'continue' ';' | 'break' ';' | 'return' ';' | 'retur...
ROSE_DLL_API bool afs_match_init_declarator(SgType *orig_type, SgType **mod_type, SgName **sname, SgExpression **initializer)
Match init declarator. Store created mod_type, name, and initializer. Original type is needed as inpu...
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
bool afs_is_lower_letter()
Check if the current character is a lower case letter.
ROSE_DLL_API bool afs_match_declaration_specifiers(SgType **tt)
Match declaration specifiers, store the matched type into *tt.
This class represents strings within the IR nodes.
ROSE_DLL_API bool afs_match_type_name()
Match a type name : specifier_qualifier_list abstract_declarator?
ROSE_DLL_API bool afs_match_char(char c)
match a char, advance one position if successful.
ROSE_DLL_API bool afs_match_assignment_expression()
assignment_expression : lvalue assignment_operator assignment_expression | conditional_expression ...
ROSE_DLL_API bool afs_match_labeled_statement()
Match labeled statement : IDENTIFIER ':' statement | 'case' constant_expression ':' statement | 'defa...
ROSE_DLL_API bool afs_match_pointer(SgType *orig_type)
Pointer constructs like * type.
ROSE_DLL_API bool afs_match_iteration_statement()
Match an iteration statement: : 'while' '(' expression ')' statement | 'do' statement 'while' '(' exp...
bool afs_is_digit()
Check if the current character is a digit. The current position of the input string remains unchanged...
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9846
ROSE_DLL_API bool afs_match_and_expression()
and_expression : equality_expression ('&' equality_expression)*
ROSE_DLL_API bool afs_match_double_const(double *result)
Match an double constant, store it into result.
ROSE_DLL_API bool afs_match_type_qualifier()
Match a type qualifier : 'const' | 'volatile'.
ROSE_DLL_API bool afs_match_exclusive_or_expression()
exclusive_or_expression : and_expression ('^' and_expression)*
ROSE_DLL_API SgNode * c_parsed_node
Store the AST substree (expression, statement) generated from a helper function.
ROSE_DLL_API bool afs_match_expression()
expression : assignment_expression (',' assignment_expression)*. Match one or more assignment_express...
ROSE_DLL_API bool afs_match_logical_and_expression()
logical_and_expression : inclusive_or_expression ('&&' inclusive_or_expression)*
ROSE_DLL_API bool afs_match_integer_const(int *result)
Match an integer constant, store it into result.
ROSE_DLL_API bool afs_match_init_declarator_list()
Match an init declarator list. Not yet implemented.
bool afs_is_upper_letter()
Check if the current character is a upper case letter.
ROSE_DLL_API bool afs_match_inclusive_or_expression()
inclusive_or_expression : exclusive_or_expression ('|' exclusive_or_expression)*
ROSE_DLL_API bool afs_match_primary_expression()
primary_expression : IDENTIFIER | constant | '(' expression ')'
ROSE_DLL_API bool afs_match_identifier()
Match identifier, move to the next character if successful. The identifier could be a name of a type...
ROSE_DLL_API const char * c_char
A namespace scope char* to avoid passing and returning a target c string for every and each function ...
ROSE_DLL_API bool afs_match_logical_or_expression()
logical_or_expression : logical_and_expression ('||' logical_and_expression)*
ROSE_DLL_API bool afs_match_constant()
Only integer constant is supported for now. Full grammar is constant : HEX_LITERAL | OCTAL_LITERAL | ...
ROSE_DLL_API bool afs_match_direct_declarator()
Match a direct declarator.
Parser building blocks for creating simple recursive descent parsers generating AST from strings...
Definition: AstFromString.h:17
ROSE_DLL_API bool afs_match_type_specifier(bool checkTrail=true)
ROSE_DLL_API bool afs_match_translation_unit()
Match a translation unit. Not yet implemented.
ROSE_DLL_API bool afs_match_compound_statement()
Not yet implemented. Match compound statement: '{' declaration* statement_list? '}'.
ROSE_DLL_API bool afs_match_argument_expression_list()
Grammar: argument_expression_list : assignment_expression (',' assignment_expression)* one assignment...
ROSE_DLL_API bool afs_match_cast_expression()
cast_expression : '(' type_name ')' cast_expression | unary_expression
ROSE_DLL_API bool afs_match_declarator(SgType *orig_type, SgType **modified_type)
Match a declarator.
ROSE_DLL_API bool afs_match_additive_expression()
Grammar: additive_expression : (multiplicative_expression) ('+' multiplicative_expression | '-' multi...
ROSE_DLL_API bool afs_match_constant_expression()
constant_expression : conditional_expression
ROSE_DLL_API bool afs_match_statement()
match any statement, not complete yet. Don't use it yet . : labeled_statement | compound_statement | ...