void CgFrontScopeCall( // GENERATE IC_SCOPE_CALL, IF REQ'D SYMBOL fun, // - function called SYMBOL dtor, // - dtor, when function is ctor DTOR_KIND kind ) // - kind of dtoring { boolean keep_scope; // - TRUE ==> keep the current scope keep_scope = FALSE; if( dtor != NULL ) { switch( kind ) { case DTORING_SCOPE : CgFrontCodePtr( IC_SCOPE_CALL_BDTOR, dtor ); keep_scope = TRUE; break; case DTORING_TEMP : CgFrontCodePtr( IC_SCOPE_CALL_TDTOR, dtor ); break; case DTORING_COMPONENT : CgFrontCodePtr( IC_SCOPE_CALL_CDTOR, dtor ); keep_scope = TRUE; break; DbgDefault( "CgFrontScopeCall -- bad DTOR_KIND" ); } } if( fun != NULL && ( fun->flag & SF_NO_LONGJUMP ) ) { fun = NULL; } if( fun != NULL || dtor != NULL ) { CgFrontCodePtr( IC_SCOPE_CALL_FUN, fun ); } if( keep_scope ) { ScopeKeep( GetCurrScope() ); } }
void ScopeGenAccessSet( // SET ACCESS SCOPE FOR GENERATION TYPE cltype ) // - type for inlining { DbgVerify( tempScope == NULL, "ScopeAccessSet -- tempScope != NULL" ); tempScope = GetCurrScope(); SetCurrScope (TypeScope( cltype )); }
static void typeSigAccessVar( // ACCESS A DTOR, DEFAULT-CTOR, COPY-CTOR TYPE_SIG_ACCESS acc_var, // - access type (variable) SYMBOL *a_sym, // - addr[ symbol for item accessed ] ACCINFO *info ) // - access information { SYMBOL sym; // - symbol for routine TYPE type; // - class type TOKEN_LOCN *err_locn; // - error location boolean fill_out; // - TRUE ==> fill out the entry sym = *a_sym; if( acc_var & info->acc ) { fill_out = info->acc & TSA_FILL_OUT; if( fill_out ) { SetCurrScope(info->class_scope); } else { SetCurrScope (info->access_scope); } } else { fill_out = TRUE; SetCurrScope(info->class_scope); } if( ( GetCurrScope() != info->class_scope ) || ( sym == NULL ) ) { type = info->type; err_locn = info->err_locn; switch( acc_var ) { case TSA_DTOR : sym = DtorFindLocn( type, err_locn ); break; case TSA_DEFAULT_CTOR : sym = DefaultCtorFind( type, err_locn, fill_out ); break; case TSA_COPY_CTOR : sym = CopyCtorFind( type, err_locn ); break; default : #ifndef NDEBUG CFatal( "typeSigAccessVar -- impossible type" ); #endif sym = NULL; } if( sym == NULL ) { if( ! fill_out ) { *info->err_occurred = TRUE; } } else { sym = ClassFunMakeAddressable( sym ); sym->flag |= SF_ADDR_TAKEN; if( ! ( info->acc & TSA_NO_REF ) ) { if( acc_var & info->acc ) { sym = SymMarkRefed( sym ); } } *a_sym = sym; CDtorScheduleArgRemap( sym ); } } }
static SCOPE moduleInitSave( // SAVE ENVIRONMENT BEFORE MOD-INIT. void ) { SCOPE save_scope; save_scope = GetCurrScope(); LabelSwitchFunc( &module_fd.label_mem ); return( save_scope ); }
static void insertOperand // INSERT FOR OPERAND, IF POSSIBLE ( PTREE* a_node ) // - addr[ operand ] { PTREE node = *a_node; // - operand SEARCH_RESULT *result; // - result of lookup SYMBOL sym; // - a symbol looked up if( NULL != node ) { switch( node->op ) { case PT_ID : if( NULL != sym_at ) { if( node->op == PT_ID ) { switch( node->cgop ) { case CO_NAME_CDTOR_EXTRA : case CO_NAME_DTOR : break; default : result = ScopeFindNaked( GetCurrScope(), node->u.id.name ); if( NULL == result ) break; sym = result->sym_name->name_syms; if( NULL == sym ) break; if( SymIsAnError( sym ) ) break; if( SymIsConstantInt( sym ) ) break; // drops thru case CO_NAME_THIS : case CO_NAME_CONVERT : node = insert( node, name_at ); break; } } } break; case PT_BINARY : switch( node->cgop ) { case CO_ARROW : case CO_DOT : node = insert( node, name_op ); break; default : break; } break; default : break; } *a_node = node; } }
static void throwBaseCnv( // CONVERSION TO A BASE CLASS SCOPE base, // - scope for base class void* dat ) // - control area { THROW_CNV_CTL *ctl; // - control area ctl = dat; if( validateBase( base, ctl ) ) { SCOPE curr_scope = GetCurrScope(); if( base->owner.type != ctl->src_type ) { SetCurrScope(base); } makeThrowCnv( ctl, ScopeClass( base ), ctl->offset ); SetCurrScope(curr_scope); } }
// forms: #pragma extref( symbol [, ...] ) // #pragma extref( "name" [, ...] ) // // causes a external reference to be emitted for the symbol or "name" // static void parseExtRef( // PARSE SYMBOL NAME void ) { PRAG_EXT_REF *entry; if( CurToken == T_STRING ) { entry = RingAlloc( &pragmaExtrefs, offsetof( PRAG_EXT_REF, name ) + TokenLen + 1 ); memcpy( entry->name, Buffer, TokenLen + 1 ); entry->symbol = NULL; } else if( IS_ID_OR_KEYWORD( CurToken ) ) { SEARCH_RESULT* result; NAME name = NameCreateLen( Buffer, TokenLen ); result = ScopeFindNaked( GetCurrScope(), name ); if( result == NULL ) { CErr2p( ERR_PRAG_EXTREF_NONE, Buffer ); } else { SYMBOL_NAME sname = result->sym_name; SYMBOL sym = sname->name_syms; ScopeFreeResult( result ); if( sym == NULL ) { CErr2p( ERR_PRAG_EXTREF_BAD, Buffer ); } else if( SymIsFunction( sym ) ) { if( IsOverloadedFunc( sym ) ) { CErr2p( ERR_PRAG_EXTREF_OVERLOADED, sym ); sym = NULL; } } else if( SymIsData( sym ) ) { // no checks now } else { CErr2p( ERR_PRAG_EXTREF_BAD, sym ); sym = NULL; } if( sym != NULL ) { entry = RingAlloc( &pragmaExtrefs, offsetof( PRAG_EXT_REF, name ) + 1 ); entry->symbol = sym; entry->name[0] = '\0'; } } } }
void ModuleInitInit( // START MODULE-INITIALIZATION FUNCTION void ) { SYMBOL module_init; // - SYMBOL for mod-init. function SCOPE curr_scope; // - current scope TYPE fn_type; // - type for init function curr_scope = moduleInitSave(); fn_type = TypeVoidFunOfVoid(); module_init = SymCreateFileScope( fn_type , SC_STATIC , 0 , CppSpecialName( SPECIAL_INIT_FUNCTION ) ); module_init_func = module_init; SetCurrScope(GetFileScope()); ScopeBeginFunction( module_init ); FunctionBodyStartup( module_init, &module_fd, FUNC_NULL ); module_fd.retn_opt = false; module_init_scope = GetCurrScope(); ScopeKeep( module_init_scope ); moduleInitRestore( curr_scope ); }
CGFILE_INS CgFrontFuncOpen( // OPEN A FUNCTION (AND ITS FILE) SYMBOL func, // - symbol for function TOKEN_LOCN *posn ) // - source position { CGFILE_GEN *gen; // - generation data DT_METHOD dtm; // - destruction method for function CGFILE_INS reg; // - position to zap for function registration codeCGFILE = CgioCreateFile( func ); if( posn != NULL ) { codeCGFILE->defined = *posn; } gen = getGenData(); if( posn != NULL ) { emitSourcePosn( gen, posn ); } CgFrontCodePtr( IC_FUNCTION_OPEN, func ); CgFrontCodePtr( IC_FUNCTION_ARGS, GetCurrScope() ); dtm = CompInfo.dt_method_speced; if( ! SymIsDtor( func ) ) { switch( dtm ) { case DTM_DIRECT_SMALL : dtm = DTM_DIRECT; break; case DTM_TABLE_SMALL : dtm = DTM_TABLE; break; } } CompInfo.dt_method = dtm; CgFrontCodeUint( IC_FUNCTION_DTM, dtm ); CgFrontCode( IC_NO_OP ); // - may be zapped to IC_FUNCTION_STAB reg = CgioLastWrite( codeCGFILE ); gen->emit_line_no.src_file = NULL; if( posn != NULL ) { emitSourcePosn( gen, posn ); } return reg; }
static void typeSigAccess( // HANDLE ACCESS FOR TYPE-SIGNATURE TYPE_SIG_ACCESS acc, // - access type TYPE_SIG *sig, // - current signature TOKEN_LOCN* err_locn, // - error location for access errors bool *error_occurred ) // - to set error indication { ACCINFO info; // - access information if( (TSA_GEN & acc) == 0 ) { info.acc = acc; info.type = StructType( sig->type ); if( info.type != NULL ) { info.err_occurred = error_occurred; info.err_locn = err_locn; info.access_scope = GetCurrScope(); info.class_scope = TypeScope( info.type ); typeSigAccessVar( TSA_DTOR, &sig->dtor, &info ); typeSigAccessVar( TSA_DEFAULT_CTOR, &sig->default_ctor, &info ); typeSigAccessVar( TSA_COPY_CTOR, &sig->copy_ctor, &info ); SetCurrScope(info.access_scope); } } }
static void pragDumpObjectModel( // DUMP OBJECT MODEL void ) { if( IS_ID_OR_KEYWORD( CurToken ) ) { NAME name = NameCreateLen( Buffer, TokenLen ); SEARCH_RESULT* result = ScopeFindNaked( GetCurrScope(), name ); if( result == NULL ) { CErr2p( ERR_DUMP_OBJ_MODEL, Buffer ); } else { SYMBOL_NAME sname = result->sym_name; ScopeFreeResult( result ); if( sname->name_syms == NULL ) { TYPE type = sname->name_type->sym_type; if( TypeDefined( type ) ) { TYPE dump_type; dump_type = StructType( type ); if( dump_type != NULL ) { DumpObjectModelClass( dump_type ); } else { dump_type = EnumType( type ); if( dump_type != NULL ) { DumpObjectModelEnum( dump_type ); } else { CErr2p( ERR_DUMP_OBJ_MODEL, Buffer ); } } } else { CErr2p( ERR_DUMP_OBJ_MODEL, Buffer ); } } else { CErr2p( ERR_DUMP_OBJ_MODEL, Buffer ); } } NextToken(); } }
SCOPE ScopeForTemps( // FIND SCOPE FOR TEMPORARIES void ) { return tempScope == NULL ? GetCurrScope() : tempScope; }