📄 cp_declaration.c
字号:
/*Copyright (c) 2000, 2001, Red Hat, Inc.This file is part of Source-Navigator.Source-Navigator is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public License as publishedby the Free Software Foundation; either version 2, or (at your option)any later version.Source-Navigator is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith Source-Navigator; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <tcl.h>#include "crossrefP.h"/* Valid debugging macros for this file: #define PRINT #define SYMTAB_TRACE*/extern Declaration_t f_Declaration( int iLevel );extern Declaration_t f_DeclarationCreate( int iType );extern DeclarationSpecial_t f_DeclarationSpecialCreate( int iType );extern void f_DeclarationDestroy( Declaration_t Declaration );extern void f_DeclarationSpecialDestroy( DeclarationSpecial_t DeclarationSpecial );static Declaration_t f_DeclarationAsm( void );static Declaration_t f_DeclarationTemplate( void );static Declaration_t f_DeclarationLinkageSpecification( void );static Declaration_t f_DeclarationUsing( void );static Declaration_t f_DeclarationNamespace( void );static Declaration_t f_DeclarationObject( int iLevel );static List_t __InitDeclaratorList( Boolean_t may_function );static List_t __MemberDeclaratorList( void );static void ctor_initializer( void );static Boolean_t f_IsDeclarationStrange( Declaration_t Declaration );static Boolean_t f_DeclaratorOldStyleFunctionDefinition( Declarator_t Declarator );static void f_DeclaratorOldStyleFunctionDefinitionProcess( Declarator_t Declarator_a );static Boolean_t f_DeclaratorHasParameterList( Declarator_t Declarator );static Declaration_t f_DeclaratorFindParameter( Declarator_t Declarator, char *pcName );static void f_DeclarationCopy( Declaration_t DeclarationDest, Declaration_t DeclarationSrc, Declarator_t DeclaratorSrc );static Boolean_t f_DeclarationIsParameter( Declaration_t Declaration );static void _DeclarationProcess( Declaration_t Declaration, int record );static void _DeclarationSpecialProcess( DeclarationSpecial_t DeclarationSpecial, int record );static Type_t f_TypeDeclaratorConcat( Type_t Type, Declarator_t Declarator );extern Declaration_t f_Declaration( int iLevel ){ Declaration_t Declaration; char ac[20000]; /* old: 10000 */ ac[0] = 0; switch( token( 0 )) { case SN_ASM : return f_DeclarationAsm(); case SN_TEMPLATE : return f_DeclarationTemplate(); case SN_NAMESPACE: return f_DeclarationNamespace(); case SN_USING : return f_DeclarationUsing(); case SN_EXTERN : if( token( 1 ) == SN_STRINGliteral ) { return f_DeclarationLinkageSpecification(); } else { if(( Declaration = f_DeclarationObject( iLevel ))) {#ifdef PRINT f_DeclarationStrcat( ac, Declaration ); printf( "declaration: %s\n", ac );#endif } return Declaration; } default : if(( Declaration = f_DeclarationObject( iLevel ))) {#ifdef PRINT f_DeclarationStrcat( ac, Declaration ); printf( "declaration: %s\n", ac );#endif } return Declaration; }}static Declaration_t f_DeclarationAsm( void ){ DeclarationSpecial_t DeclarationSpecial; niveau++; step( 1 ); DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_ASM ); if( token( 0 ) == LBRACE ) { step( 1 ); f_StepTo( RBRACE, 0 ); step( 1 ); } else if( token( 0 ) == '(' ) { step( 1 ); f_StepTo( ')', 0 ); step( 1 ); } if( token( 0 ) == ';' ) { step( 1 ); } niveau--; return (Declaration_t) DeclarationSpecial;}static Declaration_t f_DeclarationTemplate( void ){ DeclarationSpecial_t DeclarationSpecial; Declaration_t Declaration2;/* Save(); */ niveau++; DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_TEMPLATE ); step( 1 ); if( token( 0 ) == '<' ) { DeclarationSpecial->Name1 = f_TemplateArgumentList(); } if(( Declaration2 = f_Declaration( LEVEL_2 ))) { f_ListAddLast( &DeclarationSpecial->ListDeclaration, (Elem_t) Declaration2 ); niveau--; return (Declaration_t) DeclarationSpecial; } else { f_DeclarationSpecialDestroy( DeclarationSpecial ); f_StepTo( ';', 0 ); step( 1 ); niveau--; return 0; }}static Declaration_t f_DeclarationLinkageSpecification( void ){ DeclarationSpecial_t DeclarationSpecial; Declaration_t Declaration2; niveau++; DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_LINKAGE_SPECIFICATION ); step( 1 ); do { step( 1 ); } while( token( 0 ) == SN_STRINGliteral ); if( token( 0 ) == LBRACE ) { step( 1 ); while( token( 0 ) != RBRACE && token( 0 ) != 0 ) { if(( Declaration2 = f_Declaration( LEVEL_2 ))) { f_ListAddLast( &DeclarationSpecial->ListDeclaration , (Elem_t) Declaration2 ); } else { f_DeclarationSkip(); } } step( 1 ); } else { if(( Declaration2 = f_Declaration( LEVEL_2 ))) { f_ListAddLast( &DeclarationSpecial->ListDeclaration , (Elem_t) Declaration2 ); } else { f_DeclarationSkip(); } } niveau--; return (Declaration_t) DeclarationSpecial;}static Declaration_t f_DeclarationUsing( void ){ DeclarationSpecial_t DeclarationSpecial; Name_t Name;/* Save(); */ niveau++; if( token( 1 ) == SN_NAMESPACE ) { step( 2 ); if(( Name = f_NamespaceName())) { DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_USING_DIRECTIVE ); DeclarationSpecial->Name1 = Name; f_StepTo( ';', 0 ); step( 1 ); niveau--; return (Declaration_t) DeclarationSpecial; } else { f_StepTo( ';', 0 ); step( 1 ); niveau--; return 0; } } else { step( 1 ); if(( Name = f_NamespaceName())) { DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_USING ); DeclarationSpecial->Name1 = Name; f_StepTo( ';', 0 ); step( 1 ); niveau--; return (Declaration_t) DeclarationSpecial; } else { f_StepTo( ';', 0 ); step( 1 ); niveau--; return 0; } }}static Declaration_t f_DeclarationNamespace( void ){ DeclarationSpecial_t DeclarationSpecial; Declaration_t Declaration2; Name_t Name1 = 0; Name_t Name2 = 0;/* Save(); */ niveau++; step( 1 ); if( token( 0 ) == SN_IDENTIFIER ) { Name1 = f_NameCreate( ident( 0 )); step( 1 ); if( token( 0 ) == '=' ) { step( 1 ); if(( Name2 = f_NamespaceName())) { DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_NAMESPACE_ALIAS_DEFINITION ); DeclarationSpecial->Name1 = Name1; DeclarationSpecial->Name2 = Name2; f_StepTo( ';', 0 ); step( 1 ); niveau--; return (Declaration_t) DeclarationSpecial; } else { f_NameDestroy( Name1 ); f_StepTo( ';', 0 ); step( 1 ); niveau--; return 0; } } } if( token( 0 ) == LBRACE ) { DeclarationSpecial = f_DeclarationSpecialCreate( DECLARATION_NAMESPACE_DEFINITION ); DeclarationSpecial->Name1 = Name1; step( 1 ); while( token( 0 ) != RBRACE && token( 0 ) != 0 ) { if(( Declaration2 = f_Declaration( LEVEL_2 ))) { f_ListAddLast( &DeclarationSpecial->ListDeclaration , (Elem_t) Declaration2 ); } else { f_DeclarationSkip(); } } step( 1 ); niveau--; return (Declaration_t) DeclarationSpecial; } else { f_NameDestroy( Name1 ); f_StepTo( ';', 0 ); step( 1 ); niveau--; return 0; }}static Declaration_t f_DeclarationObject( int iLevel ){ Declaration_t Declaration; Class_t Class; Enum_t Enum; Name_t Name; List_t List; int iTypeSpec = 0; int iCvSpec = 0; int iStorage = 0; int iFctSpec = 0; int storage_class; Boolean_t may_function; /* 12.03.97 rigo */ Save(); niveau++; if( CompAct && token( 0 ) == SN_IDENTIFIER && token( 1 ) == ';' ) { Restore(); niveau--; return 0; } Declaration = f_DeclarationCreate( DECLARATION_OBJECT ); while( True ) { switch( token( 0 )) { case SN_PUBLIC : storage_class = 0 ; goto spec_storage; case SN_PRIVATE : storage_class = SN_STATIC; goto spec_storage; case SN_PROTECTED : storage_class = SN_STATIC; goto spec_storage;spec_storage: step( 1 ); if( iStorage + iTypeSpec + iFctSpec == 0 ) { iStorage++; iLevel = LEVEL_2; Declaration->storage_class = storage_class; } else { goto identifier; } break; case SN_AUTO : Declaration->storage_class = SN_AUTO ; goto label; case SN_REGISTER : Declaration->storage_class = SN_REGISTER; goto label; case SN_STATIC : Declaration->storage_class = SN_STATIC ; goto label; case SN_EXTERN : Declaration->storage_class = SN_EXTERN ; goto label; case SN_FRIEND : Declaration->storage_class = SN_FRIEND ; goto label; case SN_TYPEDEF : Declaration->storage_class = SN_TYPEDEF ; goto label;label: step( 1 ); iStorage++; iLevel = LEVEL_2; break; case SN_INLINE : Declaration->fct_specifier = SN_INLINE ; goto fct_spec; case SN_VIRTUAL : Declaration->fct_specifier = SN_VIRTUAL ; goto fct_spec;fct_spec: step( 1 ); iFctSpec++; iLevel = LEVEL_2; break; case SN_CLASS : if(( Class = f_Class()) == 0 ) { goto identifier; } else { Declaration->Class = Class; iTypeSpec++; iLevel = LEVEL_2; } break; case SN_STRUCT : case SN_UNION : if(( Class = f_Class()) == 0 ) { f_InternalError( 33 ); f_DeclarationDestroy( Declaration ); Restore(); niveau--; return 0; } else { Declaration->Class = Class; iTypeSpec++; iLevel = LEVEL_2; } break; case SN_ENUM : if(( Enum = f_Enum()) == 0 ) { f_InternalError( 34 ); f_DeclarationDestroy( Declaration ); Restore(); niveau--; return 0; } else { Declaration->Enum = Enum; iTypeSpec++; iLevel = LEVEL_2; } break; case SN_CONST : Declaration->s_const = True; goto cv; case SN_VOLATILE : Declaration->s_volatile = True; goto cv;cv: step( 1 ); iCvSpec++; iLevel = LEVEL_2; break; case SN_CHAR : Declaration->s_char = True; goto type; case SN_SHORT : Declaration->s_short = True; goto type; case SN_INT : Declaration->s_int = True; goto type; case SN_LONG : Declaration->s_long = True; goto type; case SN_SIGNED : Declaration->s_signed = True; goto type; case SN_UNSIGNED : Declaration->s_unsigned = True; goto type; case SN_FLOAT : Declaration->s_float = True; goto type; case SN_DOUBLE : Declaration->s_double = True; goto type; case SN_BOOL : Declaration->s_bool = True; goto type; case SN_VOID : Declaration->s_void = True; goto type;type: step( 1 ); /* We could have a global variable or a function declaration. */ iTypeSpec++; iLevel = LEVEL_2; break; case ';' : /* empty declarator_list */ step( 1 ); niveau--; return Declaration; case SN_ASM : /* 13.09.96 rigo */ case SN_CATCH : /* 13.09.96 rigo */ case SN_DELETE : /* 13.09.96 rigo */ case SN_NAMESPACE : /* 13.09.96 rigo */ case SN_NEW : /* 13.09.96 rigo */ case SN_OVERLOAD : /* 13.09.96 rigo */ case SN_TEMPLATE : /* 13.09.96 rigo */ case SN_THIS : /* 13.09.96 rigo */ case SN_THROW : /* 13.09.96 rigo */ case SN_TRY : /* 13.09.96 rigo */ case SN_USING : /* 13.09.96 rigo */ case SN_IDENTIFIER : case SN_CLCL :identifier:/* if( CompAct && iTypeSpec + iStorage + iFctSpec == 0 ) 24.02.97 rigo *//* register hdr *ptr; -t nem tudta megerteni */ if( CompAct && iTypeSpec + iFctSpec == 0 ) {complete_class_name: if(( Name = f_CompleteClassName())) { if( Declaration->Name == 0 ) { iTypeSpec++; Declaration->Name = Name; } else { f_NameDestroy( Name ); } break; } else { f_DeclarationDestroy( Declaration ); Restore(); niveau--; return 0; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -