Changeset d9a0e76 for translator/ControlStruct/LabelTypeChecker.cc
- Timestamp:
- Dec 16, 2014, 9:41:50 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 17cd4eb
- Parents:
- 3848e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ControlStruct/LabelTypeChecker.cc
r3848e0e rd9a0e76 11 11 12 12 namespace ControlStruct { 13 void LabelTypeChecker::visit(UntypedExpr *untypedExpr){ 14 assert( untypedExpr != 0 ); 15 NameExpr *fname; 16 if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) 17 && fname->get_name() == std::string("LabAddress") ) 18 std::cerr << "Taking the label of an address." << std::endl; 19 else { 20 acceptAll( untypedExpr->get_results(), *this ); 21 acceptAll( untypedExpr->get_args(), *this ); 22 } // if 23 return; 24 } 13 25 14 void LabelTypeChecker::visit(UntypedExpr *untypedExpr){ 15 assert( untypedExpr != 0 ); 16 NameExpr *fname; 17 if( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) 18 && fname->get_name() == std::string("LabAddress") ) 19 std::cerr << "Taking the label of an address." << std::endl; 20 else { 21 acceptAll( untypedExpr->get_results(), *this ); 22 acceptAll( untypedExpr->get_args(), *this ); 26 void LabelTypeChecker::visit(CompoundStmt *compoundStmt) { 27 index.enterScope(); 28 acceptAll( compoundStmt->get_kids(), *this ); 29 index.leaveScope(); 23 30 } 24 return;25 }26 31 27 void LabelTypeChecker::visit(CompoundStmt *compoundStmt) { 28 index.enterScope(); 29 acceptAll( compoundStmt->get_kids(), *this ); 30 index.leaveScope(); 31 } 32 void LabelTypeChecker::visit(DeclStmt *declStmt){ 33 declStmt->accept( index ); 32 34 33 void LabelTypeChecker::visit(DeclStmt *declStmt){ 34 declStmt->accept( index ); 35 //ObjectDecl *odecl = 0; 36 // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ){ 37 return; 38 } 35 39 36 //ObjectDecl *odecl = 0;37 // if( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ){ 38 return;39 } 40 void LabelTypeChecker::visit(BranchStmt *branchStmt) { 41 if ( branchStmt->get_type() != BranchStmt::Goto ) return; 42 Expression *target; 43 if ( (target = branchStmt->get_computedTarget()) == 0 ) return; 40 44 41 void LabelTypeChecker::visit(BranchStmt *branchStmt) { 42 if( branchStmt->get_type() != BranchStmt::Goto ) return; 43 Expression *target; 44 if( (target = branchStmt->get_computedTarget()) == 0 ) return; 45 NameExpr *name; 46 if ( ((name = dynamic_cast<NameExpr *>(target)) == 0) ) 47 return; // Not a name expression 48 49 std::list< DeclarationWithType * > interps; 50 index.lookupId(name->get_name(), interps); 51 if ( interps.size() != 1) 52 // in case of multiple declarations 53 throw SemanticError("Illegal label expression: " + name->get_name() ); 45 54 46 NameExpr *name; 47 if( ((name = dynamic_cast<NameExpr *>(target)) == 0) ) 48 return; // Not a name expression 49 50 std::list< DeclarationWithType * > interps; 51 index.lookupId(name->get_name(), interps); 52 if ( interps.size() != 1) 53 // in case of multiple declarations 54 throw SemanticError("Illegal label expression: " + name->get_name() ); 55 PointerType *ptr; 56 if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 ) 57 if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 ) 58 return; 59 else 60 throw SemanticError("Wrong type of parameter for computed goto"); 61 else 62 throw SemanticError("Wrong type of parameter for computed goto"); 55 63 56 PointerType *ptr;57 if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 )58 if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 )59 64 return; 60 else 61 throw SemanticError("Wrong type of parameter for computed goto"); 62 else 63 throw SemanticError("Wrong type of parameter for computed goto"); 64 65 return; 66 } 65 } 67 66 } // namespace ControlStruct 68 69 70 71 72
Note: See TracChangeset
for help on using the changeset viewer.