2 This file is used to be the grammar file of ECC tool
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 # The file defines the Lexer for C source files.
26 # THIS FILE IS AUTO-GENENERATED. PLEASE DON NOT MODIFY THIS FILE.
27 # This file is generated by running:
28 # java org.antlr.Tool C.g
30 # Copyright (c) 2009 - 2010, Intel Corporation All rights reserved.
32 # This program and the accompanying materials are licensed and made available
33 # under the terms and conditions of the BSD License which accompanies this
34 # distribution. The full text of the license may be found at:
35 # http://opensource.org/licenses/bsd-license.php
37 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
38 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
45 # The file defines the parser for C source files.
47 # THIS FILE IS AUTO-GENENERATED. PLEASE DON NOT MODIFY THIS FILE.
48 # This file is generated by running:
49 # java org.antlr.Tool C.g
51 # Copyright (c) 2009 - 2010, Intel Corporation All rights reserved.
53 # This program and the accompanying materials are licensed and made available
54 # under the terms and conditions of the BSD License which accompanies this
55 # distribution. The full text of the license may be found at:
56 # http://opensource.org/licenses/bsd-license.php
58 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
59 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
69 def printTokenInfo(self, line, offset, tokenText):
70 print str(line)+ ',' + str(offset) + ':' + str(tokenText)
72 def StorePredicateExpression(self, StartLine, StartOffset, EndLine, EndOffset, Text):
73 PredExp = CodeFragment.PredicateExpression(Text, (StartLine, StartOffset), (EndLine, EndOffset))
74 FileProfile.PredicateExpressionList.append(PredExp)
76 def StoreEnumerationDefinition(self, StartLine, StartOffset, EndLine, EndOffset, Text):
77 EnumDef = CodeFragment.EnumerationDefinition(Text, (StartLine, StartOffset), (EndLine, EndOffset))
78 FileProfile.EnumerationDefinitionList.append(EnumDef)
80 def StoreStructUnionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, Text):
81 SUDef = CodeFragment.StructUnionDefinition(Text, (StartLine, StartOffset), (EndLine, EndOffset))
82 FileProfile.StructUnionDefinitionList.append(SUDef)
84 def StoreTypedefDefinition(self, StartLine, StartOffset, EndLine, EndOffset, FromText, ToText):
85 Tdef = CodeFragment.TypedefDefinition(FromText, ToText, (StartLine, StartOffset), (EndLine, EndOffset))
86 FileProfile.TypedefDefinitionList.append(Tdef)
88 def StoreFunctionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText, LeftBraceLine, LeftBraceOffset, DeclLine, DeclOffset):
89 FuncDef = CodeFragment.FunctionDefinition(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset), (LeftBraceLine, LeftBraceOffset), (DeclLine, DeclOffset))
90 FileProfile.FunctionDefinitionList.append(FuncDef)
92 def StoreVariableDeclaration(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText):
93 VarDecl = CodeFragment.VariableDeclaration(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset))
94 FileProfile.VariableDeclarationList.append(VarDecl)
96 def StoreFunctionCalling(self, StartLine, StartOffset, EndLine, EndOffset, FuncName, ParamList):
97 FuncCall = CodeFragment.FunctionCalling(FuncName, ParamList, (StartLine, StartOffset), (EndLine, EndOffset))
98 FileProfile.FunctionCallingList.append(FuncCall)
103 : external_declaration*
107 /*function_declaration
109 print $function_declaration.text
111 : declaration_specifiers IDENTIFIER '(' parameter_list ')' ';'
117 print $external_declaration.text
119 : ( declaration_specifiers? declarator declaration* '{' )=> function_definition
121 | macro_statement (';')?
136 $function_definition::ModifierText = '';
137 $function_definition::DeclText = '';
138 $function_definition::LBLine = 0;
139 $function_definition::LBOffset = 0;
140 $function_definition::DeclLine = 0;
141 $function_definition::DeclOffset = 0;
144 self.StoreFunctionDefinition($function_definition.start.line, $function_definition.start.charPositionInLine, $function_definition.stop.line, $function_definition.stop.charPositionInLine, $function_definition::ModifierText, $function_definition::DeclText, $function_definition::LBLine, $function_definition::LBOffset, $function_definition::DeclLine, $function_definition::DeclOffset)
146 : d=declaration_specifiers? declarator
147 ( declaration+ a=compound_statement // K&R style
148 | b=compound_statement // ANSI style
151 $function_definition::ModifierText = $declaration_specifiers.text
153 $function_definition::ModifierText = ''
154 $function_definition::DeclText = $declarator.text
155 $function_definition::DeclLine = $declarator.start.line
156 $function_definition::DeclOffset = $declarator.start.charPositionInLine
158 $function_definition::LBLine = $a.start.line
159 $function_definition::LBOffset = $a.start.charPositionInLine
161 $function_definition::LBLine = $b.start.line
162 $function_definition::LBOffset = $b.start.charPositionInLine
167 : a='typedef' b=declaration_specifiers?
168 c=init_declarator_list d=';'
171 self.StoreTypedefDefinition($a.line, $a.charPositionInLine, $d.line, $d.charPositionInLine, $b.text, $c.text)
173 self.StoreTypedefDefinition($a.line, $a.charPositionInLine, $d.line, $d.charPositionInLine, '', $c.text)
175 | s=declaration_specifiers t=init_declarator_list? e=';'
178 self.StoreVariableDeclaration($s.start.line, $s.start.charPositionInLine, $t.start.line, $t.start.charPositionInLine, $s.text, $t.text)
182 declaration_specifiers
183 : ( storage_class_specifier
190 : init_declarator (',' init_declarator)*
194 : declarator ('=' initializer)?
197 storage_class_specifier
215 | s=struct_or_union_specifier
218 self.StoreStructUnionDefinition($s.start.line, $s.start.charPositionInLine, $s.stop.line, $s.stop.charPositionInLine, $s.text)
223 self.StoreEnumerationDefinition($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)
225 | (IDENTIFIER type_qualifier* declarator)=> type_id
230 //{self.printTokenInfo($a.line, $a.pos, $a.text)}
233 struct_or_union_specifier
235 : struct_or_union IDENTIFIER? '{' struct_declaration_list '}'
236 | struct_or_union IDENTIFIER
244 struct_declaration_list
245 : struct_declaration+
249 : specifier_qualifier_list struct_declarator_list ';'
252 specifier_qualifier_list
253 : ( type_qualifier | type_specifier )+
256 struct_declarator_list
257 : struct_declarator (',' struct_declarator)*
261 : declarator (':' constant_expression)?
262 | ':' constant_expression
267 : 'enum' '{' enumerator_list ','? '}'
268 | 'enum' IDENTIFIER '{' enumerator_list ','? '}'
273 : enumerator (',' enumerator)*
277 : IDENTIFIER ('=' constant_expression)?
289 | 'GLOBAL_REMOVE_IF_UNREFERENCED'
292 | 'EFI_RUNTIMESERVICE'
297 : pointer? ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? direct_declarator
298 // | ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? pointer? direct_declarator
303 : IDENTIFIER declarator_suffix*
304 | '(' ('EFIAPI')? declarator ')' declarator_suffix+
308 : '[' constant_expression ']'
310 | '(' parameter_type_list ')'
311 | '(' identifier_list ')'
316 : '*' type_qualifier+ pointer?
322 : parameter_list (',' ('OPTIONAL')? '...')?
326 : parameter_declaration (',' ('OPTIONAL')? parameter_declaration)*
329 parameter_declaration
330 : declaration_specifiers (declarator|abstract_declarator)* ('OPTIONAL')?
331 //accomerdate user-defined type only, no declarator follow.
332 | pointer* IDENTIFIER
341 : specifier_qualifier_list abstract_declarator?
346 : pointer direct_abstract_declarator?
347 | direct_abstract_declarator
350 direct_abstract_declarator
351 : ( '(' abstract_declarator ')' | abstract_declarator_suffix ) abstract_declarator_suffix*
354 abstract_declarator_suffix
356 | '[' constant_expression ']'
358 | '(' parameter_type_list ')'
363 : assignment_expression
364 | '{' initializer_list ','? '}'
368 : initializer (',' initializer )*
371 // E x p r e s s i o n s
373 argument_expression_list
374 : assignment_expression ('OPTIONAL')? (',' assignment_expression ('OPTIONAL')?)*
378 : (multiplicative_expression) ('+' multiplicative_expression | '-' multiplicative_expression)*
381 multiplicative_expression
382 : (cast_expression) ('*' cast_expression | '/' cast_expression | '%' cast_expression)*
386 : '(' type_name ')' cast_expression
392 | '++' unary_expression
393 | '--' unary_expression
394 | unary_operator cast_expression
395 | 'sizeof' unary_expression
396 | 'sizeof' '(' type_name ')'
404 $postfix_expression::FuncCallText = '';
406 : p=primary_expression {$postfix_expression::FuncCallText += $p.text}
408 | '(' a=')'{self.StoreFunctionCalling($p.start.line, $p.start.charPositionInLine, $a.line, $a.charPositionInLine, $postfix_expression::FuncCallText, '')}
409 | '(' c=argument_expression_list b=')' {self.StoreFunctionCalling($p.start.line, $p.start.charPositionInLine, $b.line, $b.charPositionInLine, $postfix_expression::FuncCallText, $c.text)}
410 | '(' macro_parameter_list ')'
411 | '.' x=IDENTIFIER {$postfix_expression::FuncCallText += '.' + $x.text}
412 | '*' y=IDENTIFIER {$postfix_expression::FuncCallText = $y.text}
413 | '->' z=IDENTIFIER {$postfix_expression::FuncCallText += '->' + $z.text}
420 : parameter_declaration (',' parameter_declaration)*
443 | (IDENTIFIER* STRING_LITERAL+)+ IDENTIFIER*
444 | FLOATING_POINT_LITERAL
450 : assignment_expression (',' assignment_expression)*
454 : conditional_expression
457 assignment_expression
458 : lvalue assignment_operator assignment_expression
459 | conditional_expression
480 conditional_expression
481 : e=logical_or_expression ('?' expression ':' conditional_expression {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)})?
484 logical_or_expression
485 : logical_and_expression ('||' logical_and_expression)*
488 logical_and_expression
489 : inclusive_or_expression ('&&' inclusive_or_expression)*
492 inclusive_or_expression
493 : exclusive_or_expression ('|' exclusive_or_expression)*
496 exclusive_or_expression
497 : and_expression ('^' and_expression)*
501 : equality_expression ('&' equality_expression)*
504 : relational_expression (('=='|'!=') relational_expression )*
507 relational_expression
508 : shift_expression (('<'|'>'|'<='|'>=') shift_expression)*
512 : additive_expression (('<<'|'>>') additive_expression)*
515 // S t a t e m e n t s
520 | expression_statement
521 | selection_statement
522 | iteration_statement
532 : '__asm__'? IDENTIFIER '(' (~(';'))* ')' ';'
536 : '_asm' '{' (~('}'))* '}'
540 : '__asm' '{' (~('}'))* '}'
544 : IDENTIFIER '(' declaration* statement_list? expression? ')'
548 : IDENTIFIER ':' statement
549 | 'case' constant_expression ':' statement
550 | 'default' ':' statement
554 : '{' declaration* statement_list? '}'
567 : 'if' '(' e=expression ')' {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)} statement (options {k=1; backtrack=false;}:'else' statement)?
568 | 'switch' '(' expression ')' statement
572 : 'while' '(' e=expression ')' statement {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
573 | 'do' statement 'while' '(' e=expression ')' ';' {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
574 | 'for' '(' expression_statement e=expression_statement expression? ')' statement {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
578 : 'goto' IDENTIFIER ';'
582 | 'return' expression ';'
586 : LETTER (LETTER|'0'..'9')*
598 : ('L')? '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
602 : ('L')? '"' ( EscapeSequence | ~('\\'|'"') )* '"'
605 HEX_LITERAL : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
607 DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
609 OCTAL_LITERAL : '0' ('0'..'7')+ IntegerTypeSuffix? ;
612 HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
618 | ('u'|'U') ('l'|'L')
619 | ('u'|'U') ('l'|'L') ('l'|'L')
622 FLOATING_POINT_LITERAL
623 : ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
624 | '.' ('0'..'9')+ Exponent? FloatTypeSuffix?
625 | ('0'..'9')+ Exponent FloatTypeSuffix?
626 | ('0'..'9')+ Exponent? FloatTypeSuffix
630 Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
633 FloatTypeSuffix : ('f'|'F'|'d'|'D') ;
637 : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
643 : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
644 | '\\' ('0'..'7') ('0'..'7')
650 : '\\' 'u' HexDigit HexDigit HexDigit HexDigit
653 WS : (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
656 // ingore '\' of line concatenation
657 BS : ('\\') {$channel=HIDDEN;}
660 // ingore function modifiers
661 //FUNC_MODIFIERS : 'EFIAPI' {$channel=HIDDEN;}
668 : '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
673 : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
676 // ignore #line info for now
678 : '#' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}