[51587aa] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[a08ba92] | 7 | // LabelTypeChecker.cc -- |
---|
[51587aa] | 8 | // |
---|
[843054c2] | 9 | // Author : Rodolfo G. Esteves |
---|
[51587aa] | 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[1869adf] | 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Wed Jun 24 16:24:48 2015 |
---|
| 13 | // Update Count : 3 |
---|
[51587aa] | 14 | // |
---|
[a08ba92] | 15 | |
---|
[51b7345] | 16 | #include <list> |
---|
| 17 | #include <cassert> |
---|
| 18 | |
---|
| 19 | #include "SynTree/Type.h" |
---|
| 20 | #include "SynTree/Statement.h" |
---|
| 21 | #include "SynTree/Expression.h" |
---|
| 22 | #include "SynTree/Declaration.h" |
---|
| 23 | |
---|
| 24 | #include "LabelTypeChecker.h" |
---|
| 25 | |
---|
| 26 | namespace ControlStruct { |
---|
[a08ba92] | 27 | void LabelTypeChecker::visit(UntypedExpr *untypedExpr) { |
---|
| 28 | assert( untypedExpr != 0 ); |
---|
| 29 | NameExpr *fname; |
---|
| 30 | if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) |
---|
[1869adf] | 31 | && fname->get_name() == std::string("&&") ) |
---|
[a08ba92] | 32 | std::cerr << "Taking the label of an address." << std::endl; |
---|
| 33 | else { |
---|
| 34 | acceptAll( untypedExpr->get_results(), *this ); |
---|
| 35 | acceptAll( untypedExpr->get_args(), *this ); |
---|
| 36 | } // if |
---|
| 37 | return; |
---|
| 38 | } |
---|
[51b7345] | 39 | |
---|
[a08ba92] | 40 | void LabelTypeChecker::visit(CompoundStmt *compoundStmt) { |
---|
| 41 | index.enterScope(); |
---|
| 42 | acceptAll( compoundStmt->get_kids(), *this ); |
---|
| 43 | index.leaveScope(); |
---|
| 44 | } |
---|
[51b7345] | 45 | |
---|
[a08ba92] | 46 | void LabelTypeChecker::visit(DeclStmt *declStmt) { |
---|
| 47 | declStmt->accept( index ); |
---|
[51b7345] | 48 | |
---|
[a08ba92] | 49 | //ObjectDecl *odecl = 0; |
---|
| 50 | // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ) { |
---|
| 51 | return; |
---|
| 52 | } |
---|
[51b7345] | 53 | |
---|
[a08ba92] | 54 | void LabelTypeChecker::visit(BranchStmt *branchStmt) { |
---|
| 55 | if ( branchStmt->get_type() != BranchStmt::Goto ) return; |
---|
| 56 | Expression *target; |
---|
| 57 | if ( (target = branchStmt->get_computedTarget()) == 0 ) return; |
---|
[51b7345] | 58 | |
---|
[a08ba92] | 59 | NameExpr *name; |
---|
| 60 | if ( ((name = dynamic_cast<NameExpr *>(target)) == 0) ) |
---|
| 61 | return; // Not a name expression |
---|
| 62 | |
---|
| 63 | std::list< DeclarationWithType * > interps; |
---|
| 64 | index.lookupId(name->get_name(), interps); |
---|
| 65 | if ( interps.size() != 1) |
---|
| 66 | // in case of multiple declarations |
---|
| 67 | throw SemanticError("Illegal label expression: " + name->get_name() ); |
---|
[d9a0e76] | 68 | |
---|
[a08ba92] | 69 | PointerType *ptr; |
---|
| 70 | if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 ) |
---|
| 71 | if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 ) |
---|
| 72 | return; |
---|
| 73 | else |
---|
| 74 | throw SemanticError("Wrong type of parameter for computed goto"); |
---|
| 75 | else |
---|
| 76 | throw SemanticError("Wrong type of parameter for computed goto"); |
---|
[51b7345] | 77 | |
---|
[a08ba92] | 78 | return; |
---|
| 79 | } |
---|
[51b7345] | 80 | } // namespace ControlStruct |
---|
[a08ba92] | 81 | |
---|
[51587aa] | 82 | // Local Variables: // |
---|
| 83 | // tab-width: 4 // |
---|
| 84 | // mode: c++ // |
---|
| 85 | // compile-command: "make install" // |
---|
| 86 | // End: // |
---|