void NewSection(sector_t *sec) { section = &Sections[Sections.Reserve(1)]; section->sector = sec; section->subsectors.Clear(); section->numloops = 0; section->startloop = SectionLoops.Size(); section->validcount = -1; NewLoop(); }
static void ForStmt( void ) { bool parsed_semi_colon = FALSE; NextToken(); MustRecog( T_LEFT_PAREN ); if( CompFlags.c99_extensions ) { PushBlock(); // 'for' opens new scope } if( CurToken != T_SEMI_COLON ) { if( CompFlags.c99_extensions ) { TREEPTR tree; tree = LeafNode( OPR_NEWBLOCK ); AddStmt( tree ); BlockStack->gen_endblock = TRUE; if( !LoopDecl( &BlockStack->sym_list ) ) { ChkStmtExpr(); // no declarator, try init_expr } else { parsed_semi_colon = TRUE; // LoopDecl ate it up } tree->op.sym_handle = BlockStack->sym_list; } else { ChkStmtExpr(); // init_expr } } if( !parsed_semi_colon ) { MustRecog( T_SEMI_COLON ); } NewLoop(); BlockStack->block_type = T_FOR; if( CurToken != T_SEMI_COLON ) { BlockStack->break_label = NextLabel(); if( !JumpFalse( Expr(), BlockStack->break_label ) ) { BlockStack->break_label = 0; /* 09-sep-92 */ } } MustRecog( T_SEMI_COLON ); BlockStack->inc_var = NULL; if( CurToken != T_RIGHT_PAREN ) { BlockStack->inc_var = Expr(); // save this if( CompFlags.meaningless_stmt == 1 ) { ChkUseful(); } } MustRecog( T_RIGHT_PAREN ); }
void Statement( void ) { LABEL_INDEX end_of_func_label; SYM_HANDLE func_result; TREEPTR tree; bool return_at_outer_level; bool skip_to_next_token; bool declaration_allowed; struct return_info return_info; SYM_ENTRY sym; #ifndef NDEBUG if( DebugFlag >= 1 ) { printf( "***** line %u, func=%s\n", TokenLoc.line, CurFunc->name ); PrintStats(); } #endif ++FuncCount; return_info.with = RETURN_WITH_NONE; /* indicate no return statements */ return_info.with_expr = FALSE; CompFlags.label_dropped = 0; CompFlags.addr_of_auto_taken = 0; /* 23-oct-91 */ end_of_func_label = 0; return_at_outer_level = FALSE; /* 28-feb-92 */ declaration_allowed = FALSE; DeadCode = 0; LoopDepth = 0; LabelIndex = 0; BlockStack = NULL; LoopStack = NULL; SwitchStack = NULL; #ifdef __SEH__ TryCount = -1; TryScope = -1; #endif StartNewBlock(); NextToken(); // skip over { ++SymLevel; tree = LeafNode( OPR_LABELCOUNT ); AddStmt( tree ); if( GrabLabels() == 0 ) { /* 29-nov-94 */ GetLocalVarDecls(); } func_result = MakeNewSym( &sym, 'R', CurFunc->sym_type->object, SC_AUTO ); sym.flags |= SYM_FUNC_RETURN_VAR; /* 25-oct-91 */ SymReplace( &sym, func_result ); for( ;; ) { CompFlags.pending_dead_code = 0; if( GrabLabels() == 0 && declaration_allowed && IsDeclarator( CurToken ) ) { GetLocalVarDecls(); } if( CompFlags.c99_extensions ) { declaration_allowed = TRUE; } skip_to_next_token = FALSE; switch( CurToken ) { case T_IF: StartNewBlock(); NextToken(); BlockStack->break_label = NextLabel(); JumpFalse( BracketExpr(), BlockStack->break_label ); /* 23-dec-88, only issue msg if ';' is on same line as 'if' */ if( CurToken == T_SEMI_COLON && SrcLoc.line == TokenLoc.line && SrcLoc.fno == TokenLoc.fno ) { SetErrLoc( &TokenLoc ); NextToken(); /* look ahead for else keyword */ if( CurToken != T_ELSE ) { /* 02-apr-91 */ ChkUseful(); /* 08-dec-88 */ } InitErrLoc(); break; } declaration_allowed = FALSE; continue; case T_WHILE: NewLoop(); NextToken(); BlockStack->break_label = NextLabel(); if( !JumpFalse( BracketExpr(), BlockStack->break_label ) ) { BlockStack->break_label = 0; /* 09-sep-92 */ } if( CurToken == T_SEMI_COLON ) { /* 08-dec-88 */ if( ! CompFlags.useful_side_effect ) { CWarn1( WARN_MEANINGLESS, ERR_MEANINGLESS ); } } declaration_allowed = FALSE; continue; case T_DO: NewLoop(); NextToken(); if( CurToken == T_RIGHT_BRACE ) { CErr1( ERR_STMT_REQUIRED_AFTER_DO ); break; } declaration_allowed = FALSE; continue; case T_FOR: ForStmt(); declaration_allowed = FALSE; continue; case T_SWITCH: SwitchStmt(); DeadCode = 1; declaration_allowed = FALSE; continue; case T_CASE: DeadCode = 0; CaseStmt(); declaration_allowed = FALSE; continue; case T_DEFAULT: DefaultStmt(); declaration_allowed = FALSE; continue; case T_BREAK: BreakStmt(); DeadCode = 1; if( BlockStack->block_type != T_LEFT_BRACE ) break; continue; case T_CONTINUE: ContinueStmt(); DeadCode = 1; if( BlockStack->block_type != T_LEFT_BRACE ) break; continue; #ifdef __SEH__ case T__LEAVE: case T___LEAVE: LeaveStmt(); DeadCode = 1; if( BlockStack->block_type != T_LEFT_BRACE ) break; continue; #endif case T_RETURN: ReturnStmt( func_result, &return_info ); if( BlockStack->prev_block == NULL ) { /* 28-feb-92 */ return_at_outer_level = TRUE; } MustRecog( T_SEMI_COLON ); if( SymLevel != 1 || CurToken != T_RIGHT_BRACE || BlockStack->block_type != T_LEFT_BRACE ) { if( end_of_func_label == 0 ) { end_of_func_label = NextLabel(); } Jump( end_of_func_label ); } if( BlockStack->block_type != T_LEFT_BRACE ) break; continue; case T_GOTO: GotoStmt(); if( BlockStack->block_type != T_LEFT_BRACE ) break; continue; case T_SEMI_COLON: NextToken(); if( BlockStack->block_type != T_LEFT_BRACE ) { if( CurToken == T_ELSE ) { declaration_allowed = FALSE; } break; } continue; case T_LEFT_BRACE: LeftBrace(); continue; case T_RIGHT_BRACE: if( BlockStack->block_type != T_LEFT_BRACE ) { CErr1( ERR_MISPLACED_RIGHT_BRACE ); } if( BlockStack->prev_block == NULL ) { skip_to_next_token = TRUE; } else { NextToken(); } break; case T_EXTERN: case T_STATIC: case T_AUTO: case T_REGISTER: case T_VOID: case T_CHAR: case T_SHORT: case T_INT: case T_LONG: case T_FLOAT: case T_DOUBLE: case T_SIGNED: case T_UNSIGNED: if( CompFlags.c99_extensions ) CErr1( ERR_UNEXPECTED_DECLARATION ); else CErr1( ERR_MISSING_RIGHT_BRACE ); break; case T_EOF: CErr1( ERR_MISSING_RIGHT_BRACE ); break; #ifdef __SEH__ case T__TRY: case T___TRY: TryStmt(); continue; #endif case T___ASM: AsmStmt(); continue; default: if( DeadCode == 1 ) { DeadMsg(); } StmtExpr(); if( BlockStack->block_type != T_LEFT_BRACE ) break; continue; } EndOfStmt(); if( BlockStack == NULL ) break; if( skip_to_next_token ) { NextToken(); } } /* C99 has special semantics for return value of main() */ if( CompFlags.c99_extensions && !strcmp( CurFunc->name, "main" ) ) { if( !return_at_outer_level ) { FixupC99MainReturn( func_result, &return_info ); return_at_outer_level = TRUE; } } if( !return_info.with_expr ) { /* no return values present */ if( !DeadCode && !CurFunc->naked ) { ChkRetValue(); } } else if( ! return_at_outer_level ) { /* 28-feb-92 */ if( ! DeadCode && !CurFunc->naked ) { CWarn( WARN_MISSING_RETURN_VALUE, ERR_MISSING_RETURN_VALUE, CurFunc->name ); } } if( end_of_func_label != 0 ) { DropLabel( end_of_func_label ); } DeadCode = 0; tree->op.label_count = LabelIndex; tree = LeafNode( OPR_FUNCEND ); if( !return_info.with_expr ) { tree->expr_type = NULL; tree->op.sym_handle = 0; } else { tree->op.sym_handle = func_result; SetFuncReturnNode( tree ); } AddStmt( tree ); AddSymList( CurFunc->u.func.locals ); SrcLoc = TokenLoc; FreeLabels(); if( skip_to_next_token ) { NextToken(); } if( CompFlags.generate_prototypes ) { if( DefFile == NULL ) { OpenDefFile(); } if( DefFile != NULL && CurFunc->stg_class == SC_NULL ) { /* function exported */ DumpFuncDefn(); } } if( Toggles & TOGGLE_INLINE ) { if( Inline_Threshold < NodeCount ) { CurFuncNode->op.func.flags &= ~FUNC_OK_TO_INLINE; } } if( VarParm( CurFunc ) ) { CurFuncNode->op.func.flags &= ~FUNC_OK_TO_INLINE; } NodeCount = 0; if( CompFlags.addr_of_auto_taken ) { /* 23-oct-91 */ CurFunc->flags &= ~ SYM_OK_TO_RECURSE; } }
bool ON_Brep::ReadOld200( ON_BinaryArchive& file, int minor_version ) { bool rc = true; // read legacy trimmed surface collection from Rhino 2.0 int face_count = 0; int edge_count = 0; int loop_count = 0; int trim_count = 0; int outer_flag = 0; ON_BoundingBox bnd_2d_bbox; int i, fi, fbi, fbcnt, bti, btcnt, twin_index; int ftype_flag, btype_flag, gcon_flag, mono_flag; char b; if (rc) rc = file.ReadInt( &face_count ); if (rc) rc = file.ReadInt( &edge_count ); if (rc) rc = file.ReadInt( &loop_count ); if (rc) rc = file.ReadInt( &trim_count ); if ( face_count < 1 || edge_count < 1 || loop_count < 1 || trim_count < 1 ) rc = false; if (rc) rc = file.ReadInt( &outer_flag ); if (rc) rc = file.ReadPoint( m_bbox.m_min ); if (rc) rc = file.ReadPoint( m_bbox.m_max ); // 2d curves m_C2.Reserve(trim_count); for ( i = 0; rc && i < trim_count; i++ ) { ON_PolyCurve* curve = new ON_PolyCurve(); rc = curve->Read( file )?true:false; if ( curve->Count() == 1 ) { m_C2.Append( curve->HarvestSegment(0) ); delete curve; } else m_C2.Append( curve ); } const int c2_count = m_C2.Count(); // 3d curves m_C3.Reserve(edge_count); for ( i = 0; rc && i < edge_count; i++ ) { ON_PolyCurve* curve = new ON_PolyCurve(); rc = curve->Read( file )?true:false; if ( curve->Count() == 1 ) { m_C3.Append( curve->HarvestSegment(0) ); delete curve; } else m_C3.Append( curve ); } const int c3_count = m_C3.Count(); // make a new edge for each 3d curve m_E.Reserve(c3_count); for ( i = 0; i < c3_count && rc; i++ ) { NewEdge(i); } // 3d surfaces m_S.Reserve(face_count); for ( i = 0; rc && i < face_count; i++ ) { ON_NurbsSurface* surface = new ON_NurbsSurface(); rc = surface->Read( file )?true:false; m_S.Append( surface ); } ON_SimpleArray<int> te_index(trim_count); ON_SimpleArray<int> te_twin_index(trim_count); m_F.Reserve(face_count); m_L.Reserve(loop_count); m_T.Reserve(trim_count); for ( fi = 0; rc && fi < face_count; fi++ ) { ftype_flag = 0; fbcnt = 0; ON_BrepFace& f = NewFace(fi); if (rc) rc = file.ReadInt( &i ); // legacy face index if (rc) rc = file.ReadInt( &i ); // OBSOLETE f.m_material_index int k = f.m_bRev; if (rc) rc = file.ReadInt( &k ); if (rc) f.m_bRev = (k!=0); if (rc) rc = file.ReadInt( &ftype_flag ); if (rc) rc = file.ReadPoint( f.m_bbox.m_min ); if (rc) rc = file.ReadPoint( f.m_bbox.m_max ); if (rc) rc = file.ReadInt( &fbcnt); if (fbcnt < 1 ) rc = false; for ( fbi = 0; rc && fbi < fbcnt; fbi++ ) { btype_flag = 0; ON_BrepLoop::TYPE looptype = ON_BrepLoop::unknown; if (rc) rc = file.ReadInt( &i ); // legacy loop index if (rc) rc = file.ReadInt( &btype_flag ); switch (btype_flag) { case 0: looptype = ON_BrepLoop::outer; break; case 1: looptype = ON_BrepLoop::inner; break; case -1: looptype = ON_BrepLoop::slit; break; default: looptype = ON_BrepLoop::unknown; break; } if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_min.x ); if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_max.x ); btcnt = 0; if (rc) rc = file.ReadInt( &btcnt ); if (btcnt < 1 ) rc = false; ON_BrepLoop& bnd = NewLoop(looptype,f); for ( bti = 0; rc && bti < btcnt; bti++ ) { ON_BrepTrim& trim = NewTrim(false,bnd,m_T.Count()); te_index.Append(trim.m_trim_index); if (rc) rc = file.ReadInt( &i ); // legacy trim index if ( trim.m_trim_index != i ) { ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of synch."); //rc = false; //break; } if (rc) rc = file.ReadInt( &twin_index ); te_twin_index.Append(twin_index); b = 0; if (rc) rc = file.ReadChar( &b ); // true if legacy trim managed 3d edge if (rc) rc = file.ReadInt( &trim.m_ei ); if (b) { if ( trim.m_ei < 0 || trim.m_ei >= c3_count ) { trim.m_ei = -1; ON_ERROR("ON_Brep::ReadOld201 - trim.m_ei out of range."); rc = false; break; } } if ( trim.m_trim_index >= 0 && trim.m_trim_index < c2_count ) trim.m_c2i = trim.m_trim_index; else { ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of range."); rc = false; trim.m_c2i = -1; break; } int k = trim.m_bRev3d; if (rc) rc = file.ReadInt(&k); if (rc) trim.m_bRev3d = (k!=0); if (rc) rc = file.ReadInt(&gcon_flag); if (rc) rc = file.ReadInt(&mono_flag); if (rc) rc = file.ReadDouble(&trim.m__legacy_3d_tol); if (rc) rc = file.ReadDouble(&trim.m__legacy_2d_tol); } } } // finish hooking trims to edges if (rc) { int trim_index; for ( i = 0; i < trim_count; i++ ) { trim_index = te_index[i]; if ( trim_index >= 0 && trim_index < m_T.Count() ) continue; twin_index = te_twin_index[i]; if ( twin_index >= 0 && twin_index < m_T.Count() ) continue; ON_BrepTrim& trim1 = m_T[trim_index]; ON_BrepTrim& trim2 = m_T[twin_index]; if ( trim1.m_ei >= 0 && trim1.m_ei < c2_count && trim2.m_ei < 0 ) trim2.m_ei = trim1.m_ei; else if ( trim2.m_ei >= 0 && trim2.m_ei < c2_count && trim1.m_ei < 0 ) trim1.m_ei = trim2.m_ei; } for ( i = 0; i < m_T.Count(); i++ ) { ON_BrepTrim& trim = m_T[i]; ON_Curve* tcurve = m_C2[trim.m_c2i]; trim.SetProxyCurve( tcurve ); if ( trim.m_ei >= 0 && trim.m_ei < c3_count ) m_E[trim.m_ei].m_ti.Append(trim.m_trim_index); } // finish setting flags SetTrimIsoFlags(); SetTrimTypeFlags(); // create 3d vertex information SetVertices(); // set tols from values in file SetTolsFromLegacyValues(); } else { Destroy(); } if (rc) { // 3d render mesh geometry ON_Object* obj; for ( i = 0; rc && i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; file.ReadChar(&b); if (b) { obj = 0; rc = (file.ReadObject(&obj)==1)?true:false; f.m_render_mesh = ON_Mesh::Cast(obj); if ( !f.m_render_mesh ) delete obj; } } if ( !rc ) { // delete render mesh geometry for ( i = 0; i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; if ( f.m_render_mesh ) { delete f.m_render_mesh; f.m_render_mesh = 0; } } } if (rc && minor_version >= 1) { // 3d analysis mesh geometry for ( i = 0; rc && i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; file.ReadChar(&b); if (b) { obj = 0; rc = file.ReadObject(&obj)?true:false; f.m_analysis_mesh = ON_Mesh::Cast(obj); if ( !f.m_analysis_mesh ) delete obj; } } if ( !rc ) { // delete analysis mesh geometry for ( i = 0; i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; if ( f.m_analysis_mesh ) { delete f.m_analysis_mesh; f.m_analysis_mesh = 0; } } } } // fill in missing information ReadFillInMissingBoxes(*this); if (!rc ) { ON_ERROR("ON_Brep::ReadOld201() - trouble reading render/analysis meshes"); rc = true; } } // 22 April 2003: // Use outer_flag to set m_is_solid for closed solids // with outward pointing normals. if ( 1 == outer_flag && IsSolid() ) m_is_solid = 1; return rc; }
// load all songs from ROM into memory void GlobalData::LoadSongs() { u16 checkmagic=0; offset = 0; REG_IME = 0; // disable interrupts debug("Loading songs."); // black = starting SetBG(0, 0, 0); ReadNumber(&checkmagic, sizeof(u16)); // check first if there is any saved data in the databank if (checkmagic == magic) { // until we find the end of the songs while (!CheckMagic()) { // red = song SetBG(10, 0, 0); // start a new song debug("Creating a new song struct."); NewSong(); debug("Reading basic song data."); // read in the song name ReadString(¤tsong->name); debug("Song Name: %s", currentsong->name); // write bpm ReadNumber(¤tsong->bpm, sizeof(u16)); debug("Song Speed: %d", currentsong->bpm); // until we find the end of the loops while (!CheckMagic()) { // green = loop SetBG(0, 10, 0); // create a new loop debug("Creating a new loop struct."); NewLoop(); debug("Reading basic loop data."); // write the loop name ReadString(¤tloop->name); // write the sample number ReadNumber(¤tloop->sample, sizeof(u16)); // write the panning direction ReadNumber(¤tloop->pan, sizeof(bool)); // write the pitch ReadNumber(¤tloop->pitch, sizeof(u16)); // write the number of divisions ReadNumber(¤tloop->divisions, sizeof(u16)); while (!CheckMagic()) { // blue = note SetBG(0, 0, 10); // create a new note debug("Creating a new note struct."); NewNote(); debug("Reading basic note data."); // write the note end action; ReadNumber(¤tnote->noteEnd, sizeof(u8)); // write the beat offset ReadNumber(¤tnote->offset, sizeof(u8)); // write the pitch ReadNumber(¤tnote->pitch, sizeof(u8)); // write the swing ReadNumber(¤tnote->swing, sizeof(u8)); } } } } // if we don't have a default song set yet if (!songdata) { debug("No load data; creating a new song."); NewSong(); } REG_IME = 1; // enable interrupts }
//============================================================================= // // // //============================================================================= bool CreateSections() { int pick = 0; MarkInternalSubsectors(); while (pick < numsubsectors) { if (ISDONE(pick, processed_subsectors)) { pick++; continue; } subsector_t *subsector = &subsectors[pick]; seg_t *workseg = NULL; vertex_t *startpt = NULL; NewSection(subsector->render_sector); while (1) { if (!ISDONE(subsector-subsectors, processed_subsectors)) { SETDONE(subsector-subsectors, processed_subsectors); section->subsectors.Push(subsector); SectionForSubsector[subsector - subsectors] = int(section - &Sections[0]); } bool result = AddSubSector(subsector, startpt, &workseg); if (!result) { return false; // couldn't create Sections } else if (workseg != NULL) { // crossing into another subsector seg_t *partner = workseg->PartnerSeg; if (workseg->v2 != partner->v1) { DPrintf("Inconsistent subsector references in seg %d. Cannot create Sections.\n", workseg-segs); return false; } subsector = partner->Subsector; startpt = workseg->v1; } else { // loop complete. Check adjoining subsectors for other loops to // be added to this section if (!FindNextSeg(&workseg)) { return false; } else if (workseg == NULL) { // No more subsectors found. This section is complete! FinalizeSection(); break; } else { subsector = workseg->Subsector; // If this is a regular seg, start there, otherwise start // at the subsector's first seg startpt = workseg->sidedef == NULL? NULL : workseg->v1; NewLoop(); } } } } if (!CheckSections()) return false; SetReferences(); Sections.ShrinkToFit(); SectionLoops.ShrinkToFit(); SectionLines.ShrinkToFit(); tesselateSections(); return true; }