Ignore:
Timestamp:
Dec 16, 2014, 9:41:50 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

remove Parser.old, add -XCFA to driver, copy ptrdiff_t from stddef.h in preclude, remove casts from initialization constants, adjust formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/ControlStruct/LabelTypeChecker.cc

    r3848e0e rd9a0e76  
    1111
    1212namespace 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    }
    1325
    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();
    2330    }
    24     return;
    25   }
    2631
    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 );
    3234
    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    }
    3539
    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;
    4044
    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() );
    4554
    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");
    5563
    56     PointerType *ptr;
    57     if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 )
    58       if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 )
    5964        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    }
    6766} // namespace ControlStruct
    68 
    69 
    70 
    71 
    72 
Note: See TracChangeset for help on using the changeset viewer.