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 SPDX-License-Identifier: BSD-2-Clause-Patent
18 # The file defines the Lexer for C source files.
20 # THIS FILE IS AUTO-GENERATED. PLEASE DO NOT MODIFY THIS FILE.
21 # This file is generated by running:
22 # java org.antlr.Tool C.g
24 # Copyright (c) 2009 - 2010, Intel Corporation All rights reserved.
26 # This program and the accompanying materials are licensed and made available
27 # under the terms and conditions of the BSD License which accompanies this
28 # distribution. The full text of the license may be found at:
29 # http://opensource.org/licenses/bsd-license.php
31 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
39 # The file defines the parser for C source files.
41 # THIS FILE IS AUTO-GENERATED. PLEASE DO NOT MODIFY THIS FILE.
42 # This file is generated by running:
43 # java org.antlr.Tool C.g
45 # Copyright (c) 2009 - 2010, Intel Corporation All rights reserved.
47 # This program and the accompanying materials are licensed and made available
48 # under the terms and conditions of the BSD License which accompanies this
49 # distribution. The full text of the license may be found at:
50 # http://opensource.org/licenses/bsd-license.php
52 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
53 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
63 def printTokenInfo(self, line, offset, tokenText):
64 print str(line)+ ',' + str(offset) + ':' + str(tokenText)
66 def StorePredicateExpression(self, StartLine, StartOffset, EndLine, EndOffset, Text):
67 PredExp = CodeFragment.PredicateExpression(Text, (StartLine, StartOffset), (EndLine, EndOffset))
68 FileProfile.PredicateExpressionList.append(PredExp)
70 def StoreEnumerationDefinition(self, StartLine, StartOffset, EndLine, EndOffset, Text):
71 EnumDef = CodeFragment.EnumerationDefinition(Text, (StartLine, StartOffset), (EndLine, EndOffset))
72 FileProfile.EnumerationDefinitionList.append(EnumDef)
74 def StoreStructUnionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, Text):
75 SUDef = CodeFragment.StructUnionDefinition(Text, (StartLine, StartOffset), (EndLine, EndOffset))
76 FileProfile.StructUnionDefinitionList.append(SUDef)
78 def StoreTypedefDefinition(self, StartLine, StartOffset, EndLine, EndOffset, FromText, ToText):
79 Tdef = CodeFragment.TypedefDefinition(FromText, ToText, (StartLine, StartOffset), (EndLine, EndOffset))
80 FileProfile.TypedefDefinitionList.append(Tdef)
82 def StoreFunctionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText, LeftBraceLine, LeftBraceOffset, DeclLine, DeclOffset):
83 FuncDef = CodeFragment.FunctionDefinition(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset), (LeftBraceLine, LeftBraceOffset), (DeclLine, DeclOffset))
84 FileProfile.FunctionDefinitionList.append(FuncDef)
86 def StoreVariableDeclaration(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText):
87 VarDecl = CodeFragment.VariableDeclaration(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset))
88 FileProfile.VariableDeclarationList.append(VarDecl)
90 def StoreFunctionCalling(self, StartLine, StartOffset, EndLine, EndOffset, FuncName, ParamList):
91 FuncCall = CodeFragment.FunctionCalling(FuncName, ParamList, (StartLine, StartOffset), (EndLine, EndOffset))
92 FileProfile.FunctionCallingList.append(FuncCall)
97 : external_declaration*
101 /*function_declaration
103 print $function_declaration.text
105 : declaration_specifiers IDENTIFIER '(' parameter_list ')' ';'
111 print $external_declaration.text
113 : ( declaration_specifiers? declarator declaration* '{' )=> function_definition
115 | macro_statement (';')?
130 $function_definition::ModifierText = '';
131 $function_definition::DeclText = '';
132 $function_definition::LBLine = 0;
133 $function_definition::LBOffset = 0;
134 $function_definition::DeclLine = 0;
135 $function_definition::DeclOffset = 0;
138 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)
140 : d=declaration_specifiers? declarator
141 ( declaration+ a=compound_statement // K&R style
142 | b=compound_statement // ANSI style
145 $function_definition::ModifierText = $declaration_specifiers.text
147 $function_definition::ModifierText = ''
148 $function_definition::DeclText = $declarator.text
149 $function_definition::DeclLine = $declarator.start.line
150 $function_definition::DeclOffset = $declarator.start.charPositionInLine
152 $function_definition::LBLine = $a.start.line
153 $function_definition::LBOffset = $a.start.charPositionInLine
155 $function_definition::LBLine = $b.start.line
156 $function_definition::LBOffset = $b.start.charPositionInLine
161 : a='typedef' b=declaration_specifiers?
162 c=init_declarator_list d=';'
165 self.StoreTypedefDefinition($a.line, $a.charPositionInLine, $d.line, $d.charPositionInLine, $b.text, $c.text)
167 self.StoreTypedefDefinition($a.line, $a.charPositionInLine, $d.line, $d.charPositionInLine, '', $c.text)
169 | s=declaration_specifiers t=init_declarator_list? e=';'
172 self.StoreVariableDeclaration($s.start.line, $s.start.charPositionInLine, $t.start.line, $t.start.charPositionInLine, $s.text, $t.text)
176 declaration_specifiers
177 : ( storage_class_specifier
184 : init_declarator (',' init_declarator)*
188 : declarator ('=' initializer)?
191 storage_class_specifier
209 | s=struct_or_union_specifier
212 self.StoreStructUnionDefinition($s.start.line, $s.start.charPositionInLine, $s.stop.line, $s.stop.charPositionInLine, $s.text)
217 self.StoreEnumerationDefinition($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)
219 | (IDENTIFIER type_qualifier* declarator)=> type_id
224 //{self.printTokenInfo($a.line, $a.pos, $a.text)}
227 struct_or_union_specifier
229 : struct_or_union IDENTIFIER? '{' struct_declaration_list '}'
230 | struct_or_union IDENTIFIER
238 struct_declaration_list
239 : struct_declaration+
243 : specifier_qualifier_list struct_declarator_list ';'
246 specifier_qualifier_list
247 : ( type_qualifier | type_specifier )+
250 struct_declarator_list
251 : struct_declarator (',' struct_declarator)*
255 : declarator (':' constant_expression)?
256 | ':' constant_expression
261 : 'enum' '{' enumerator_list ','? '}'
262 | 'enum' IDENTIFIER '{' enumerator_list ','? '}'
267 : enumerator (',' enumerator)*
271 : IDENTIFIER ('=' constant_expression)?
283 | 'GLOBAL_REMOVE_IF_UNREFERENCED'
286 | 'EFI_RUNTIMESERVICE'
291 : pointer? ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? direct_declarator
292 // | ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? pointer? direct_declarator
297 : IDENTIFIER declarator_suffix*
298 | '(' ('EFIAPI')? declarator ')' declarator_suffix+
302 : '[' constant_expression ']'
304 | '(' parameter_type_list ')'
305 | '(' identifier_list ')'
310 : '*' type_qualifier+ pointer?
316 : parameter_list (',' ('OPTIONAL')? '...')?
320 : parameter_declaration (',' ('OPTIONAL')? parameter_declaration)*
323 parameter_declaration
324 : declaration_specifiers (declarator|abstract_declarator)* ('OPTIONAL')?
325 //accomerdate user-defined type only, no declarator follow.
326 | pointer* IDENTIFIER
335 : specifier_qualifier_list abstract_declarator?
340 : pointer direct_abstract_declarator?
341 | direct_abstract_declarator
344 direct_abstract_declarator
345 : ( '(' abstract_declarator ')' | abstract_declarator_suffix ) abstract_declarator_suffix*
348 abstract_declarator_suffix
350 | '[' constant_expression ']'
352 | '(' parameter_type_list ')'
357 : assignment_expression
358 | '{' initializer_list ','? '}'
362 : initializer (',' initializer )*
365 // E x p r e s s i o n s
367 argument_expression_list
368 : assignment_expression ('OPTIONAL')? (',' assignment_expression ('OPTIONAL')?)*
372 : (multiplicative_expression) ('+' multiplicative_expression | '-' multiplicative_expression)*
375 multiplicative_expression
376 : (cast_expression) ('*' cast_expression | '/' cast_expression | '%' cast_expression)*
380 : '(' type_name ')' cast_expression
386 | '++' unary_expression
387 | '--' unary_expression
388 | unary_operator cast_expression
389 | 'sizeof' unary_expression
390 | 'sizeof' '(' type_name ')'
398 $postfix_expression::FuncCallText = '';
400 : p=primary_expression {$postfix_expression::FuncCallText += $p.text}
402 | '(' a=')'{self.StoreFunctionCalling($p.start.line, $p.start.charPositionInLine, $a.line, $a.charPositionInLine, $postfix_expression::FuncCallText, '')}
403 | '(' c=argument_expression_list b=')' {self.StoreFunctionCalling($p.start.line, $p.start.charPositionInLine, $b.line, $b.charPositionInLine, $postfix_expression::FuncCallText, $c.text)}
404 | '(' macro_parameter_list ')'
405 | '.' x=IDENTIFIER {$postfix_expression::FuncCallText += '.' + $x.text}
406 | '*' y=IDENTIFIER {$postfix_expression::FuncCallText = $y.text}
407 | '->' z=IDENTIFIER {$postfix_expression::FuncCallText += '->' + $z.text}
414 : parameter_declaration (',' parameter_declaration)*
437 | (IDENTIFIER* STRING_LITERAL+)+ IDENTIFIER*
438 | FLOATING_POINT_LITERAL
444 : assignment_expression (',' assignment_expression)*
448 : conditional_expression
451 assignment_expression
452 : lvalue assignment_operator assignment_expression
453 | conditional_expression
474 conditional_expression
475 : e=logical_or_expression ('?' expression ':' conditional_expression {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)})?
478 logical_or_expression
479 : logical_and_expression ('||' logical_and_expression)*
482 logical_and_expression
483 : inclusive_or_expression ('&&' inclusive_or_expression)*
486 inclusive_or_expression
487 : exclusive_or_expression ('|' exclusive_or_expression)*
490 exclusive_or_expression
491 : and_expression ('^' and_expression)*
495 : equality_expression ('&' equality_expression)*
498 : relational_expression (('=='|'!=') relational_expression )*
501 relational_expression
502 : shift_expression (('<'|'>'|'<='|'>=') shift_expression)*
506 : additive_expression (('<<'|'>>') additive_expression)*
509 // S t a t e m e n t s
514 | expression_statement
515 | selection_statement
516 | iteration_statement
526 : '__asm__'? IDENTIFIER '(' (~(';'))* ')' ';'
530 : '_asm' '{' (~('}'))* '}'
534 : '__asm' '{' (~('}'))* '}'
538 : IDENTIFIER '(' declaration* statement_list? expression? ')'
542 : IDENTIFIER ':' statement
543 | 'case' constant_expression ':' statement
544 | 'default' ':' statement
548 : '{' declaration* statement_list? '}'
561 : '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)?
562 | 'switch' '(' expression ')' statement
566 : 'while' '(' e=expression ')' statement {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
567 | 'do' statement 'while' '(' e=expression ')' ';' {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
568 | 'for' '(' expression_statement e=expression_statement expression? ')' statement {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
572 : 'goto' IDENTIFIER ';'
576 | 'return' expression ';'
580 : LETTER (LETTER|'0'..'9')*
592 : ('L')? '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
596 : ('L')? '"' ( EscapeSequence | ~('\\'|'"') )* '"'
599 HEX_LITERAL : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
601 DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
603 OCTAL_LITERAL : '0' ('0'..'7')+ IntegerTypeSuffix? ;
606 HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
612 | ('u'|'U') ('l'|'L')
613 | ('u'|'U') ('l'|'L') ('l'|'L')
616 FLOATING_POINT_LITERAL
617 : ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
618 | '.' ('0'..'9')+ Exponent? FloatTypeSuffix?
619 | ('0'..'9')+ Exponent FloatTypeSuffix?
620 | ('0'..'9')+ Exponent? FloatTypeSuffix
624 Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
627 FloatTypeSuffix : ('f'|'F'|'d'|'D') ;
631 : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
637 : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
638 | '\\' ('0'..'7') ('0'..'7')
644 : '\\' 'u' HexDigit HexDigit HexDigit HexDigit
647 WS : (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
650 // ignore '\' of line concatenation
651 BS : ('\\') {$channel=HIDDEN;}
654 // ignore function modifiers
655 //FUNC_MODIFIERS : 'EFIAPI' {$channel=HIDDEN;}
662 : '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
667 : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
670 // ignore #line info for now
672 : '#' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}