/* @file
This file is used to be the grammar file of ECC tool
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
grammar C;
options {
backtrack=true;
memoize=true;
k=2;
}
## @file
#
#
#
#
#
##
}
@header {
## @file
#
#
#
#
#
##
import CodeFragment
import FileProfile
}
@members {
Tdef = CodeFragment.TypedefDefinition(FromText, ToText, (StartLine, StartOffset), (EndLine, EndOffset))
def StoreFunctionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText, LeftBraceLine, LeftBraceOffset, DeclLine, DeclOffset):
FuncDef = CodeFragment.FunctionDefinition(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset), (LeftBraceLine, LeftBraceOffset), (DeclLine, DeclOffset))
def StoreVariableDeclaration(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText):
VarDecl = CodeFragment.VariableDeclaration(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset))
FuncCall = CodeFragment.FunctionCalling(FuncName, ParamList, (StartLine, StartOffset), (EndLine, EndOffset))
}
;
/*function_declaration
@after{
print $function_declaration.text
}
: declaration_specifiers IDENTIFIER '(' parameter_list ')' ';'
;
*/
options {k=1;}
/*@after{
print $external_declaration.text
}*/
| macro_statement (';')?
;
scope {
}
@init {
}
@after{
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)
}
| b=compound_statement // ANSI style
) {
if d != None:
else:
if a != None:
else:
}
;
: a='typedef' b=declaration_specifiers?
c=init_declarator_list d=';'
{
if b != None:
self.StoreTypedefDefinition($a.line, $a.charPositionInLine, $d.line, $d.charPositionInLine, $b.text, $c.text)
else:
self.StoreTypedefDefinition($a.line, $a.charPositionInLine, $d.line, $d.charPositionInLine, '', $c.text)
}
{
if t != None:
self.StoreVariableDeclaration($s.start.line, $s.start.charPositionInLine, $t.start.line, $t.start.charPositionInLine, $s.text, $t.text)
}
;
)+
;
;
;
: 'extern'
| 'static'
| 'auto'
| 'register'
| 'STATIC'
;
: 'void'
| 'char'
| 'short'
| 'int'
| 'long'
| 'float'
| 'double'
| 'signed'
| 'unsigned'
{
self.StoreStructUnionDefinition($s.start.line, $s.start.charPositionInLine, $s.stop.line, $s.stop.charPositionInLine, $s.text)
}
| e=enum_specifier
{
self.StoreEnumerationDefinition($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)
}
;
//{self.printTokenInfo($a.line, $a.pos, $a.text)}
;
options {k=3;}
;
: 'struct'
| 'union'
;
;
;
: ( type_qualifier | type_specifier )+
;
;
| ':' constant_expression
;
options {k=3;}
| 'enum' IDENTIFIER
;
;
;
: 'const'
| 'volatile'
| 'IN'
| 'OUT'
| 'OPTIONAL'
| 'CONST'
| 'UNALIGNED'
| 'VOLATILE'
| 'GLOBAL_REMOVE_IF_UNREFERENCED'
| 'EFIAPI'
| 'EFI_BOOTSERVICE'
| 'EFI_RUNTIMESERVICE'
| 'PACKED'
;
// | ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? pointer? direct_declarator
| pointer
;
;
| '[' ']'
| '(' ')'
;
| '*' pointer
| '*'
;
;
;
//accomerdate user-defined type only, no declarator follow.
;
(',' IDENTIFIER)*
;
| type_id
;
;
;
: '[' ']'
| '(' ')'
;
;
;
// E x p r e s s i o n s
;
;
;
;
| '++' unary_expression
| '--' unary_expression
| 'sizeof' unary_expression
;
scope {
}
@init {
}
| '(' a=')'{self.StoreFunctionCalling($p.start.line, $p.start.charPositionInLine, $a.line, $a.charPositionInLine, $postfix_expression::FuncCallText, '')}
| '(' c=argument_expression_list b=')' {self.StoreFunctionCalling($p.start.line, $p.start.charPositionInLine, $b.line, $b.charPositionInLine, $postfix_expression::FuncCallText, $c.text)}
| '++'
| '--'
)*
;
;
: '&'
| '*'
| '+'
| '-'
| '~'
| '!'
;
| constant
;
;
/////
;
;
;
;
: '='
| '*='
| '/='
| '%='
| '+='
| '-='
| '<<='
| '>>='
| '&='
| '^='
| '|='
;
: e=logical_or_expression ('?' expression ':' conditional_expression {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)})?
;
;
;
;
;
;
;
;
;
// S t a t e m e n t s
;
;
: '_asm' '{' (~('}'))* '}'
;
: '__asm' '{' (~('}'))* '}'
;
;
| 'default' ':' statement
;
;
: statement+
;
: ';'
| expression ';'
;
: '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)?
;
: 'while' '(' e=expression ')' statement {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
| 'do' statement 'while' '(' e=expression ')' ';' {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
| 'for' '(' expression_statement e=expression_statement expression? ')' statement {self.StorePredicateExpression($e.start.line, $e.start.charPositionInLine, $e.stop.line, $e.stop.charPositionInLine, $e.text)}
;
| 'continue' ';'
| 'break' ';'
| 'return' ';'
;
;
: '$'
| 'A'..'Z'
| 'a'..'z'
| '_'
;
;
;
: ('u'|'U')
| ('l'|'L')
| ('u'|'U') ('l'|'L')
| ('u'|'U') ('l'|'L') ('l'|'L')
;
;
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
;
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
;
;
// ingore '\' of line concatenation
;
// ingore function modifiers
//FUNC_MODIFIERS : 'EFIAPI' {$channel=HIDDEN;}
// ;
: '\u0003'..'\uFFFE'
;
;
;
// ignore #line info for now
;