source: translator/ControlStruct/LabelTypeChecker.cc @ 51587aa

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: fourth groups of files

  • Property mode set to 100644
File size: 2.4 KB
Line 
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//
7// XXX.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By :
12// Last Modified On :
13// Update Count     : 0
14//
15#include <list>
16#include <cassert>
17
18#include "SynTree/Type.h"
19#include "SynTree/Statement.h"
20#include "SynTree/Expression.h"
21#include "SynTree/Declaration.h"
22
23#include "LabelTypeChecker.h"
24
25
26namespace ControlStruct {
27    void LabelTypeChecker::visit(UntypedExpr *untypedExpr){
28        assert( untypedExpr != 0 );
29        NameExpr *fname;
30        if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) 
31            && fname->get_name() == std::string("LabAddress") )
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    }
39
40    void LabelTypeChecker::visit(CompoundStmt *compoundStmt) {
41        index.enterScope();
42        acceptAll( compoundStmt->get_kids(), *this );
43        index.leaveScope();
44    }
45
46    void LabelTypeChecker::visit(DeclStmt *declStmt){
47        declStmt->accept( index );
48
49        //ObjectDecl *odecl = 0;
50        // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ){
51        return;
52    }
53
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;
58
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() );
68
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");
77
78        return;
79    }
80} // namespace ControlStruct
81// Local Variables: //
82// tab-width: 4 //
83// mode: c++ //
84// compile-command: "make install" //
85// End: //
Note: See TracBrowser for help on using the repository browser.