Changeset 0dd3a2f for translator/SynTree
- Timestamp:
- May 18, 2015, 11:20:23 AM (11 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:
- 51587aa
- Parents:
- a32b204
- Location:
- translator/SynTree
- Files:
-
- 43 edited
-
AddressExpr.cc (modified) (2 diffs)
-
AggregateDecl.cc (modified) (5 diffs)
-
ApplicationExpr.cc (modified) (2 diffs)
-
ArrayType.cc (modified) (2 diffs)
-
AttrType.cc (modified) (2 diffs)
-
BasicType.cc (modified) (1 diff)
-
CodeGenVisitor.cc (modified) (2 diffs)
-
CodeGenVisitor.h (modified) (2 diffs)
-
CommaExpr.cc (modified) (2 diffs)
-
CompoundStmt.cc (modified) (2 diffs)
-
Constant.cc (modified) (3 diffs)
-
Constant.h (modified) (2 diffs)
-
DeclStmt.cc (modified) (2 diffs)
-
Declaration.cc (modified) (3 diffs)
-
Declaration.h (modified) (2 diffs)
-
DeclarationWithType.cc (modified) (2 diffs)
-
Expression.cc (modified) (5 diffs)
-
Expression.h (modified) (5 diffs)
-
FunctionDecl.cc (modified) (2 diffs)
-
FunctionType.cc (modified) (2 diffs)
-
Initializer.cc (modified) (5 diffs)
-
Initializer.h (modified) (4 diffs)
-
Mutator.cc (modified) (2 diffs)
-
Mutator.h (modified) (2 diffs)
-
NamedTypeDecl.cc (modified) (1 diff)
-
ObjectDecl.cc (modified) (2 diffs)
-
PointerType.cc (modified) (2 diffs)
-
ReferenceToType.cc (modified) (7 diffs)
-
Statement.cc (modified) (3 diffs)
-
Statement.h (modified) (2 diffs)
-
SynTree.h (modified) (3 diffs)
-
TupleExpr.cc (modified) (1 diff)
-
TupleType.cc (modified) (1 diff)
-
Type.cc (modified) (2 diffs)
-
Type.h (modified) (2 diffs)
-
TypeDecl.cc (modified) (1 diff)
-
TypeExpr.cc (modified) (2 diffs)
-
TypeSubstitution.cc (modified) (1 diff)
-
TypeSubstitution.h (modified) (3 diffs)
-
TypeofType.cc (modified) (2 diffs)
-
Visitor.cc (modified) (2 diffs)
-
Visitor.h (modified) (2 diffs)
-
VoidType.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/AddressExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AddressExpr.cc,v 1.6 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // AddressExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 23:54:44 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:48:14 2015 13 // Update Count : 5 14 // 7 15 8 16 #include "Expression.h" … … 10 18 #include "utility.h" 11 19 12 13 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) 14 : Expression( _aname ), arg( arg ) 15 { 20 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) { 16 21 for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) { 17 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );18 } 22 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) ); 23 } // for 19 24 } 20 25 21 AddressExpr::AddressExpr( const AddressExpr &other ) 22 : Expression( other ), arg( maybeClone( other.arg ) ) 23 { 26 AddressExpr::AddressExpr( const AddressExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 24 27 } 25 28 26 AddressExpr::~AddressExpr() 27 { 29 AddressExpr::~AddressExpr() { 28 30 delete arg; 29 31 } 30 32 31 void 32 AddressExpr::print( std::ostream &os, int indent ) const 33 { 33 void AddressExpr::print( std::ostream &os, int indent ) const { 34 34 os << std::string( indent, ' ' ) << "Address of:" << std::endl; 35 35 if ( arg ) { 36 arg->print( os, indent+2 );37 } 36 arg->print( os, indent+2 ); 37 } // if 38 38 } 39 39 40 40 // Local Variables: // 41 // tab-width: 4 // 42 // mode: c++ // 43 // compile-command: "make install" // 44 // End: // -
translator/SynTree/AggregateDecl.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AggregateDecl.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // AggregateDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 23:56:39 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:48:23 2015 13 // Update Count : 4 14 // 7 15 8 16 #include "Declaration.h" … … 11 19 12 20 13 AggregateDecl::AggregateDecl( const std::string &name ) 14 : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall ) 15 { 21 AggregateDecl::AggregateDecl( const std::string &name ) : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall ) { 16 22 } 17 23 18 AggregateDecl::AggregateDecl( const AggregateDecl &other ) 19 : Parent( other ) 20 { 24 AggregateDecl::AggregateDecl( const AggregateDecl &other ) : Parent( other ) { 21 25 cloneAll( other.members, members ); 22 26 cloneAll( other.parameters, parameters ); 23 27 } 24 28 25 AggregateDecl::~AggregateDecl() 26 { 29 AggregateDecl::~AggregateDecl() { 27 30 deleteAll( members ); 28 31 deleteAll( parameters ); 29 32 } 30 33 31 void 32 AggregateDecl::print( std::ostream &os, int indent ) const 33 { 34 void AggregateDecl::print( std::ostream &os, int indent ) const { 34 35 using std::string; 35 36 using std::endl; … … 37 38 os << typeString() << " " << get_name(); 38 39 if ( ! parameters.empty() ) { 39 os << endl << string( indent+2, ' ' ) << "with parameters" << endl;40 printAll( parameters, os, indent+4 );41 } 40 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 41 printAll( parameters, os, indent+4 ); 42 } // if 42 43 if ( ! members.empty() ) { 43 os << endl << string( indent+2, ' ' ) << "with members" << endl;44 printAll( members, os, indent+4 );45 } 44 os << endl << string( indent+2, ' ' ) << "with members" << endl; 45 printAll( members, os, indent+4 ); 46 } // if 46 47 } 47 48 48 void 49 AggregateDecl::printShort( std::ostream &os, int indent ) const 50 { 49 void AggregateDecl::printShort( std::ostream &os, int indent ) const { 51 50 using std::string; 52 51 using std::endl; … … 54 53 os << typeString() << " " << get_name(); 55 54 if ( ! parameters.empty() ) { 56 os << endl << string( indent+2, ' ' ) << "with parameters" << endl;57 printAll( parameters, os, indent+4 );58 } 55 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 56 printAll( parameters, os, indent+4 ); 57 } // if 59 58 } 60 59 … … 67 66 std::string ContextDecl::typeString() const { return "context"; } 68 67 68 // Local Variables: // 69 // tab-width: 4 // 70 // mode: c++ // 71 // compile-command: "make install" // 72 // End: // -
translator/SynTree/ApplicationExpr.cc
ra32b204 r0dd3a2f 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 // ApplicationExpr.cc.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:54:17 2015 13 // Update Count : 4 14 // 15 1 16 #include <cassert> 2 17 … … 8 23 9 24 10 ParamEntry::ParamEntry( const ParamEntry &other ) 11 : decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) 12 { 25 ParamEntry::ParamEntry( const ParamEntry &other ) : 26 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) { 13 27 } 14 28 15 ParamEntry & 16 ParamEntry::operator=( const ParamEntry &other ) 17 { 18 if ( &other == this ) return *this; 19 decl = other.decl; 20 actualType = maybeClone( other.actualType ); 21 formalType = maybeClone( other.formalType ); 22 expr = maybeClone( other.expr ); 23 return *this; 29 ParamEntry &ParamEntry::operator=( const ParamEntry &other ) { 30 if ( &other == this ) return *this; 31 decl = other.decl; 32 actualType = maybeClone( other.actualType ); 33 formalType = maybeClone( other.formalType ); 34 expr = maybeClone( other.expr ); 35 return *this; 24 36 } 25 37 26 ParamEntry::~ParamEntry() 27 { 28 delete actualType; 29 delete formalType; 30 delete expr; 38 ParamEntry::~ParamEntry() { 39 delete actualType; 40 delete formalType; 41 delete expr; 31 42 } 32 43 33 ApplicationExpr::ApplicationExpr( Expression *funcExpr ) 34 : function( funcExpr ) 35 { 36 PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); 37 assert( pointer ); 38 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); 39 assert( function ); 40 41 for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { 42 get_results().push_back( (*i)->get_type()->clone() ); 43 } 44 ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) { 45 PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); 46 assert( pointer ); 47 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); 48 assert( function ); 49 50 for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { 51 get_results().push_back( (*i)->get_type()->clone() ); 52 } // for 44 53 } 45 54 46 ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) 47 : Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) 48 { 49 cloneAll( other.args, args ); 55 ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) : 56 Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) { 57 cloneAll( other.args, args ); 50 58 } 51 59 52 ApplicationExpr::~ApplicationExpr() 53 { 54 delete function; 55 deleteAll( args ); 60 ApplicationExpr::~ApplicationExpr() { 61 delete function; 62 deleteAll( args ); 56 63 } 57 64 58 void 59 ApplicationExpr::print( std::ostream &os, int indent ) const 60 { 61 os << std::string( indent, ' ' ) << "Application of" << std::endl; 62 function->print( os, indent+2 ); 63 if ( ! args.empty() ) { 64 os << std::string( indent, ' ' ) << "to arguments" << std::endl; 65 printAll( args, os, indent+2 ); 66 } 67 if ( ! inferParams.empty() ) { 68 os << std::string(indent, ' ') << "with inferred parameters:" << std::endl; 69 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 70 os << std::string(indent+2, ' '); 71 Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); 72 os << std::endl; 73 } 74 } 75 Expression::print( os, indent ); 65 void ApplicationExpr::print( std::ostream &os, int indent ) const { 66 os << std::string( indent, ' ' ) << "Application of" << std::endl; 67 function->print( os, indent+2 ); 68 if ( ! args.empty() ) { 69 os << std::string( indent, ' ' ) << "to arguments" << std::endl; 70 printAll( args, os, indent+2 ); 71 } // if 72 if ( ! inferParams.empty() ) { 73 os << std::string(indent, ' ') << "with inferred parameters:" << std::endl; 74 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 75 os << std::string(indent+2, ' '); 76 Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); 77 os << std::endl; 78 } // for 79 } // if 80 Expression::print( os, indent ); 76 81 } 77 82 83 // Local Variables: // 84 // tab-width: 4 // 85 // mode: c++ // 86 // compile-command: "make install" // 87 // End: // -
translator/SynTree/ArrayType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: ArrayType.cc,v 1.6 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // ArrayType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:52:08 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" … … 12 20 13 21 ArrayType::ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ) 14 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) 15 { 16 base->set_isLvalue( false ); 22 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) { 23 base->set_isLvalue( false ); 17 24 } 18 25 19 26 ArrayType::ArrayType( const ArrayType &other ) 20 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 21 isVarLen( other.isVarLen ), isStatic( other.isStatic ) 22 { 27 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 28 isVarLen( other.isVarLen ), isStatic( other.isStatic ) { 23 29 } 24 30 25 ArrayType::~ArrayType() 26 { 27 delete base; 28 delete dimension; 31 ArrayType::~ArrayType() { 32 delete base; 33 delete dimension; 29 34 } 30 35 31 void 32 ArrayType::print( std::ostream &os, int indent ) const 33 { 34 Type::print( os, indent ); 35 if ( isStatic ) { 36 os << "static "; 37 } 38 if ( isVarLen ) { 39 os << "variable length array of "; 40 } else if ( dimension ) { 41 os << "array of "; 42 dimension->print( os, indent ); 43 } else { 44 os << "open array of "; 45 } 46 if ( base ) { 47 base->print( os, indent ); 48 } 36 void ArrayType::print( std::ostream &os, int indent ) const { 37 Type::print( os, indent ); 38 if ( isStatic ) { 39 os << "static "; 40 } // if 41 if ( isVarLen ) { 42 os << "variable length array of "; 43 } else if ( dimension ) { 44 os << "array of "; 45 dimension->print( os, indent ); 46 } else { 47 os << "open array of "; 48 } // if 49 if ( base ) { 50 base->print( os, indent ); 51 } // if 49 52 } 50 53 54 // Local Variables: // 55 // tab-width: 4 // 56 // mode: c++ // 57 // compile-command: "make install" // 58 // End: // -
translator/SynTree/AttrType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AttrType.cc,v 1.3 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:53:48 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Type.h" … … 12 20 13 21 AttrType::AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ) 14 : Type( tq ), name( name ), expr( expr ), type( 0 ), isType( false ) 15 { 22 : Type( tq ), name( name ), expr( expr ), type( 0 ), isType( false ) { 16 23 } 17 24 18 25 AttrType::AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ) 19 : Type( tq ), name( name ), expr( 0 ), type( type ), isType( true ) 20 { 26 : Type( tq ), name( name ), expr( 0 ), type( type ), isType( true ) { 21 27 } 22 28 23 29 AttrType::AttrType( const AttrType &other ) 24 : Type( other ), name( other.name ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) 25 { 30 : Type( other ), name( other.name ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 26 31 } 27 32 28 AttrType::~AttrType() 29 { 30 delete expr; 31 delete type; 33 AttrType::~AttrType() { 34 delete expr; 35 delete type; 32 36 } 33 37 34 void 35 AttrType::print( std::ostream &os, int indent ) const 36 { 37 Type::print( os, indent ); 38 os << "attribute " << name << " applied to "; 39 if ( expr ) { 40 os << "expression "; 41 expr->print( os, indent ); 42 } 43 if ( type ) { 44 os << "type "; 45 type->print( os, indent ); 46 } 38 void AttrType::print( std::ostream &os, int indent ) const { 39 Type::print( os, indent ); 40 os << "attribute " << name << " applied to "; 41 if ( expr ) { 42 os << "expression "; 43 expr->print( os, indent ); 44 } // if 45 if ( type ) { 46 os << "type "; 47 type->print( os, indent ); 48 } // if 47 49 } 48 50 51 // Local Variables: // 52 // tab-width: 4 // 53 // mode: c++ // 54 // compile-command: "make install" // 55 // End: // -
translator/SynTree/BasicType.cc
ra32b204 r0dd3a2f 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 // BasicType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:55:16 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 3 17 #include "Type.h" 4 5 18 6 19 BasicType::BasicType( const Type::Qualifiers &tq, Kind bt ) : Type( tq ), kind( bt ) {} 7 20 8 21 void BasicType::print( std::ostream &os, int indent ) const { 9 static const char *kindNames[] = {10 "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int",11 "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int",12 "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex",13 "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary"14 };22 static const char *kindNames[] = { 23 "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int", 24 "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int", 25 "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex", 26 "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary" 27 }; 15 28 16 Type::print( os, indent );17 os << kindNames[ kind ] << ' ';29 Type::print( os, indent ); 30 os << kindNames[ kind ] << ' '; 18 31 } 19 32 20 33 bool BasicType::isInteger() const { 21 switch ( kind ) { 22 case Bool: 23 case Char: 24 case SignedChar: 25 case UnsignedChar: 26 case ShortSignedInt: 27 case ShortUnsignedInt: 28 case SignedInt: 29 case UnsignedInt: 30 case LongSignedInt: 31 case LongUnsignedInt: 32 case LongLongSignedInt: 33 case LongLongUnsignedInt: 34 return true; 35 36 case Float: 37 case Double: 38 case LongDouble: 39 case FloatComplex: 40 case DoubleComplex: 41 case LongDoubleComplex: 42 case FloatImaginary: 43 case DoubleImaginary: 44 case LongDoubleImaginary: 34 switch ( kind ) { 35 case Bool: 36 case Char: 37 case SignedChar: 38 case UnsignedChar: 39 case ShortSignedInt: 40 case ShortUnsignedInt: 41 case SignedInt: 42 case UnsignedInt: 43 case LongSignedInt: 44 case LongUnsignedInt: 45 case LongLongSignedInt: 46 case LongLongUnsignedInt: 47 return true; 48 case Float: 49 case Double: 50 case LongDouble: 51 case FloatComplex: 52 case DoubleComplex: 53 case LongDoubleComplex: 54 case FloatImaginary: 55 case DoubleImaginary: 56 case LongDoubleImaginary: 57 return false; 58 case NUMBER_OF_BASIC_TYPES: 59 assert( false ); 60 } // switch 61 assert( false ); 45 62 return false; 46 47 case NUMBER_OF_BASIC_TYPES:48 assert( false );49 }50 assert( false );51 return false;52 63 } 53 64 54 65 66 // Local Variables: // 67 // tab-width: 4 // 68 // mode: c++ // 69 // compile-command: "make install" // 70 // End: // -
translator/SynTree/CodeGenVisitor.cc
ra32b204 r0dd3a2f 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 // CodeGenVisitor.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:57:51 2015 13 // Update Count : 3 14 // 15 1 16 #include <iostream> 2 17 #include <list> … … 7 22 using namespace std; 8 23 9 //*** Types 10 void CodeGenVisitor::visit(Type *type){ } 11 void CodeGenVisitor::visit(BasicType *basicType) { } 24 void CodeGenVisitor::visit( Type *type ){ } 25 void CodeGenVisitor::visit( BasicType *basicType ) { } 12 26 13 //*** Constant 14 void CodeGenVisitor::visit(Constant *constant) { 15 cout << constant->get_value() << endl; 27 void CodeGenVisitor::visit( Constant *constant ) { 28 cout << constant->get_value() << endl; 16 29 } 17 30 18 //*** Expressions 19 void CodeGenVisitor::visit(Expression *expr){ } 31 void CodeGenVisitor::visit( Expression *expr ){ } 20 32 21 void CodeGenVisitor::visit( ConstantExpr *cnst){22 if (cnst != 0)23 visit(cnst->get_constant());33 void CodeGenVisitor::visit( ConstantExpr *cnst ) { 34 if ( cnst != 0 ) 35 visit(cnst->get_constant()); 24 36 } 25 37 26 //*** Statements 27 void CodeGenVisitor::visit(Statement *stmt){ } 38 void CodeGenVisitor::visit( Statement *stmt ) { } 28 39 29 void CodeGenVisitor::visit( ExprStmt *exprStmt){30 if (exprStmt != 0)31 exprStmt->get_expr()->accept(*this);// visit(exprStmt->get_expr()) doesn't work40 void CodeGenVisitor::visit( ExprStmt *exprStmt ) { 41 if ( exprStmt != 0 ) 42 exprStmt->get_expr()->accept( *this ); // visit(exprStmt->get_expr()) doesn't work 32 43 } 33 44 34 void CodeGenVisitor::visit( SwitchStmt *switchStmt){35 cout << "switch (" << endl;36 // visit(switchStmt->get_condition()); // why doesn't this work?37 switchStmt->get_condition()->accept(*this);45 void CodeGenVisitor::visit( SwitchStmt *switchStmt ) { 46 cout << "switch (" << endl; 47 // visit(switchStmt->get_condition()); // why doesn't this work? 48 switchStmt->get_condition()->accept(*this); 38 49 39 cout << ") {" << endl;40 // visit(switchStmt->get_body()); // why doesn't this work?41 cout << "}" << endl;50 cout << ") {" << endl; 51 // visit(switchStmt->get_body()); // why doesn't this work? 52 cout << "}" << endl; 42 53 } 43 54 44 55 // Local Variables: // 56 // tab-width: 4 // 57 // mode: c++ // 58 // compile-command: "make install" // 59 // End: // -
translator/SynTree/CodeGenVisitor.h
ra32b204 r0dd3a2f 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 // CodeGenVisitor.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:47 2015 13 // Update Count : 4 14 // 15 1 16 #ifndef CODEGENV_H 2 17 #define CODEGENV_H … … 7 22 #include "Visitor.h" 8 23 24 class CodeGenVisitor : public Visitor { 25 public: 26 virtual void visit( Type * ); 27 virtual void visit( BasicType * ); 9 28 10 class CodeGenVisitor : public Visitor { 11 public: 12 //*** Types 13 virtual void visit(Type *); 14 virtual void visit(BasicType *); 29 virtual void visit( Constant * ); 15 30 16 //*** Constant 17 virtual void visit(Constant *);31 virtual void visit( Expression * ); 32 virtual void visit( ConstantExpr * ); 18 33 19 //*** Expressions 20 virtual void visit(Expression *); 21 virtual void visit(ConstantExpr *); 22 23 //*** Statements 24 virtual void visit(Statement *); 25 virtual void visit(ExprStmt *); 26 virtual void visit(SwitchStmt *); 34 virtual void visit( Statement * ); 35 virtual void visit( ExprStmt * ); 36 virtual void visit( SwitchStmt * ); 27 37 }; 28 38 39 #endif // CODEGENV_H 29 40 30 #endif /* #ifndef CODEGENV_H */ 41 // Local Variables: // 42 // tab-width: 4 // 43 // mode: c++ // 44 // compile-command: "make install" // 45 // End: // -
translator/SynTree/CommaExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: CommaExpr.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // CommaExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:09:58 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Expression.h" … … 10 18 #include "utility.h" 11 19 12 13 20 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname ) 14 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) 15 { 16 cloneAll( arg2->get_results(), get_results() ); 21 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) { 22 cloneAll( arg2->get_results(), get_results() ); 17 23 } 18 24 19 25 CommaExpr::CommaExpr( const CommaExpr &other ) 20 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ) 21 { 26 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ) { 22 27 } 23 28 24 CommaExpr::~CommaExpr() 25 { 26 delete arg1; 27 delete arg2; 29 CommaExpr::~CommaExpr() { 30 delete arg1; 31 delete arg2; 28 32 } 29 33 30 void 31 CommaExpr::print( std::ostream &os, int indent ) const 32 { 33 os << std::string( indent, ' ' ) << "Comma Expression:" << std::endl; 34 arg1->print( os, indent+2 ); 35 os << std::endl; 36 arg2->print( os, indent+2 ); 37 Expression::print( os, indent ); 34 void CommaExpr::print( std::ostream &os, int indent ) const { 35 os << std::string( indent, ' ' ) << "Comma Expression:" << std::endl; 36 arg1->print( os, indent+2 ); 37 os << std::endl; 38 arg2->print( os, indent+2 ); 39 Expression::print( os, indent ); 38 40 } 39 41 40 42 // Local Variables: // 43 // tab-width: 4 // 44 // mode: c++ // 45 // compile-command: "make install" // 46 // End: // -
translator/SynTree/CompoundStmt.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: CompoundStmt.cc,v 1.4 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:11:02 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Statement.h" … … 18 26 19 27 CompoundStmt::CompoundStmt( const CompoundStmt &other ) : Statement( other ) { 20 cloneAll( other.kids, kids );28 cloneAll( other.kids, kids ); 21 29 } 22 30 23 31 CompoundStmt::~CompoundStmt() { 24 deleteAll( kids );32 deleteAll( kids ); 25 33 } 26 34 27 35 void CompoundStmt::print( std::ostream &os, int indent ) { 28 os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ;29 printAll( kids, os, indent+2 );36 os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ; 37 printAll( kids, os, indent+2 ); 30 38 } 31 39 32 33 34 35 40 // Local Variables: // 41 // tab-width: 4 // 42 // mode: c++ // 43 // compile-command: "make install" // 44 // End: // -
translator/SynTree/Constant.cc
ra32b204 r0dd3a2f 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 // Constant.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:13:25 2015 13 // Update Count : 1 14 // 15 1 16 #include <iostream> 2 17 #include <list> … … 5 20 #include "Type.h" 6 21 7 8 Constant::Constant(Type *_type, std::string _value): 9 type(_type), value(_value) {} 22 Constant::Constant( Type *_type, std::string _value ) : type(_type), value(_value) {} 10 23 11 24 Constant::~Constant() {} … … 14 27 15 28 void Constant::print( std::ostream &os ) const { 16 os << value;17 if ( type ) {18 os << " (type: ";19 type->print( os );20 os << ")";21 } 29 os << value; 30 if ( type ) { 31 os << " (type: "; 32 type->print( os ); 33 os << ")"; 34 } // if 22 35 } 23 36 24 25 26 37 // Local Variables: // 38 // tab-width: 4 // 39 // mode: c++ // 40 // compile-command: "make install" // 41 // End: // -
translator/SynTree/Constant.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: Constant.h,v 1.6 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // Constant.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:37 2015 13 // Update Count : 2 14 // 7 15 8 16 #ifndef CONSTANT_H … … 13 21 #include "Mutator.h" 14 22 23 class Constant { 24 public: 25 Constant( Type *type, std::string value ); 26 virtual ~Constant(); 15 27 16 class Constant 17 { 18 public: 19 Constant( Type *type, std::string value ); 20 virtual ~Constant(); 28 Type *get_type() { return type; } 29 void set_type( Type *newValue ) { type = newValue; } 30 std::string get_value() { return value; } 31 void set_value( std::string newValue ) { value = newValue; } 21 32 22 Type *get_type() { return type; } 23 void set_type( Type *newValue ) { type = newValue; } 24 std::string get_value() { return value; } 25 void set_value( std::string newValue ) { value = newValue; } 26 27 virtual Constant *clone() const; 28 virtual void accept( Visitor &v ) { v.visit( this ); } 29 virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); } 30 virtual void print( std::ostream &os ) const; 31 32 private: 33 Type *type; 34 std::string value; 33 virtual Constant *clone() const; 34 virtual void accept( Visitor &v ) { v.visit( this ); } 35 virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); } 36 virtual void print( std::ostream &os ) const; 37 private: 38 Type *type; 39 std::string value; 35 40 }; 36 41 42 #endif // CONSTANT_H 37 43 38 39 40 #endif /* #ifndef CONSTANT_H */ 44 // Local Variables: // 45 // tab-width: 4 // 46 // mode: c++ // 47 // compile-command: "make install" // 48 // End: // -
translator/SynTree/DeclStmt.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: DeclStmt.cc,v 1.4 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // DeclStmt.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:16:03 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Statement.h" … … 10 18 #include "utility.h" 11 19 12 13 DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) 14 : Statement( labels ), decl( decl ) 15 { 20 DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) : Statement( labels ), decl( decl ) { 16 21 } 17 22 18 DeclStmt::DeclStmt( const DeclStmt &other ) 19 : Statement( other ), decl( maybeClone( other.decl ) ) 20 { 23 DeclStmt::DeclStmt( const DeclStmt &other ) : Statement( other ), decl( maybeClone( other.decl ) ) { 21 24 } 22 25 23 DeclStmt::~DeclStmt() 24 { 25 delete decl; 26 DeclStmt::~DeclStmt() { 27 delete decl; 26 28 } 27 29 28 void 29 DeclStmt::print( std::ostream &os, int indent ) 30 { 31 os << "Declaration of "; 32 if ( decl ) { 33 decl->print( os, indent ); 34 } 30 void DeclStmt::print( std::ostream &os, int indent ) { 31 os << "Declaration of "; 32 if ( decl ) { 33 decl->print( os, indent ); 34 } // if 35 35 } 36 36 37 37 // Local Variables: // 38 // tab-width: 4 // 39 // mode: c++ // 40 // compile-command: "make install" // 41 // End: // -
translator/SynTree/Declaration.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: Declaration.cc,v 1.8 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // Declaration.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:18:35 2015 13 // Update Count : 2 14 // 7 15 8 16 #include <string> … … 14 22 #include "utility.h" 15 23 16 17 24 const char* Declaration::storageClassName[] = { "", "auto", "static", "extern", "register" }; 18 25 … … 22 29 23 30 Declaration::Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ) 24 : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) 25 { 31 : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) { 26 32 } 27 33 28 34 Declaration::Declaration( const Declaration &other ) 29 : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) 30 { 35 : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) { 31 36 } 32 37 33 Declaration::~Declaration() 34 { 38 Declaration::~Declaration() { 35 39 } 36 40 37 void 38 Declaration::fixUniqueId() 39 { 40 uniqueId = ++lastUniqueId; 41 idMap[ uniqueId ] = this; 41 void Declaration::fixUniqueId() { 42 uniqueId = ++lastUniqueId; 43 idMap[ uniqueId ] = this; 42 44 } 43 45 44 46 /* static class method */ 45 Declaration * 46 Declaration::declFromId( UniqueId id ) 47 { 48 IdMapType::const_iterator i = idMap.find( id ); 49 if ( i != idMap.end() ) { 50 return i->second; 51 } else { 52 return 0; 53 } 47 Declaration *Declaration::declFromId( UniqueId id ) { 48 IdMapType::const_iterator i = idMap.find( id ); 49 if ( i != idMap.end() ) { 50 return i->second; 51 } else { 52 return 0; 53 } // if 54 54 } 55 55 56 56 /* static class method */ 57 void 58 Declaration::dumpIds( std::ostream &os ) 59 { 60 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) { 61 os << i->first << " -> "; 62 i->second->printShort( os ); 63 os << std::endl; 64 } 57 void Declaration::dumpIds( std::ostream &os ) { 58 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) { 59 os << i->first << " -> "; 60 i->second->printShort( os ); 61 os << std::endl; 62 } // for 65 63 } 66 64 65 // Local Variables: // 66 // tab-width: 4 // 67 // mode: c++ // 68 // compile-command: "make install" // 69 // End: // -
translator/SynTree/Declaration.h
ra32b204 r0dd3a2f 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 // Declaration.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:25 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef DECLARATION_H 2 17 #define DECLARATION_H … … 7 22 #include "Parser/LinkageSpec.h" 8 23 9 10 24 class Declaration { 11 25 public: 12 enum StorageClass {13 NoStorageClass,14 Extern,15 Static,16 Auto,17 Register,18 Inline,19 Fortran,20 };21 22 Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );23 Declaration( const Declaration &other );24 virtual ~Declaration();25 26 std::string get_name() const { return name; }27 void set_name( std::string newValue ) { name = newValue; }28 StorageClass get_storageClass() const { return storageClass; }29 void set_storageClass( StorageClass newValue ) { storageClass = newValue; }30 LinkageSpec::Type get_linkage() const { return linkage; }31 void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }32 UniqueId get_uniqueId() const { return uniqueId; }33 34 void fixUniqueId( void );35 virtual Declaration *clone() const = 0;36 virtual void accept( Visitor &v ) = 0;37 virtual Declaration *acceptMutator( Mutator &m ) = 0;38 virtual void print( std::ostream &os, int indent = 0 ) const = 0;39 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;40 41 static const char* storageClassName[];42 43 static void dumpIds( std::ostream &os );44 static Declaration *declFromId( UniqueId id );45 private: 46 std::string name;47 StorageClass storageClass;48 LinkageSpec::Type linkage;49 UniqueId uniqueId;26 enum StorageClass { 27 NoStorageClass, 28 Extern, 29 Static, 30 Auto, 31 Register, 32 Inline, 33 Fortran, 34 }; 35 36 Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); 37 Declaration( const Declaration &other ); 38 virtual ~Declaration(); 39 40 std::string get_name() const { return name; } 41 void set_name( std::string newValue ) { name = newValue; } 42 StorageClass get_storageClass() const { return storageClass; } 43 void set_storageClass( StorageClass newValue ) { storageClass = newValue; } 44 LinkageSpec::Type get_linkage() const { return linkage; } 45 void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; } 46 UniqueId get_uniqueId() const { return uniqueId; } 47 48 void fixUniqueId( void ); 49 virtual Declaration *clone() const = 0; 50 virtual void accept( Visitor &v ) = 0; 51 virtual Declaration *acceptMutator( Mutator &m ) = 0; 52 virtual void print( std::ostream &os, int indent = 0 ) const = 0; 53 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0; 54 55 static const char* storageClassName[]; 56 57 static void dumpIds( std::ostream &os ); 58 static Declaration *declFromId( UniqueId id ); 59 private: 60 std::string name; 61 StorageClass storageClass; 62 LinkageSpec::Type linkage; 63 UniqueId uniqueId; 50 64 }; 51 65 52 66 class DeclarationWithType : public Declaration { 53 67 public: 54 DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );55 DeclarationWithType( const DeclarationWithType &other );56 virtual ~DeclarationWithType();57 58 std::string get_mangleName() const { return mangleName; }59 void set_mangleName( std::string newValue ) { mangleName = newValue; }60 61 virtual DeclarationWithType *clone() const = 0;62 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;63 64 virtual Type *get_type() const = 0;65 virtual void set_type(Type *) = 0;66 private: 67 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass268 std::string mangleName;68 DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); 69 DeclarationWithType( const DeclarationWithType &other ); 70 virtual ~DeclarationWithType(); 71 72 std::string get_mangleName() const { return mangleName; } 73 void set_mangleName( std::string newValue ) { mangleName = newValue; } 74 75 virtual DeclarationWithType *clone() const = 0; 76 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; 77 78 virtual Type *get_type() const = 0; 79 virtual void set_type(Type *) = 0; 80 private: 81 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2 82 std::string mangleName; 69 83 }; 70 84 71 85 class ObjectDecl : public DeclarationWithType { 72 typedef DeclarationWithType Parent;73 public: 74 ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init );75 ObjectDecl( const ObjectDecl &other );76 virtual ~ObjectDecl();77 78 virtual Type *get_type() const { return type; }79 virtual void set_type(Type *newType) { type = newType; }80 81 Initializer *get_init() const { return init; }82 void set_init( Initializer *newValue ) { init = newValue; }83 Expression *get_bitfieldWidth() const { return bitfieldWidth; }84 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }85 86 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }87 virtual void accept( Visitor &v ) { v.visit( this ); }88 virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }89 virtual void print( std::ostream &os, int indent = 0 ) const;90 virtual void printShort( std::ostream &os, int indent = 0 ) const;91 private: 92 Type *type;93 Initializer *init;94 Expression *bitfieldWidth;86 typedef DeclarationWithType Parent; 87 public: 88 ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ); 89 ObjectDecl( const ObjectDecl &other ); 90 virtual ~ObjectDecl(); 91 92 virtual Type *get_type() const { return type; } 93 virtual void set_type(Type *newType) { type = newType; } 94 95 Initializer *get_init() const { return init; } 96 void set_init( Initializer *newValue ) { init = newValue; } 97 Expression *get_bitfieldWidth() const { return bitfieldWidth; } 98 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; } 99 100 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } 101 virtual void accept( Visitor &v ) { v.visit( this ); } 102 virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } 103 virtual void print( std::ostream &os, int indent = 0 ) const; 104 virtual void printShort( std::ostream &os, int indent = 0 ) const; 105 private: 106 Type *type; 107 Initializer *init; 108 Expression *bitfieldWidth; 95 109 }; 96 110 97 111 class FunctionDecl : public DeclarationWithType { 98 typedef DeclarationWithType Parent;99 public: 100 FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline );101 FunctionDecl( const FunctionDecl &other );102 virtual ~FunctionDecl();103 104 Type *get_type() const;105 virtual void set_type(Type *);106 107 FunctionType *get_functionType() const { return type; }108 void set_functionType( FunctionType *newValue ) { type = newValue; }109 CompoundStmt *get_statements() const { return statements; }110 void set_statements( CompoundStmt *newValue ) { statements = newValue; }112 typedef DeclarationWithType Parent; 113 public: 114 FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ); 115 FunctionDecl( const FunctionDecl &other ); 116 virtual ~FunctionDecl(); 117 118 Type *get_type() const; 119 virtual void set_type(Type *); 120 121 FunctionType *get_functionType() const { return type; } 122 void set_functionType( FunctionType *newValue ) { type = newValue; } 123 CompoundStmt *get_statements() const { return statements; } 124 void set_statements( CompoundStmt *newValue ) { statements = newValue; } 111 125 // bool get_isInline() const { return isInline; } 112 126 // void set_isInline( bool newValue ) { isInline = newValue; } 113 std::list< std::string >& get_oldIdents() { return oldIdents; }114 std::list< Declaration* >& get_oldDecls() { return oldDecls; }115 116 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }117 virtual void accept( Visitor &v ) { v.visit( this ); }118 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }119 virtual void print( std::ostream &os, int indent = 0 ) const;120 virtual void printShort( std::ostream &os, int indent = 0 ) const;121 private: 122 FunctionType *type;123 CompoundStmt *statements;124 bool isInline;125 std::list< std::string > oldIdents;126 std::list< Declaration* > oldDecls;127 std::list< std::string >& get_oldIdents() { return oldIdents; } 128 std::list< Declaration* >& get_oldDecls() { return oldDecls; } 129 130 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } 131 virtual void accept( Visitor &v ) { v.visit( this ); } 132 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); } 133 virtual void print( std::ostream &os, int indent = 0 ) const; 134 virtual void printShort( std::ostream &os, int indent = 0 ) const; 135 private: 136 FunctionType *type; 137 CompoundStmt *statements; 138 bool isInline; 139 std::list< std::string > oldIdents; 140 std::list< Declaration* > oldDecls; 127 141 }; 128 142 129 143 class NamedTypeDecl : public Declaration { 130 typedef Declaration Parent;131 public: 132 NamedTypeDecl( const std::string &name, StorageClass sc, Type *type );133 NamedTypeDecl( const TypeDecl &other );134 virtual ~NamedTypeDecl();135 136 Type *get_base() const { return base; }137 void set_base( Type *newValue ) { base = newValue; }138 std::list< TypeDecl* >& get_parameters() { return parameters; }139 std::list< DeclarationWithType* >& get_assertions() { return assertions; }140 141 virtual NamedTypeDecl *clone() const = 0;142 virtual void print( std::ostream &os, int indent = 0 ) const;143 virtual void printShort( std::ostream &os, int indent = 0 ) const;144 typedef Declaration Parent; 145 public: 146 NamedTypeDecl( const std::string &name, StorageClass sc, Type *type ); 147 NamedTypeDecl( const TypeDecl &other ); 148 virtual ~NamedTypeDecl(); 149 150 Type *get_base() const { return base; } 151 void set_base( Type *newValue ) { base = newValue; } 152 std::list< TypeDecl* >& get_parameters() { return parameters; } 153 std::list< DeclarationWithType* >& get_assertions() { return assertions; } 154 155 virtual NamedTypeDecl *clone() const = 0; 156 virtual void print( std::ostream &os, int indent = 0 ) const; 157 virtual void printShort( std::ostream &os, int indent = 0 ) const; 144 158 protected: 145 virtual std::string typeString() const = 0;146 private: 147 Type *base;148 std::list< TypeDecl* > parameters;149 std::list< DeclarationWithType* > assertions;159 virtual std::string typeString() const = 0; 160 private: 161 Type *base; 162 std::list< TypeDecl* > parameters; 163 std::list< DeclarationWithType* > assertions; 150 164 }; 151 165 152 166 class TypeDecl : public NamedTypeDecl { 153 typedef NamedTypeDecl Parent;154 public: 155 enum Kind { Any, Dtype, Ftype };156 157 TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind );158 TypeDecl( const TypeDecl &other );159 160 Kind get_kind() const { return kind; }161 162 virtual TypeDecl *clone() const { return new TypeDecl( *this ); }163 virtual void accept( Visitor &v ) { v.visit( this ); }164 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }165 private: 166 virtual std::string typeString() const;167 Kind kind;167 typedef NamedTypeDecl Parent; 168 public: 169 enum Kind { Any, Dtype, Ftype }; 170 171 TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ); 172 TypeDecl( const TypeDecl &other ); 173 174 Kind get_kind() const { return kind; } 175 176 virtual TypeDecl *clone() const { return new TypeDecl( *this ); } 177 virtual void accept( Visitor &v ) { v.visit( this ); } 178 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } 179 private: 180 virtual std::string typeString() const; 181 Kind kind; 168 182 }; 169 183 170 184 class TypedefDecl : public NamedTypeDecl { 171 typedef NamedTypeDecl Parent;172 public: 173 TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {}174 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}175 176 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }177 virtual void accept( Visitor &v ) { v.visit( this ); }178 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }179 private: 180 virtual std::string typeString() const;185 typedef NamedTypeDecl Parent; 186 public: 187 TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {} 188 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} 189 190 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); } 191 virtual void accept( Visitor &v ) { v.visit( this ); } 192 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 193 private: 194 virtual std::string typeString() const; 181 195 }; 182 196 183 197 class AggregateDecl : public Declaration { 184 typedef Declaration Parent;185 public: 186 AggregateDecl( const std::string &name );187 AggregateDecl( const AggregateDecl &other );188 virtual ~AggregateDecl();189 190 std::list<Declaration*>& get_members() { return members; }191 std::list<TypeDecl*>& get_parameters() { return parameters; }192 193 virtual void print( std::ostream &os, int indent = 0 ) const;194 virtual void printShort( std::ostream &os, int indent = 0 ) const;198 typedef Declaration Parent; 199 public: 200 AggregateDecl( const std::string &name ); 201 AggregateDecl( const AggregateDecl &other ); 202 virtual ~AggregateDecl(); 203 204 std::list<Declaration*>& get_members() { return members; } 205 std::list<TypeDecl*>& get_parameters() { return parameters; } 206 207 virtual void print( std::ostream &os, int indent = 0 ) const; 208 virtual void printShort( std::ostream &os, int indent = 0 ) const; 195 209 protected: 196 virtual std::string typeString() const = 0;197 198 private: 199 std::list<Declaration*> members;200 std::list<TypeDecl*> parameters;210 virtual std::string typeString() const = 0; 211 212 private: 213 std::list<Declaration*> members; 214 std::list<TypeDecl*> parameters; 201 215 }; 202 216 203 217 class StructDecl : public AggregateDecl { 204 typedef AggregateDecl Parent;205 public: 206 StructDecl( const std::string &name ) : Parent( name ) {}207 StructDecl( const StructDecl &other ) : Parent( other ) {}208 209 virtual StructDecl *clone() const { return new StructDecl( *this ); }210 virtual void accept( Visitor &v ) { v.visit( this ); }211 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }212 213 private: 214 virtual std::string typeString() const;218 typedef AggregateDecl Parent; 219 public: 220 StructDecl( const std::string &name ) : Parent( name ) {} 221 StructDecl( const StructDecl &other ) : Parent( other ) {} 222 223 virtual StructDecl *clone() const { return new StructDecl( *this ); } 224 virtual void accept( Visitor &v ) { v.visit( this ); } 225 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 226 227 private: 228 virtual std::string typeString() const; 215 229 }; 216 230 217 231 class UnionDecl : public AggregateDecl { 218 typedef AggregateDecl Parent;219 public: 220 UnionDecl( const std::string &name ) : Parent( name ) {}221 UnionDecl( const UnionDecl &other ) : Parent( other ) {}222 223 virtual UnionDecl *clone() const { return new UnionDecl( *this ); }224 virtual void accept( Visitor &v ) { v.visit( this ); }225 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }226 private: 227 virtual std::string typeString() const;232 typedef AggregateDecl Parent; 233 public: 234 UnionDecl( const std::string &name ) : Parent( name ) {} 235 UnionDecl( const UnionDecl &other ) : Parent( other ) {} 236 237 virtual UnionDecl *clone() const { return new UnionDecl( *this ); } 238 virtual void accept( Visitor &v ) { v.visit( this ); } 239 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 240 private: 241 virtual std::string typeString() const; 228 242 }; 229 243 230 244 class EnumDecl : public AggregateDecl { 231 typedef AggregateDecl Parent;232 public: 233 EnumDecl( const std::string &name ) : Parent( name ) {}234 EnumDecl( const EnumDecl &other ) : Parent( other ) {}235 236 virtual EnumDecl *clone() const { return new EnumDecl( *this ); }237 virtual void accept( Visitor &v ) { v.visit( this ); }238 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }239 private: 240 virtual std::string typeString() const;245 typedef AggregateDecl Parent; 246 public: 247 EnumDecl( const std::string &name ) : Parent( name ) {} 248 EnumDecl( const EnumDecl &other ) : Parent( other ) {} 249 250 virtual EnumDecl *clone() const { return new EnumDecl( *this ); } 251 virtual void accept( Visitor &v ) { v.visit( this ); } 252 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 253 private: 254 virtual std::string typeString() const; 241 255 }; 242 256 243 257 class ContextDecl : public AggregateDecl { 244 typedef AggregateDecl Parent;245 public: 246 ContextDecl( const std::string &name ) : Parent( name ) {}247 ContextDecl( const ContextDecl &other ) : Parent( other ) {}248 249 virtual ContextDecl *clone() const { return new ContextDecl( *this ); }250 virtual void accept( Visitor &v ) { v.visit( this ); }251 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }252 private: 253 virtual std::string typeString() const;258 typedef AggregateDecl Parent; 259 public: 260 ContextDecl( const std::string &name ) : Parent( name ) {} 261 ContextDecl( const ContextDecl &other ) : Parent( other ) {} 262 263 virtual ContextDecl *clone() const { return new ContextDecl( *this ); } 264 virtual void accept( Visitor &v ) { v.visit( this ); } 265 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 266 private: 267 virtual std::string typeString() const; 254 268 }; 255 269 256 270 #endif // DECLARATION_H 271 272 // Local Variables: // 273 // tab-width: 4 // 274 // mode: c++ // 275 // compile-command: "make install" // 276 // End: // -
translator/SynTree/DeclarationWithType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: DeclarationWithType.cc,v 1.9 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // DeclarationWithType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:20:23 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Declaration.h" … … 10 18 #include "utility.h" 11 19 12 13 20 DeclarationWithType::DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ) 14 : Declaration( name, sc, linkage ) 15 { 21 : Declaration( name, sc, linkage ) { 16 22 } 17 23 18 24 DeclarationWithType::DeclarationWithType( const DeclarationWithType &other ) 19 : Declaration( other ), mangleName( other.mangleName ) 20 { 25 : Declaration( other ), mangleName( other.mangleName ) { 21 26 } 22 27 23 DeclarationWithType::~DeclarationWithType() 24 { 28 DeclarationWithType::~DeclarationWithType() { 25 29 } 26 30 31 // Local Variables: // 32 // tab-width: 4 // 33 // mode: c++ // 34 // compile-command: "make install" // 35 // End: // -
translator/SynTree/Expression.cc
ra32b204 r0dd3a2f 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 // Expression.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:27:07 2015 13 // Update Count : 2 14 // 15 1 16 #include <iostream> 2 17 #include <cassert> … … 14 29 15 30 16 //*** Expression17 31 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {} 18 Expression::Expression( const Expression &other ) 19 : env( maybeClone( other.env ) ) 20 { 21 cloneAll( other.results, results ); 22 argName = other.get_argName(); 23 } 24 Expression::~Expression() 25 { 26 delete env; 27 // delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 28 deleteAll( results ); 29 } 30 31 void 32 Expression::add_result( Type *t ) 33 { 34 if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { 35 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); 36 } else { 37 results.push_back(t); 38 } 32 33 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ) { 34 cloneAll( other.results, results ); 35 argName = other.get_argName(); 36 } 37 38 Expression::~Expression() { 39 delete env; 40 // delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 41 deleteAll( results ); 42 } 43 44 void Expression::add_result( Type *t ) { 45 if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { 46 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); 47 } else { 48 results.push_back(t); 49 } // if 39 50 } 40 51 41 52 void Expression::print(std::ostream &os, int indent) const { 42 if ( env ) { 43 os << std::string(indent, ' ') << "with environment:" << std::endl; 44 env->print( os, indent+2 ); 45 } 46 47 if ( argName ) { 48 os << std::string(indent, ' ') << "with designator:"; 49 argName->print( os, indent+2 ); 50 } 51 } 52 53 //*** ConstantExpr 54 ConstantExpr::ConstantExpr(Constant _c, Expression *_aname ): 55 Expression( _aname ), constant(_c) 56 { 57 add_result( constant.get_type()->clone() ); 58 } 59 60 ConstantExpr::ConstantExpr( const ConstantExpr &other) 61 : Expression( other ), constant( other.constant ) 62 {} 53 if ( env ) { 54 os << std::string(indent, ' ') << "with environment:" << std::endl; 55 env->print( os, indent+2 ); 56 } // if 57 58 if ( argName ) { 59 os << std::string(indent, ' ') << "with designator:"; 60 argName->print( os, indent+2 ); 61 } // if 62 } 63 64 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { 65 add_result( constant.get_type()->clone() ); 66 } 67 68 ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { 69 } 63 70 64 71 ConstantExpr::~ConstantExpr() {} 65 72 66 void ConstantExpr::print(std::ostream &os, int indent) const { 67 os << std::string(indent, ' ') << "Constant Expression: " ; 68 constant.print(os); 69 os << std::endl; 70 Expression::print( os, indent ); 71 } 72 73 //*** VariableExpr 74 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) 75 { 76 add_result( var->get_type()->clone() ); 77 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 78 (*i)->set_isLvalue( true ); 79 } 80 } 81 82 VariableExpr::VariableExpr( const VariableExpr &other ) 83 : Expression( other ), var( other.var ) 84 { 85 } 86 87 VariableExpr::~VariableExpr() 88 { 89 // don't delete the declaration, since it points somewhere else in the tree 90 } 91 92 void VariableExpr::print(std::ostream &os, int indent) const { 93 os << std::string(indent, ' ') << "Variable Expression: "; 94 95 Declaration *decl = get_var(); 96 // if ( decl != 0) decl->print(os, indent + 2); 97 if ( decl != 0) decl->printShort(os, indent + 2); 98 os << std::endl; 99 Expression::print( os, indent ); 100 } 101 102 //*** SizeofExpr 73 void ConstantExpr::print( std::ostream &os, int indent ) const { 74 os << std::string(indent, ' ') << "Constant Expression: " ; 75 constant.print(os); 76 os << std::endl; 77 Expression::print( os, indent ); 78 } 79 80 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) { 81 add_result( var->get_type()->clone() ); 82 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 83 (*i)->set_isLvalue( true ); 84 } // for 85 } 86 87 VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) { 88 } 89 90 VariableExpr::~VariableExpr() { 91 // don't delete the declaration, since it points somewhere else in the tree 92 } 93 94 void VariableExpr::print( std::ostream &os, int indent ) const { 95 os << std::string(indent, ' ') << "Variable Expression: "; 96 97 Declaration *decl = get_var(); 98 // if ( decl != 0) decl->print(os, indent + 2); 99 if ( decl != 0) decl->printShort(os, indent + 2); 100 os << std::endl; 101 Expression::print( os, indent ); 102 } 103 103 104 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : 104 Expression( _aname ), expr(expr_), type(0), isType(false) 105 { 106 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 105 Expression( _aname ), expr(expr_), type(0), isType(false) { 106 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 107 107 } 108 108 109 109 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : 110 Expression( _aname ), expr(0), type(type_), isType(true) 111 { 112 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 113 } 114 115 SizeofExpr::SizeofExpr( const SizeofExpr &other ) 116 : Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) 117 { 118 } 119 120 SizeofExpr::~SizeofExpr(){ 121 delete expr; 122 delete type; 110 Expression( _aname ), expr(0), type(type_), isType(true) { 111 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 112 } 113 114 SizeofExpr::SizeofExpr( const SizeofExpr &other ) : 115 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 116 } 117 118 SizeofExpr::~SizeofExpr() { 119 delete expr; 120 delete type; 123 121 } 124 122 125 123 void SizeofExpr::print( std::ostream &os, int indent) const { 126 os << std::string(indent, ' ') << "Sizeof Expression on: "; 127 128 if (isType) 129 type->print(os, indent + 2); 130 else 131 expr->print(os, indent + 2); 132 133 os << std::endl; 134 Expression::print( os, indent ); 135 } 136 137 //*** AttrExpr 124 os << std::string(indent, ' ') << "Sizeof Expression on: "; 125 126 if (isType) 127 type->print(os, indent + 2); 128 else 129 expr->print(os, indent + 2); 130 131 os << std::endl; 132 Expression::print( os, indent ); 133 } 134 138 135 AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) : 139 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) 140 { 136 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) { 141 137 } 142 138 143 139 AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) : 144 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) 145 { 146 } 147 148 AttrExpr::AttrExpr( const AttrExpr &other ) 149 : Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) 150 { 151 } 152 153 AttrExpr::~AttrExpr(){ 154 delete attr; 155 delete expr; 156 delete type; 140 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) { 141 } 142 143 AttrExpr::AttrExpr( const AttrExpr &other ) : 144 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 145 } 146 147 AttrExpr::~AttrExpr() { 148 delete attr; 149 delete expr; 150 delete type; 157 151 } 158 152 159 153 void AttrExpr::print( std::ostream &os, int indent) const { 160 os << std::string(indent, ' ') << "Attr "; 161 attr->print( os, indent + 2 ); 162 if ( isType || expr ) { 163 os << "applied to: "; 164 165 if (isType) 166 type->print(os, indent + 2); 167 else 168 expr->print(os, indent + 2); 169 } 170 171 os << std::endl; 172 Expression::print( os, indent ); 173 } 174 175 //*** CastExpr 176 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) 177 { 178 add_result(toType); 154 os << std::string(indent, ' ') << "Attr "; 155 attr->print( os, indent + 2 ); 156 if ( isType || expr ) { 157 os << "applied to: "; 158 159 if (isType) 160 type->print(os, indent + 2); 161 else 162 expr->print(os, indent + 2); 163 } // if 164 165 os << std::endl; 166 Expression::print( os, indent ); 167 } 168 169 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { 170 add_result(toType); 179 171 } 180 172 … … 182 174 } 183 175 184 CastExpr::CastExpr( const CastExpr &other ) 185 : Expression( other ), arg( maybeClone( other.arg ) ) 186 { 176 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 187 177 } 188 178 189 179 CastExpr::~CastExpr() { 190 delete arg;180 delete arg; 191 181 } 192 182 … … 194 184 195 185 void CastExpr::print( std::ostream &os, int indent ) const { 196 os << std::string(indent, ' ') << "Cast of:" << std::endl; 197 arg->print(os, indent+2); 198 os << std::endl << std::string(indent, ' ') << "to:" << std::endl; 199 if ( results.empty() ) { 200 os << std::string(indent+2, ' ') << "nothing" << std::endl; 201 } else { 202 printAll(results, os, indent+2); 203 } 204 Expression::print( os, indent ); 205 } 206 207 //*** UntypedMemberExpr 186 os << std::string(indent, ' ') << "Cast of:" << std::endl; 187 arg->print(os, indent+2); 188 os << std::endl << std::string(indent, ' ') << "to:" << std::endl; 189 if ( results.empty() ) { 190 os << std::string(indent+2, ' ') << "nothing" << std::endl; 191 } else { 192 printAll(results, os, indent+2); 193 } // if 194 Expression::print( os, indent ); 195 } 196 208 197 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : 209 Expression( _aname ), member(_member), aggregate(_aggregate) {} 210 211 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) 212 : Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) 213 { 198 Expression( _aname ), member(_member), aggregate(_aggregate) {} 199 200 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : 201 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { 214 202 } 215 203 216 204 UntypedMemberExpr::~UntypedMemberExpr() { 217 delete aggregate;205 delete aggregate; 218 206 } 219 207 220 208 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 221 os << std::string(indent, ' ') << "Member Expression, with field: " << get_member(); 222 223 Expression *agg = get_aggregate(); 224 os << std::string(indent, ' ') << "from aggregate: "; 225 if (agg != 0) agg->print(os, indent + 2); 226 Expression::print( os, indent ); 227 } 228 229 230 //*** MemberExpr 209 os << std::string(indent, ' ') << "Member Expression, with field: " << get_member(); 210 211 Expression *agg = get_aggregate(); 212 os << std::string(indent, ' ') << "from aggregate: "; 213 if (agg != 0) agg->print(os, indent + 2); 214 Expression::print( os, indent ); 215 } 216 217 231 218 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 232 Expression( _aname ), member(_member), aggregate(_aggregate) 233 { 234 add_result( member->get_type()->clone() ); 235 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 236 (*i)->set_isLvalue( true ); 237 } 238 } 239 240 MemberExpr::MemberExpr( const MemberExpr &other ) 241 : Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) 242 { 219 Expression( _aname ), member(_member), aggregate(_aggregate) { 220 add_result( member->get_type()->clone() ); 221 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 222 (*i)->set_isLvalue( true ); 223 } // for 224 } 225 226 MemberExpr::MemberExpr( const MemberExpr &other ) : 227 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 243 228 } 244 229 245 230 MemberExpr::~MemberExpr() { 246 delete member;247 delete aggregate;231 delete member; 232 delete aggregate; 248 233 } 249 234 250 235 void MemberExpr::print( std::ostream &os, int indent ) const { 251 os << std::string(indent, ' ') << "Member Expression, with field: " << std::endl; 252 253 assert( member ); 254 os << std::string(indent + 2, ' '); 255 member->print( os, indent + 2 ); 256 os << std::endl; 257 258 Expression *agg = get_aggregate(); 259 os << std::string(indent, ' ') << "from aggregate: " << std::endl; 260 if (agg != 0) agg->print(os, indent + 2); 261 Expression::print( os, indent ); 262 } 263 264 265 //*** UntypedExpr 236 os << std::string(indent, ' ') << "Member Expression, with field: " << std::endl; 237 238 assert( member ); 239 os << std::string(indent + 2, ' '); 240 member->print( os, indent + 2 ); 241 os << std::endl; 242 243 Expression *agg = get_aggregate(); 244 os << std::string(indent, ' ') << "from aggregate: " << std::endl; 245 if (agg != 0) agg->print(os, indent + 2); 246 Expression::print( os, indent ); 247 } 248 249 266 250 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {} 267 251 268 UntypedExpr::UntypedExpr( const UntypedExpr &other ) 269 : Expression( other ), function( maybeClone( other.function ) ) 270 { 271 cloneAll( other.args, args ); 252 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : 253 Expression( other ), function( maybeClone( other.function ) ) { 254 cloneAll( other.args, args ); 272 255 } 273 256 274 257 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) : 275 Expression( _aname ), function(_function), args(_args) {}258 Expression( _aname ), function(_function), args(_args) {} 276 259 277 260 UntypedExpr::~UntypedExpr() {} 278 261 279 262 void UntypedExpr::print( std::ostream &os, int indent ) const { 280 os << std::string(indent, ' ') << "Applying untyped: " << std::endl; 281 function->print(os, indent + 4); 282 os << "\r" << std::string(indent, ' ') << "...to: " << std::endl; 283 printArgs(os, indent + 4); 284 Expression::print( os, indent ); 285 } 286 287 void UntypedExpr::printArgs(std::ostream &os, int indent ) const { 288 std::list<Expression *>::const_iterator i; 289 for (i = args.begin(); i != args.end(); i++) 290 (*i)->print(os, indent); 291 } 292 293 //*** NameExpr 263 os << std::string(indent, ' ') << "Applying untyped: " << std::endl; 264 function->print(os, indent + 4); 265 os << "\r" << std::string(indent, ' ') << "...to: " << std::endl; 266 printArgs(os, indent + 4); 267 Expression::print( os, indent ); 268 } 269 270 void UntypedExpr::printArgs( std::ostream &os, int indent ) const { 271 std::list<Expression *>::const_iterator i; 272 for (i = args.begin(); i != args.end(); i++) 273 (*i)->print(os, indent); 274 } 275 294 276 NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {} 295 277 296 NameExpr::NameExpr( const NameExpr &other ) 297 : Expression( other ), name( other.name ) 298 { 278 NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) { 299 279 } 300 280 … … 302 282 303 283 void NameExpr::print( std::ostream &os, int indent ) const { 304 os << std::string(indent, ' ') << "Name: " << get_name() << std::endl; 305 Expression::print( os, indent ); 306 } 307 308 //*** LogicalExpr 284 os << std::string(indent, ' ') << "Name: " << get_name() << std::endl; 285 Expression::print( os, indent ); 286 } 287 309 288 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : 310 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) 311 { 312 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 313 } 314 315 LogicalExpr::LogicalExpr( const LogicalExpr &other ) 316 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) 317 { 289 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { 290 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 291 } 292 293 LogicalExpr::LogicalExpr( const LogicalExpr &other ) : 294 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { 318 295 } 319 296 320 297 LogicalExpr::~LogicalExpr(){ 321 delete arg1;322 delete arg2;298 delete arg1; 299 delete arg2; 323 300 } 324 301 325 302 void LogicalExpr::print( std::ostream &os, int indent )const { 326 os << std::string(indent, ' ') << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 327 arg1->print(os); 328 os << " and "; 329 arg2->print(os); 330 os << std::endl; 331 Expression::print( os, indent ); 332 } 333 334 //*** ConditionalExpr 303 os << std::string(indent, ' ') << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 304 arg1->print(os); 305 os << " and "; 306 arg2->print(os); 307 os << std::endl; 308 Expression::print( os, indent ); 309 } 310 335 311 ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) : 336 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} 337 338 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) 339 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) 340 { 341 } 312 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} 313 314 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : 315 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { 316 } 342 317 343 318 ConditionalExpr::~ConditionalExpr() { 344 delete arg1;345 delete arg2;346 delete arg3;319 delete arg1; 320 delete arg2; 321 delete arg3; 347 322 } 348 323 349 324 void ConditionalExpr::print( std::ostream &os, int indent ) const { 350 os << std::string(indent, ' ') << "Conditional expression on: " << std::endl; 351 arg1->print( os, indent+2 ); 352 os << std::string(indent, ' ') << "First alternative:" << std::endl; 353 arg2->print( os, indent+2 ); 354 os << std::string(indent, ' ') << "Second alternative:" << std::endl; 355 arg3->print( os, indent+2 ); 356 os << std::endl; 357 Expression::print( os, indent ); 358 } 359 360 //*** UntypedValofExpr 361 void UntypedValofExpr::print( std::ostream &os, int indent ) const 362 { 363 os << std::string(indent, ' ') << "Valof Expression: " << std::endl; 364 if ( get_body() != 0 ) 365 get_body()->print( os, indent + 2 ); 366 } 367 368 325 os << std::string(indent, ' ') << "Conditional expression on: " << std::endl; 326 arg1->print( os, indent+2 ); 327 os << std::string(indent, ' ') << "First alternative:" << std::endl; 328 arg2->print( os, indent+2 ); 329 os << std::string(indent, ' ') << "Second alternative:" << std::endl; 330 arg3->print( os, indent+2 ); 331 os << std::endl; 332 Expression::print( os, indent ); 333 } 334 335 void UntypedValofExpr::print( std::ostream &os, int indent ) const { 336 os << std::string(indent, ' ') << "Valof Expression: " << std::endl; 337 if ( get_body() != 0 ) 338 get_body()->print( os, indent + 2 ); 339 } 340 341 // Local Variables: // 342 // tab-width: 4 // 343 // mode: c++ // 344 // compile-command: "make install" // 345 // End: // -
translator/SynTree/Expression.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: Expression.h,v 1.31 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 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 // Expression.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:15 2015 13 // Update Count : 3 14 // 7 15 8 16 #ifndef EXPRESSION_H … … 15 23 #include "Constant.h" 16 24 17 18 class Expression 19 { 20 public: 21 Expression(Expression *_aname = 0 ); 22 Expression( const Expression &other ); 23 virtual ~Expression(); 24 25 std::list<Type *>& get_results() { return results; } 26 void add_result(Type *t); 27 28 TypeSubstitution *get_env() const { return env; } 29 void set_env( TypeSubstitution *newValue ) { env = newValue; } 30 Expression *get_argName() const { return argName; } 31 void set_argName( Expression *name ) { argName = name; } 32 33 virtual Expression *clone() const = 0; 34 virtual void accept( Visitor &v ) = 0; 35 virtual Expression *acceptMutator( Mutator &m ) = 0; 36 virtual void print( std::ostream &os, int indent = 0 ) const; 37 38 protected: 39 std::list<Type *> results; 40 TypeSubstitution *env; 41 Expression* argName; // if expression is used as an argument, it can be "designated" by this name 25 class Expression { 26 public: 27 Expression(Expression *_aname = 0 ); 28 Expression( const Expression &other ); 29 virtual ~Expression(); 30 31 std::list<Type *>& get_results() { return results; } 32 void add_result(Type *t); 33 34 TypeSubstitution *get_env() const { return env; } 35 void set_env( TypeSubstitution *newValue ) { env = newValue; } 36 Expression *get_argName() const { return argName; } 37 void set_argName( Expression *name ) { argName = name; } 38 39 virtual Expression *clone() const = 0; 40 virtual void accept( Visitor &v ) = 0; 41 virtual Expression *acceptMutator( Mutator &m ) = 0; 42 virtual void print( std::ostream &os, int indent = 0 ) const; 43 protected: 44 std::list<Type *> results; 45 TypeSubstitution *env; 46 Expression* argName; // if expression is used as an argument, it can be "designated" by this name 42 47 }; 43 48 44 49 // ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, 45 50 // but subject to decay-to-pointer and type parameter renaming 46 struct ParamEntry 47 {48 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}49 ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}50 ParamEntry( const ParamEntry &other );51 ~ParamEntry();52 ParamEntry &operator=( const ParamEntry &other );53 54 UniqueId decl;55 Type *actualType;56 Type *formalType;57 Expression* expr;51 52 struct ParamEntry { 53 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {} 54 ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {} 55 ParamEntry( const ParamEntry &other ); 56 ~ParamEntry(); 57 ParamEntry &operator=( const ParamEntry &other ); 58 59 UniqueId decl; 60 Type *actualType; 61 Type *formalType; 62 Expression* expr; 58 63 }; 59 64 … … 62 67 // ApplicationExpr represents the application of a function to a set of parameters. This is the 63 68 // result of running an UntypedExpr through the expression analyzer. 64 class ApplicationExpr : public Expression 65 { 66 public: 67 ApplicationExpr( Expression *function ); 68 ApplicationExpr( const ApplicationExpr &other ); 69 virtual ~ApplicationExpr(); 70 71 Expression *get_function() const { return function; } 72 void set_function( Expression *newValue ) { function = newValue; } 73 std::list<Expression *>& get_args() { return args; } 74 InferredParams &get_inferParams() { return inferParams; } 75 76 virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); } 77 virtual void accept( Visitor &v ) { v.visit( this ); } 78 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 79 virtual void print( std::ostream &os, int indent = 0 ) const; 80 81 private: 82 Expression *function; 83 std::list<Expression *> args; 84 InferredParams inferParams; 69 70 class ApplicationExpr : public Expression { 71 public: 72 ApplicationExpr( Expression *function ); 73 ApplicationExpr( const ApplicationExpr &other ); 74 virtual ~ApplicationExpr(); 75 76 Expression *get_function() const { return function; } 77 void set_function( Expression *newValue ) { function = newValue; } 78 std::list<Expression *>& get_args() { return args; } 79 InferredParams &get_inferParams() { return inferParams; } 80 81 virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); } 82 virtual void accept( Visitor &v ) { v.visit( this ); } 83 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 84 virtual void print( std::ostream &os, int indent = 0 ) const; 85 private: 86 Expression *function; 87 std::list<Expression *> args; 88 InferredParams inferParams; 85 89 }; 86 90 … … 88 92 // particular overload for the function name has not yet been determined. Most operators are 89 93 // converted into functional form automatically, to permit operator overloading. 90 class UntypedExpr : public Expression 91 { 92 public: 93 UntypedExpr( Expression *function, Expression *_aname = 0 ); 94 UntypedExpr( const UntypedExpr &other ); 95 UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 ); 96 virtual ~UntypedExpr(); 97 98 Expression *get_function() const { return function; } 99 void set_function( Expression *newValue ) { function = newValue; } 100 101 void set_args( std::list<Expression *> &listArgs ) { args = listArgs; } 102 std::list<Expression*>::iterator begin_args() { return args.begin(); } 103 std::list<Expression*>::iterator end_args() { return args.end(); } 104 std::list<Expression*>& get_args() { return args; } 105 106 virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); } 107 virtual void accept( Visitor &v ) { v.visit( this ); } 108 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 109 virtual void print( std::ostream &os, int indent = 0 ) const; 110 virtual void printArgs(std::ostream &os, int indent = 0) const; 111 112 private: 113 114 Expression *function; 115 std::list<Expression*> args; 94 95 class UntypedExpr : public Expression { 96 public: 97 UntypedExpr( Expression *function, Expression *_aname = 0 ); 98 UntypedExpr( const UntypedExpr &other ); 99 UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 ); 100 virtual ~UntypedExpr(); 101 102 Expression *get_function() const { return function; } 103 void set_function( Expression *newValue ) { function = newValue; } 104 105 void set_args( std::list<Expression *> &listArgs ) { args = listArgs; } 106 std::list<Expression*>::iterator begin_args() { return args.begin(); } 107 std::list<Expression*>::iterator end_args() { return args.end(); } 108 std::list<Expression*>& get_args() { return args; } 109 110 virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); } 111 virtual void accept( Visitor &v ) { v.visit( this ); } 112 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 113 virtual void print( std::ostream &os, int indent = 0 ) const; 114 virtual void printArgs(std::ostream &os, int indent = 0) const; 115 private: 116 Expression *function; 117 std::list<Expression*> args; 116 118 }; 117 119 118 120 // this class contains a name whose meaning is still not determined 119 class NameExpr : public Expression 120 { 121 public: 122 NameExpr( std::string name, Expression *_aname = 0 ); 123 NameExpr( const NameExpr &other ); 124 virtual ~NameExpr(); 125 126 std::string get_name() const { return name; } 127 void set_name( std::string newValue ) { name = newValue; } 128 129 virtual NameExpr *clone() const { return new NameExpr( *this ); } 130 virtual void accept( Visitor &v ) { v.visit( this ); } 131 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 132 virtual void print( std::ostream &os, int indent = 0 ) const; 133 134 private: 135 136 std::string name; 121 class NameExpr : public Expression { 122 public: 123 NameExpr( std::string name, Expression *_aname = 0 ); 124 NameExpr( const NameExpr &other ); 125 virtual ~NameExpr(); 126 127 std::string get_name() const { return name; } 128 void set_name( std::string newValue ) { name = newValue; } 129 130 virtual NameExpr *clone() const { return new NameExpr( *this ); } 131 virtual void accept( Visitor &v ) { v.visit( this ); } 132 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 133 virtual void print( std::ostream &os, int indent = 0 ) const; 134 private: 135 std::string name; 137 136 }; 138 137 … … 141 140 142 141 // AddressExpr represents a address-of expression, e.g. &e 143 class AddressExpr : public Expression 144 { 145 public: 146 AddressExpr( Expression *arg, Expression *_aname = 0 ); 147 AddressExpr( const AddressExpr &other ); 148 virtual ~AddressExpr(); 149 150 Expression *get_arg() const { return arg; } 151 void set_arg(Expression *newValue ) { arg = newValue; } 152 153 virtual AddressExpr *clone() const { return new AddressExpr( *this ); } 154 virtual void accept( Visitor &v ) { v.visit( this ); } 155 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 156 virtual void print( std::ostream &os, int indent = 0 ) const; 157 158 private: 159 Expression *arg; 160 }; 161 162 class LabelAddressExpr : public Expression 163 { 164 public: 165 LabelAddressExpr( Expression *arg ); 166 LabelAddressExpr( const AddressExpr &other ); 167 virtual ~LabelAddressExpr(); 168 169 Expression *get_arg() const { return arg; } 170 void set_arg(Expression *newValue ) { arg = newValue; } 171 172 virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); } 173 virtual void accept( Visitor &v ) { v.visit( this ); } 174 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 175 virtual void print( std::ostream &os, int indent = 0 ) const; 176 177 private: 178 Expression *arg; 142 class AddressExpr : public Expression { 143 public: 144 AddressExpr( Expression *arg, Expression *_aname = 0 ); 145 AddressExpr( const AddressExpr &other ); 146 virtual ~AddressExpr(); 147 148 Expression *get_arg() const { return arg; } 149 void set_arg(Expression *newValue ) { arg = newValue; } 150 151 virtual AddressExpr *clone() const { return new AddressExpr( *this ); } 152 virtual void accept( Visitor &v ) { v.visit( this ); } 153 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 154 virtual void print( std::ostream &os, int indent = 0 ) const; 155 private: 156 Expression *arg; 157 }; 158 159 class LabelAddressExpr : public Expression { 160 public: 161 LabelAddressExpr( Expression *arg ); 162 LabelAddressExpr( const AddressExpr &other ); 163 virtual ~LabelAddressExpr(); 164 165 Expression *get_arg() const { return arg; } 166 void set_arg(Expression *newValue ) { arg = newValue; } 167 168 virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); } 169 virtual void accept( Visitor &v ) { v.visit( this ); } 170 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 171 virtual void print( std::ostream &os, int indent = 0 ) const; 172 private: 173 Expression *arg; 179 174 }; 180 175 181 176 // CastExpr represents a type cast expression, e.g. (int)e 182 class CastExpr : public Expression 183 { 184 public: 185 CastExpr( Expression *arg, Expression *_aname = 0 ); 186 CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 ); 187 CastExpr( const CastExpr &other ); 188 virtual ~CastExpr(); 189 190 Expression *get_arg() const { return arg; } 191 void set_arg(Expression *newValue ) { arg = newValue; } 192 193 virtual CastExpr *clone() const { return new CastExpr( *this ); } 194 virtual void accept( Visitor &v ) { v.visit( this ); } 195 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 196 virtual void print( std::ostream &os, int indent = 0 ) const; 197 198 private: 199 Expression *arg; 200 }; 201 202 // UntypedMemberExpr represents a member selection operation, e.g. q.p 203 // before processing by the expression analyzer 204 class UntypedMemberExpr : public Expression 205 { 206 public: 207 UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 ); 208 UntypedMemberExpr( const UntypedMemberExpr &other ); 209 virtual ~UntypedMemberExpr(); 210 211 std::string get_member() const { return member; } 212 void set_member( const std::string &newValue ) { member = newValue; } 213 Expression *get_aggregate() const { return aggregate; } 214 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 215 216 virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); } 217 virtual void accept( Visitor &v ) { v.visit( this ); } 218 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 219 virtual void print( std::ostream &os, int indent = 0 ) const; 220 221 private: 222 std::string member; 223 Expression *aggregate; 224 }; 225 226 // MemberExpr represents a member selection operation, e.g. q.p 227 // after processing by the expression analyzer 228 class MemberExpr : public Expression 229 { 230 public: 231 MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 ); 232 MemberExpr( const MemberExpr &other ); 233 virtual ~MemberExpr(); 234 235 DeclarationWithType *get_member() const { return member; } 236 void set_member( DeclarationWithType *newValue ) { member = newValue; } 237 Expression *get_aggregate() const { return aggregate; } 238 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 239 240 virtual MemberExpr *clone() const { return new MemberExpr( *this ); } 241 virtual void accept( Visitor &v ) { v.visit( this ); } 242 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 243 virtual void print( std::ostream &os, int indent = 0 ) const; 244 245 private: 246 DeclarationWithType *member; 247 Expression *aggregate; 177 class CastExpr : public Expression { 178 public: 179 CastExpr( Expression *arg, Expression *_aname = 0 ); 180 CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 ); 181 CastExpr( const CastExpr &other ); 182 virtual ~CastExpr(); 183 184 Expression *get_arg() const { return arg; } 185 void set_arg(Expression *newValue ) { arg = newValue; } 186 187 virtual CastExpr *clone() const { return new CastExpr( *this ); } 188 virtual void accept( Visitor &v ) { v.visit( this ); } 189 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 190 virtual void print( std::ostream &os, int indent = 0 ) const; 191 private: 192 Expression *arg; 193 }; 194 195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer 196 class UntypedMemberExpr : public Expression { 197 public: 198 UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 ); 199 UntypedMemberExpr( const UntypedMemberExpr &other ); 200 virtual ~UntypedMemberExpr(); 201 202 std::string get_member() const { return member; } 203 void set_member( const std::string &newValue ) { member = newValue; } 204 Expression *get_aggregate() const { return aggregate; } 205 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 206 207 virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); } 208 virtual void accept( Visitor &v ) { v.visit( this ); } 209 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 210 virtual void print( std::ostream &os, int indent = 0 ) const; 211 private: 212 std::string member; 213 Expression *aggregate; 214 }; 215 216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 217 class MemberExpr : public Expression { 218 public: 219 MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 ); 220 MemberExpr( const MemberExpr &other ); 221 virtual ~MemberExpr(); 222 223 DeclarationWithType *get_member() const { return member; } 224 void set_member( DeclarationWithType *newValue ) { member = newValue; } 225 Expression *get_aggregate() const { return aggregate; } 226 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 227 228 virtual MemberExpr *clone() const { return new MemberExpr( *this ); } 229 virtual void accept( Visitor &v ) { v.visit( this ); } 230 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 231 virtual void print( std::ostream &os, int indent = 0 ) const; 232 private: 233 DeclarationWithType *member; 234 Expression *aggregate; 248 235 }; 249 236 250 237 // VariableExpr represents an expression that simply refers to the value of a named variable 251 class VariableExpr : public Expression 252 { 253 public: 254 VariableExpr( DeclarationWithType *var, Expression *_aname = 0 ); 255 VariableExpr( const VariableExpr &other ); 256 virtual ~VariableExpr(); 257 258 DeclarationWithType *get_var() const { return var; } 259 void set_var( DeclarationWithType *newValue ) { var = newValue; } 260 261 virtual VariableExpr *clone() const { return new VariableExpr( *this ); } 262 virtual void accept( Visitor &v ) { v.visit( this ); } 263 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 264 virtual void print( std::ostream &os, int indent = 0 ) const; 265 266 private: 267 DeclarationWithType *var; 238 class VariableExpr : public Expression { 239 public: 240 VariableExpr( DeclarationWithType *var, Expression *_aname = 0 ); 241 VariableExpr( const VariableExpr &other ); 242 virtual ~VariableExpr(); 243 244 DeclarationWithType *get_var() const { return var; } 245 void set_var( DeclarationWithType *newValue ) { var = newValue; } 246 247 virtual VariableExpr *clone() const { return new VariableExpr( *this ); } 248 virtual void accept( Visitor &v ) { v.visit( this ); } 249 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 250 virtual void print( std::ostream &os, int indent = 0 ) const; 251 private: 252 DeclarationWithType *var; 268 253 }; 269 254 270 255 // ConstantExpr represents an expression that simply refers to the value of a constant 271 class ConstantExpr : public Expression 272 { 273 public: 274 ConstantExpr( Constant constant, Expression *_aname = 0 ); 275 ConstantExpr( const ConstantExpr &other ); 276 virtual ~ConstantExpr(); 277 278 Constant *get_constant() { return &constant; } 279 void set_constant( const Constant &newValue ) { constant = newValue; } 280 281 virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); } 282 virtual void accept( Visitor &v ) { v.visit( this ); } 283 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 284 virtual void print( std::ostream &os, int indent = 0 ) const; 285 286 private: 287 Constant constant; 256 class ConstantExpr : public Expression { 257 public: 258 ConstantExpr( Constant constant, Expression *_aname = 0 ); 259 ConstantExpr( const ConstantExpr &other ); 260 virtual ~ConstantExpr(); 261 262 Constant *get_constant() { return &constant; } 263 void set_constant( const Constant &newValue ) { constant = newValue; } 264 265 virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); } 266 virtual void accept( Visitor &v ) { v.visit( this ); } 267 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 268 virtual void print( std::ostream &os, int indent = 0 ) const; 269 private: 270 Constant constant; 288 271 }; 289 272 290 273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) 291 class SizeofExpr : public Expression 292 { 293 public: 294 SizeofExpr( Expression *expr, Expression *_aname = 0 ); 295 SizeofExpr( const SizeofExpr &other ); 296 SizeofExpr( Type *type, Expression *_aname = 0 ); 297 virtual ~SizeofExpr(); 298 299 Expression *get_expr() const { return expr; } 300 void set_expr( Expression *newValue ) { expr = newValue; } 301 Type *get_type() const { return type; } 302 void set_type( Type *newValue ) { type = newValue; } 303 bool get_isType() const { return isType; } 304 void set_isType( bool newValue ) { isType = newValue; } 305 306 virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); } 307 virtual void accept( Visitor &v ) { v.visit( this ); } 308 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 309 virtual void print( std::ostream &os, int indent = 0 ) const; 310 311 private: 312 Expression *expr; 313 Type *type; 314 bool isType; 274 class SizeofExpr : public Expression { 275 public: 276 SizeofExpr( Expression *expr, Expression *_aname = 0 ); 277 SizeofExpr( const SizeofExpr &other ); 278 SizeofExpr( Type *type, Expression *_aname = 0 ); 279 virtual ~SizeofExpr(); 280 281 Expression *get_expr() const { return expr; } 282 void set_expr( Expression *newValue ) { expr = newValue; } 283 Type *get_type() const { return type; } 284 void set_type( Type *newValue ) { type = newValue; } 285 bool get_isType() const { return isType; } 286 void set_isType( bool newValue ) { isType = newValue; } 287 288 virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); } 289 virtual void accept( Visitor &v ) { v.visit( this ); } 290 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 291 virtual void print( std::ostream &os, int indent = 0 ) const; 292 private: 293 Expression *expr; 294 Type *type; 295 bool isType; 315 296 }; 316 297 317 298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined) 318 class AttrExpr : public Expression 319 { 320 public: 321 AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 ); 322 AttrExpr( const AttrExpr &other ); 323 AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 ); 324 virtual ~AttrExpr(); 325 326 Expression *get_attr() const { return attr; } 327 void set_attr( Expression *newValue ) { attr = newValue; } 328 Expression *get_expr() const { return expr; } 329 void set_expr( Expression *newValue ) { expr = newValue; } 330 Type *get_type() const { return type; } 331 void set_type( Type *newValue ) { type = newValue; } 332 bool get_isType() const { return isType; } 333 void set_isType( bool newValue ) { isType = newValue; } 334 335 virtual AttrExpr *clone() const { return new AttrExpr( *this ); } 336 virtual void accept( Visitor &v ) { v.visit( this ); } 337 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 338 virtual void print( std::ostream &os, int indent = 0 ) const; 339 340 private: 341 Expression *attr; 342 Expression *expr; 343 Type *type; 344 bool isType; 299 class AttrExpr : public Expression { 300 public: 301 AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 ); 302 AttrExpr( const AttrExpr &other ); 303 AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 ); 304 virtual ~AttrExpr(); 305 306 Expression *get_attr() const { return attr; } 307 void set_attr( Expression *newValue ) { attr = newValue; } 308 Expression *get_expr() const { return expr; } 309 void set_expr( Expression *newValue ) { expr = newValue; } 310 Type *get_type() const { return type; } 311 void set_type( Type *newValue ) { type = newValue; } 312 bool get_isType() const { return isType; } 313 void set_isType( bool newValue ) { isType = newValue; } 314 315 virtual AttrExpr *clone() const { return new AttrExpr( *this ); } 316 virtual void accept( Visitor &v ) { v.visit( this ); } 317 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 318 virtual void print( std::ostream &os, int indent = 0 ) const; 319 private: 320 Expression *attr; 321 Expression *expr; 322 Type *type; 323 bool isType; 345 324 }; 346 325 347 326 // LogicalExpr represents a short-circuit boolean expression (&& or ||) 348 class LogicalExpr : public Expression 349 { 350 public: 351 LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 ); 352 LogicalExpr( const LogicalExpr &other ); 353 virtual ~LogicalExpr(); 354 355 bool get_isAnd() const { return isAnd; } 356 Expression *get_arg1() { return arg1; } 357 void set_arg1( Expression *newValue ) { arg1 = newValue; } 358 Expression *get_arg2() const { return arg2; } 359 void set_arg2( Expression *newValue ) { arg2 = newValue; } 360 361 virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); } 362 virtual void accept( Visitor &v ) { v.visit( this ); } 363 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 364 virtual void print( std::ostream &os, int indent = 0 ) const; 365 366 private: 367 Expression *arg1; 368 Expression *arg2; 369 bool isAnd; 327 class LogicalExpr : public Expression { 328 public: 329 LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 ); 330 LogicalExpr( const LogicalExpr &other ); 331 virtual ~LogicalExpr(); 332 333 bool get_isAnd() const { return isAnd; } 334 Expression *get_arg1() { return arg1; } 335 void set_arg1( Expression *newValue ) { arg1 = newValue; } 336 Expression *get_arg2() const { return arg2; } 337 void set_arg2( Expression *newValue ) { arg2 = newValue; } 338 339 virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); } 340 virtual void accept( Visitor &v ) { v.visit( this ); } 341 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 342 virtual void print( std::ostream &os, int indent = 0 ) const; 343 private: 344 Expression *arg1; 345 Expression *arg2; 346 bool isAnd; 370 347 }; 371 348 372 349 // ConditionalExpr represents the three-argument conditional ( p ? a : b ) 373 class ConditionalExpr : public Expression 374 { 375 public: 376 ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 ); 377 ConditionalExpr( const ConditionalExpr &other ); 378 virtual ~ConditionalExpr(); 379 380 Expression *get_arg1() const { return arg1; } 381 void set_arg1( Expression *newValue ) { arg1 = newValue; } 382 Expression *get_arg2() const { return arg2; } 383 void set_arg2( Expression *newValue ) { arg2 = newValue; } 384 Expression *get_arg3() const { return arg3; } 385 void set_arg3( Expression *newValue ) { arg3 = newValue; } 386 387 virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); } 388 virtual void accept( Visitor &v ) { v.visit( this ); } 389 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 390 virtual void print( std::ostream &os, int indent = 0 ) const; 391 392 private: 393 Expression *arg1; 394 Expression *arg2; 395 Expression *arg3; 350 class ConditionalExpr : public Expression { 351 public: 352 ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 ); 353 ConditionalExpr( const ConditionalExpr &other ); 354 virtual ~ConditionalExpr(); 355 356 Expression *get_arg1() const { return arg1; } 357 void set_arg1( Expression *newValue ) { arg1 = newValue; } 358 Expression *get_arg2() const { return arg2; } 359 void set_arg2( Expression *newValue ) { arg2 = newValue; } 360 Expression *get_arg3() const { return arg3; } 361 void set_arg3( Expression *newValue ) { arg3 = newValue; } 362 363 virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); } 364 virtual void accept( Visitor &v ) { v.visit( this ); } 365 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 366 virtual void print( std::ostream &os, int indent = 0 ) const; 367 private: 368 Expression *arg1; 369 Expression *arg2; 370 Expression *arg3; 396 371 }; 397 372 398 373 // CommaExpr represents the sequence operator ( a, b ) 399 class CommaExpr : public Expression 400 { 401 public: 402 CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 ); 403 CommaExpr( const CommaExpr &other ); 404 virtual ~CommaExpr(); 405 406 Expression *get_arg1() const { return arg1; } 407 void set_arg1( Expression *newValue ) { arg1 = newValue; } 408 Expression *get_arg2() const { return arg2; } 409 void set_arg2( Expression *newValue ) { arg2 = newValue; } 410 411 virtual CommaExpr *clone() const { return new CommaExpr( *this ); } 412 virtual void accept( Visitor &v ) { v.visit( this ); } 413 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 414 virtual void print( std::ostream &os, int indent = 0 ) const; 415 416 private: 417 Expression *arg1; 418 Expression *arg2; 374 class CommaExpr : public Expression { 375 public: 376 CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 ); 377 CommaExpr( const CommaExpr &other ); 378 virtual ~CommaExpr(); 379 380 Expression *get_arg1() const { return arg1; } 381 void set_arg1( Expression *newValue ) { arg1 = newValue; } 382 Expression *get_arg2() const { return arg2; } 383 void set_arg2( Expression *newValue ) { arg2 = newValue; } 384 385 virtual CommaExpr *clone() const { return new CommaExpr( *this ); } 386 virtual void accept( Visitor &v ) { v.visit( this ); } 387 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 388 virtual void print( std::ostream &os, int indent = 0 ) const; 389 private: 390 Expression *arg1; 391 Expression *arg2; 419 392 }; 420 393 421 394 // TupleExpr represents a tuple expression ( [a, b, c] ) 422 class TupleExpr : public Expression 423 { 424 public: 425 TupleExpr( Expression *_aname = 0 ); 426 TupleExpr( const TupleExpr &other ); 427 virtual ~TupleExpr(); 428 429 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } 430 std::list<Expression*>& get_exprs() { return exprs; } 431 432 virtual TupleExpr *clone() const { return new TupleExpr( *this ); } 433 virtual void accept( Visitor &v ) { v.visit( this ); } 434 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 435 virtual void print( std::ostream &os, int indent = 0 ) const; 436 437 private: 438 std::list<Expression*> exprs; 395 class TupleExpr : public Expression { 396 public: 397 TupleExpr( Expression *_aname = 0 ); 398 TupleExpr( const TupleExpr &other ); 399 virtual ~TupleExpr(); 400 401 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } 402 std::list<Expression*>& get_exprs() { return exprs; } 403 404 virtual TupleExpr *clone() const { return new TupleExpr( *this ); } 405 virtual void accept( Visitor &v ) { v.visit( this ); } 406 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 407 virtual void print( std::ostream &os, int indent = 0 ) const; 408 private: 409 std::list<Expression*> exprs; 439 410 }; 440 411 441 412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on 442 class SolvedTupleExpr : public Expression 443 { 444 public: 445 446 SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {} 447 SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 ); 448 SolvedTupleExpr( const SolvedTupleExpr &other ); 449 virtual ~SolvedTupleExpr() {} 450 451 std::list<Expression*> &get_exprs() { return exprs; } 452 453 virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); } 454 virtual void accept( Visitor &v ) { v.visit( this ); } 455 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 456 virtual void print( std::ostream &os, int indent = 0 ) const; 457 private: 458 std::list<Expression*> exprs; 413 class SolvedTupleExpr : public Expression { 414 public: 415 SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {} 416 SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 ); 417 SolvedTupleExpr( const SolvedTupleExpr &other ); 418 virtual ~SolvedTupleExpr() {} 419 420 std::list<Expression*> &get_exprs() { return exprs; } 421 422 virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); } 423 virtual void accept( Visitor &v ) { v.visit( this ); } 424 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 425 virtual void print( std::ostream &os, int indent = 0 ) const; 426 private: 427 std::list<Expression*> exprs; 459 428 }; 460 429 461 430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 462 class TypeExpr : public Expression 463 { 464 public: 465 TypeExpr( Type *type ); 466 TypeExpr( const TypeExpr &other ); 467 virtual ~TypeExpr(); 468 469 Type *get_type() const { return type; } 470 void set_type( Type *newValue ) { type = newValue; } 471 472 virtual TypeExpr *clone() const { return new TypeExpr( *this ); } 473 virtual void accept( Visitor &v ) { v.visit( this ); } 474 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 475 virtual void print( std::ostream &os, int indent = 0 ) const; 476 477 private: 478 Type *type; 431 class TypeExpr : public Expression { 432 public: 433 TypeExpr( Type *type ); 434 TypeExpr( const TypeExpr &other ); 435 virtual ~TypeExpr(); 436 437 Type *get_type() const { return type; } 438 void set_type( Type *newValue ) { type = newValue; } 439 440 virtual TypeExpr *clone() const { return new TypeExpr( *this ); } 441 virtual void accept( Visitor &v ) { v.visit( this ); } 442 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 443 virtual void print( std::ostream &os, int indent = 0 ) const; 444 private: 445 Type *type; 479 446 }; 480 447 481 448 // ValofExpr represents a GCC 'lambda expression' 482 class UntypedValofExpr : public Expression 483 { 484 public: 485 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 486 virtual ~UntypedValofExpr() {} 487 488 Expression *get_value(); 489 Statement *get_body() const { return body; } 490 491 virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); } 492 virtual void accept( Visitor &v ) { v.visit( this ); } 493 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 494 virtual void print( std::ostream &os, int indent = 0 ) const; 495 496 private: 497 Statement *body; 498 }; 499 500 501 #endif /* #ifndef EXPRESSION_H */ 502 503 /* 504 Local Variables: 505 mode: c++ 506 End: 507 */ 449 class UntypedValofExpr : public Expression { 450 public: 451 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 452 virtual ~UntypedValofExpr() {} 453 454 Expression *get_value(); 455 Statement *get_body() const { return body; } 456 457 virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); } 458 virtual void accept( Visitor &v ) { v.visit( this ); } 459 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 460 virtual void print( std::ostream &os, int indent = 0 ) const; 461 private: 462 Statement *body; 463 }; 464 465 #endif // EXPRESSION_H 466 467 // Local Variables: // 468 // tab-width: 4 // 469 // mode: c++ // 470 // compile-command: "make install" // 471 // End: // -
translator/SynTree/FunctionDecl.cc
ra32b204 r0dd3a2f 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 // FunctionDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:48:46 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 17 … … 6 21 #include "utility.h" 7 22 8 9 23 FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ) 10 24 : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) { 11 // this is a brazen hack to force the function "main" to have C linkage12 if ( name == "main" ) {13 set_linkage( LinkageSpec::C );14 } 25 // this is a brazen hack to force the function "main" to have C linkage 26 if ( name == "main" ) { 27 set_linkage( LinkageSpec::C ); 28 } // if 15 29 } 16 30 17 31 FunctionDecl::FunctionDecl( const FunctionDecl &other ) 18 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) {32 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) { 19 33 } 20 34 21 35 FunctionDecl::~FunctionDecl() { 22 delete type;23 delete statements;36 delete type; 37 delete statements; 24 38 } 25 39 26 40 Type * FunctionDecl::get_type() const { 27 return type;41 return type; 28 42 } 29 43 30 44 void FunctionDecl::set_type( Type *t ) { 31 type = dynamic_cast< FunctionType* >( t );32 assert( type );45 type = dynamic_cast< FunctionType* >( t ); 46 assert( type ); 33 47 } 34 48 35 49 void FunctionDecl::print( std::ostream &os, int indent ) const { 36 using std::endl;37 using std::string;38 39 if ( get_name() != "" ) {40 os << get_name() << ": a ";41 } 42 if ( get_linkage() != LinkageSpec::Cforall ) {43 os << LinkageSpec::toString( get_linkage() ) << " ";44 } 45 if ( isInline ) {46 os << "inline ";47 } 48 if ( get_storageClass() != NoStorageClass ) {49 os << storageClassName[ get_storageClass() ] << ' ';50 } 51 if ( get_type() ) {52 get_type()->print( os, indent );53 } else {54 os << "untyped entity ";55 } 56 if ( ! oldIdents.empty() ) {57 os << string( indent+2, ' ' ) << "with parameter names" << endl;58 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {59 os << string( indent+4, ' ' ) << *i << endl;60 }61 } 62 if ( ! oldDecls.empty() ) {63 os << string( indent+2, ' ' ) << "with parameter declarations" << endl;64 printAll( oldDecls, os, indent+4 );65 } 66 if ( statements ) {67 os << string( indent+2, ' ' ) << "with body " << endl;68 statements->print( os, indent+4 );69 } 50 using std::endl; 51 using std::string; 52 53 if ( get_name() != "" ) { 54 os << get_name() << ": a "; 55 } // if 56 if ( get_linkage() != LinkageSpec::Cforall ) { 57 os << LinkageSpec::toString( get_linkage() ) << " "; 58 } // if 59 if ( isInline ) { 60 os << "inline "; 61 } // if 62 if ( get_storageClass() != NoStorageClass ) { 63 os << storageClassName[ get_storageClass() ] << ' '; 64 } // if 65 if ( get_type() ) { 66 get_type()->print( os, indent ); 67 } else { 68 os << "untyped entity "; 69 } // if 70 if ( ! oldIdents.empty() ) { 71 os << string( indent+2, ' ' ) << "with parameter names" << endl; 72 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) { 73 os << string( indent+4, ' ' ) << *i << endl; 74 } // for 75 } // if 76 if ( ! oldDecls.empty() ) { 77 os << string( indent+2, ' ' ) << "with parameter declarations" << endl; 78 printAll( oldDecls, os, indent+4 ); 79 } // if 80 if ( statements ) { 81 os << string( indent+2, ' ' ) << "with body " << endl; 82 statements->print( os, indent+4 ); 83 } // if 70 84 } 71 85 72 86 void FunctionDecl::printShort( std::ostream &os, int indent ) const { 73 using std::endl;74 using std::string;75 76 if ( get_name() != "" ) {77 os << get_name() << ": a ";78 } 79 if ( isInline ) {80 os << "inline ";81 } 82 if ( get_storageClass() != NoStorageClass ) {83 os << storageClassName[ get_storageClass() ] << ' ';84 } 85 if ( get_type() ) {86 get_type()->print( os, indent );87 } else {88 os << "untyped entity ";89 } 87 using std::endl; 88 using std::string; 89 90 if ( get_name() != "" ) { 91 os << get_name() << ": a "; 92 } // if 93 if ( isInline ) { 94 os << "inline "; 95 } // if 96 if ( get_storageClass() != NoStorageClass ) { 97 os << storageClassName[ get_storageClass() ] << ' '; 98 } // if 99 if ( get_type() ) { 100 get_type()->print( os, indent ); 101 } else { 102 os << "untyped entity "; 103 } // if 90 104 } 105 106 // Local Variables: // 107 // tab-width: 4 // 108 // mode: c++ // 109 // compile-command: "make install" // 110 // End: // -
translator/SynTree/FunctionType.cc
ra32b204 r0dd3a2f 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 // FunctionType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:01:28 2015 13 // Update Count : 1 14 // 15 1 16 #include <algorithm> 2 17 … … 5 20 #include "utility.h" 6 21 7 8 22 FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) : Type( tq ), isVarArgs( isVarArgs ) { 9 23 } 10 24 11 25 FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) { 12 cloneAll( other.returnVals, returnVals );13 cloneAll( other.parameters, parameters );26 cloneAll( other.returnVals, returnVals ); 27 cloneAll( other.parameters, parameters ); 14 28 } 15 29 16 30 FunctionType::~FunctionType() { 17 deleteAll( returnVals );18 deleteAll( parameters );31 deleteAll( returnVals ); 32 deleteAll( parameters ); 19 33 } 20 34 21 35 void FunctionType::print( std::ostream &os, int indent ) const { 22 using std::string;23 using std::endl;36 using std::string; 37 using std::endl; 24 38 25 Type::print( os, indent );26 os << "function" << endl;27 if ( ! parameters.empty() ) {28 os << string( indent + 2, ' ' ) << "with parameters" << endl;29 printAll( parameters, os, indent + 4 );30 if ( isVarArgs ) {31 os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl;32 }33 } else if ( isVarArgs ) {34 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;35 } 36 os << string( indent + 2, ' ' ) << "returning ";37 if ( returnVals.empty() ) {38 os << endl << string( indent + 4, ' ' ) << "nothing " << endl;39 } else {40 os << endl;41 printAll( returnVals, os, indent + 4 );42 } 39 Type::print( os, indent ); 40 os << "function" << endl; 41 if ( ! parameters.empty() ) { 42 os << string( indent + 2, ' ' ) << "with parameters" << endl; 43 printAll( parameters, os, indent + 4 ); 44 if ( isVarArgs ) { 45 os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl; 46 } // if 47 } else if ( isVarArgs ) { 48 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl; 49 } // if 50 os << string( indent + 2, ' ' ) << "returning "; 51 if ( returnVals.empty() ) { 52 os << endl << string( indent + 4, ' ' ) << "nothing " << endl; 53 } else { 54 os << endl; 55 printAll( returnVals, os, indent + 4 ); 56 } // if 43 57 } 44 58 59 // Local Variables: // 60 // tab-width: 4 // 61 // mode: c++ // 62 // compile-command: "make install" // 63 // End: // -
translator/SynTree/Initializer.cc
ra32b204 r0dd3a2f 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 // Initializer.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:02:45 2015 13 // Update Count : 2 14 // 15 1 16 #include "Initializer.h" 2 17 #include "Expression.h" 3 18 #include "utility.h" 4 5 19 6 20 Initializer::Initializer() {} … … 9 23 10 24 std::string Initializer::designator_name( Expression *des ) { 11 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )12 return n->get_name();13 else14 throw 0;25 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) 26 return n->get_name(); 27 else 28 throw 0; 15 29 } 16 30 … … 21 35 22 36 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) { 23 cloneAll(other.designators, designators );37 cloneAll(other.designators, designators ); 24 38 } 25 39 … … 29 43 30 44 void SingleInit::print( std::ostream &os, int indent ) { 31 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: ";32 value->print( os, indent+2 );45 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: "; 46 value->print( os, indent+2 ); 33 47 34 if ( ! designators.empty() ) {35 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ;36 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ )37 ( *i )->print(os, indent + 4 );38 } 48 if ( ! designators.empty() ) { 49 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ; 50 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) 51 ( *i )->print(os, indent + 4 ); 52 } // if 39 53 } 40 54 41 55 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) 42 : initializers( _initializers ), designators( _designators ) {56 : initializers( _initializers ), designators( _designators ) { 43 57 } 44 58 … … 46 60 47 61 ListInit *ListInit::clone() const { 48 return new ListInit( *this );62 return new ListInit( *this ); 49 63 } 50 64 51 65 void ListInit::print( std::ostream &os, int indent ) { 52 os << std::endl << std::string(indent, ' ') << "Compound initializer: ";53 if ( ! designators.empty() ) {54 os << std::string(indent + 2, ' ' ) << "designated by: [";55 for ( std::list < Expression * >::iterator i = designators.begin();56 i != designators.end(); i++ ) {57 ( *i )->print(os, indent + 4 );58 }66 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 67 if ( ! designators.empty() ) { 68 os << std::string(indent + 2, ' ' ) << "designated by: ["; 69 for ( std::list < Expression * >::iterator i = designators.begin(); 70 i != designators.end(); i++ ) { 71 ( *i )->print(os, indent + 4 ); 72 } // for 59 73 60 os << std::string(indent + 2, ' ' ) << "]";61 } 74 os << std::string(indent + 2, ' ' ) << "]"; 75 } // if 62 76 63 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )64 (*i)->print( os, indent + 2 );77 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 78 (*i)->print( os, indent + 2 ); 65 79 } 80 // Local Variables: // 81 // tab-width: 4 // 82 // mode: c++ // 83 // compile-command: "make install" // 84 // End: // -
translator/SynTree/Initializer.h
ra32b204 r0dd3a2f 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 // Initializer.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:03:48 2015 13 // Update Count : 1 14 // 15 1 16 #ifndef INITIALIZER_H 2 17 #define INITIALIZER_H … … 8 23 #include <cassert> 9 24 10 11 25 // Initializer: base class for object initializers (provide default values) 12 26 class Initializer { 13 27 public: 14 // Initializer( std::string _name = std::string(""), int _pos = 0 );15 Initializer( );16 virtual ~Initializer();28 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 29 Initializer( ); 30 virtual ~Initializer(); 17 31 18 static std::string designator_name( Expression *designator );32 static std::string designator_name( Expression *designator ); 19 33 20 // void set_name( std::string newValue ) { name = newValue; }21 // std::string get_name() const { return name; }34 // void set_name( std::string newValue ) { name = newValue; } 35 // std::string get_name() const { return name; } 22 36 23 // void set_pos( int newValue ) { pos = newValue; }24 // int get_pos() const { return pos; }25 virtual void set_designators( std::list<Expression *> & ) { assert(false); }26 virtual std::list<Expression *> &get_designators() {27 assert(false);28 std::list<Expression *> *ret = 0; return *ret; // never reached29 }37 // void set_pos( int newValue ) { pos = newValue; } 38 // int get_pos() const { return pos; } 39 virtual void set_designators( std::list<Expression *> & ) { assert(false); } 40 virtual std::list<Expression *> &get_designators() { 41 assert(false); 42 std::list<Expression *> *ret = 0; return *ret; // never reached 43 } 30 44 31 virtual Initializer *clone() const = 0;32 virtual void accept( Visitor &v ) = 0;33 virtual Initializer *acceptMutator( Mutator &m ) = 0;34 virtual void print( std::ostream &os, int indent = 0 );45 virtual Initializer *clone() const = 0; 46 virtual void accept( Visitor &v ) = 0; 47 virtual Initializer *acceptMutator( Mutator &m ) = 0; 48 virtual void print( std::ostream &os, int indent = 0 ); 35 49 private: 36 // std::string name;37 // int pos;50 // std::string name; 51 // int pos; 38 52 }; 39 53 … … 41 55 class SingleInit : public Initializer { 42 56 public: 43 SingleInit( Expression *value, std::list< Expression *> &designators );44 SingleInit( const SingleInit &other );45 virtual ~SingleInit();46 47 Expression *get_value() { return value; }48 void set_value( Expression *newValue ) { value = newValue; }57 SingleInit( Expression *value, std::list< Expression *> &designators ); 58 SingleInit( const SingleInit &other ); 59 virtual ~SingleInit(); 60 61 Expression *get_value() { return value; } 62 void set_value( Expression *newValue ) { value = newValue; } 49 63 50 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }51 std::list<Expression *> &get_designators() { return designators; }64 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; } 65 std::list<Expression *> &get_designators() { return designators; } 52 66 53 virtual SingleInit *clone() const;54 virtual void accept( Visitor &v ) { v.visit( this ); }55 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }56 virtual void print( std::ostream &os, int indent = 0 );67 virtual SingleInit *clone() const; 68 virtual void accept( Visitor &v ) { v.visit( this ); } 69 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 70 virtual void print( std::ostream &os, int indent = 0 ); 57 71 private: 58 //Constant *value;59 Expression *value; // has to be a compile-time constant60 std::list< Expression * > designators;72 //Constant *value; 73 Expression *value; // has to be a compile-time constant 74 std::list< Expression * > designators; 61 75 }; 62 76 … … 65 79 class ListInit : public Initializer { 66 80 public: 67 ListInit( std::list<Initializer*> &,68 std::list<Expression *> &designators = *(new std::list<Expression *>()) );69 virtual ~ListInit();81 ListInit( std::list<Initializer*> &, 82 std::list<Expression *> &designators = *(new std::list<Expression *>()) ); 83 virtual ~ListInit(); 70 84 71 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }72 std::list<Expression *> &get_designators() { return designators; }73 void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }74 std::list<Initializer*> &get_initializers() { return initializers; }85 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; } 86 std::list<Expression *> &get_designators() { return designators; } 87 void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; } 88 std::list<Initializer*> &get_initializers() { return initializers; } 75 89 76 std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }77 std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }90 std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); } 91 std::list<Initializer*>::iterator end_initializers() { return initializers.end(); } 78 92 79 virtual ListInit *clone() const;80 virtual void accept( Visitor &v ) { v.visit( this ); }81 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }82 virtual void print( std::ostream &os, int indent = 0 );93 virtual ListInit *clone() const; 94 virtual void accept( Visitor &v ) { v.visit( this ); } 95 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 96 virtual void print( std::ostream &os, int indent = 0 ); 83 97 private: 84 std::list<Initializer*> initializers; // order *is* important85 std::list<Expression *> designators;98 std::list<Initializer*> initializers; // order *is* important 99 std::list<Expression *> designators; 86 100 }; 87 101 88 102 #endif // INITIALIZER_H 103 104 // Local Variables: // 105 // tab-width: 4 // 106 // mode: c++ // 107 // compile-command: "make install" // 108 // End: // -
translator/SynTree/Mutator.cc
ra32b204 r0dd3a2f 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 // Mutator.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:10:46 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 17 #include "Mutator.h" … … 14 29 15 30 ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) { 16 objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) );17 objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) );18 objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) );19 return objectDecl;31 objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) ); 32 objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) ); 33 objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) ); 34 return objectDecl; 20 35 } 21 36 22 37 DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) { 23 functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );24 mutateAll( functionDecl->get_oldDecls(), *this );25 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );26 return functionDecl;38 functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) ); 39 mutateAll( functionDecl->get_oldDecls(), *this ); 40 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 41 return functionDecl; 27 42 } 28 43 29 44 Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) { 30 mutateAll( aggregateDecl->get_parameters(), *this );31 mutateAll( aggregateDecl->get_members(), *this );32 return aggregateDecl;45 mutateAll( aggregateDecl->get_parameters(), *this ); 46 mutateAll( aggregateDecl->get_members(), *this ); 47 return aggregateDecl; 33 48 } 34 49 35 50 Declaration *Mutator::mutate( StructDecl *aggregateDecl ) { 36 handleAggregateDecl( aggregateDecl );37 return aggregateDecl;51 handleAggregateDecl( aggregateDecl ); 52 return aggregateDecl; 38 53 } 39 54 40 55 Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) { 41 handleAggregateDecl( aggregateDecl );42 return aggregateDecl;56 handleAggregateDecl( aggregateDecl ); 57 return aggregateDecl; 43 58 } 44 59 45 60 Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) { 46 handleAggregateDecl( aggregateDecl );47 return aggregateDecl;61 handleAggregateDecl( aggregateDecl ); 62 return aggregateDecl; 48 63 } 49 64 50 65 Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) { 51 handleAggregateDecl( aggregateDecl );52 return aggregateDecl;66 handleAggregateDecl( aggregateDecl ); 67 return aggregateDecl; 53 68 } 54 69 55 70 Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) { 56 mutateAll( typeDecl->get_parameters(), *this );57 mutateAll( typeDecl->get_assertions(), *this );58 typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) );59 return typeDecl;71 mutateAll( typeDecl->get_parameters(), *this ); 72 mutateAll( typeDecl->get_assertions(), *this ); 73 typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) ); 74 return typeDecl; 60 75 } 61 76 62 77 TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) { 63 handleNamedTypeDecl( typeDecl );64 return typeDecl;78 handleNamedTypeDecl( typeDecl ); 79 return typeDecl; 65 80 } 66 81 67 82 Declaration *Mutator::mutate( TypedefDecl *typeDecl ) { 68 handleNamedTypeDecl( typeDecl );69 return typeDecl;83 handleNamedTypeDecl( typeDecl ); 84 return typeDecl; 70 85 } 71 86 72 87 CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) { 73 mutateAll( compoundStmt->get_kids(), *this );74 return compoundStmt;88 mutateAll( compoundStmt->get_kids(), *this ); 89 return compoundStmt; 75 90 } 76 91 77 92 Statement *Mutator::mutate( ExprStmt *exprStmt ) { 78 exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );79 return exprStmt;93 exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) ); 94 return exprStmt; 80 95 } 81 96 82 97 Statement *Mutator::mutate( IfStmt *ifStmt ) { 83 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );84 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );85 ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) );86 return ifStmt;98 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 99 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); 100 ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) ); 101 return ifStmt; 87 102 } 88 103 89 104 Statement *Mutator::mutate( WhileStmt *whileStmt ) { 90 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );91 whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) );92 return whileStmt;105 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); 106 whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) ); 107 return whileStmt; 93 108 } 94 109 95 110 Statement *Mutator::mutate( ForStmt *forStmt ) { 96 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) );97 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );98 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );99 forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) );100 return forStmt;111 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) ); 112 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); 113 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); 114 forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) ); 115 return forStmt; 101 116 } 102 117 103 118 Statement *Mutator::mutate( SwitchStmt *switchStmt ) { 104 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );105 mutateAll( switchStmt->get_branches(), *this );106 return switchStmt;119 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 120 mutateAll( switchStmt->get_branches(), *this ); 121 return switchStmt; 107 122 } 108 123 109 124 Statement *Mutator::mutate( ChooseStmt *switchStmt ) { 110 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );111 mutateAll( switchStmt->get_branches(), *this );112 return switchStmt;125 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 126 mutateAll( switchStmt->get_branches(), *this ); 127 return switchStmt; 113 128 } 114 129 115 130 Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) { 116 return fallthruStmt;131 return fallthruStmt; 117 132 } 118 133 119 134 Statement *Mutator::mutate( CaseStmt *caseStmt ) { 120 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );121 mutateAll (caseStmt->get_statements(), *this );122 123 return caseStmt;135 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); 136 mutateAll (caseStmt->get_statements(), *this ); 137 138 return caseStmt; 124 139 } 125 140 126 141 Statement *Mutator::mutate( BranchStmt *branchStmt ) { 127 return branchStmt;142 return branchStmt; 128 143 } 129 144 130 145 Statement *Mutator::mutate( ReturnStmt *returnStmt ) { 131 returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );132 return returnStmt;146 returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) ); 147 return returnStmt; 133 148 } 134 149 135 150 Statement *Mutator::mutate( TryStmt *tryStmt ) { 136 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );137 mutateAll( tryStmt->get_catchers(), *this );138 return tryStmt;151 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); 152 mutateAll( tryStmt->get_catchers(), *this ); 153 return tryStmt; 139 154 } 140 155 141 156 Statement *Mutator::mutate( CatchStmt *catchStmt ) { 142 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );143 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );144 return catchStmt;157 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 158 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); 159 return catchStmt; 145 160 } 146 161 147 162 Statement *Mutator::mutate( FinallyStmt *finalStmt ) { 148 finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );149 return finalStmt;163 finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) ); 164 return finalStmt; 150 165 } 151 166 152 167 NullStmt *Mutator::mutate( NullStmt *nullStmt ) { 153 return nullStmt;168 return nullStmt; 154 169 } 155 170 156 171 Statement *Mutator::mutate( DeclStmt *declStmt ) { 157 declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );158 return declStmt;172 declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) ); 173 return declStmt; 159 174 } 160 175 161 176 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 162 mutateAll( applicationExpr->get_results(), *this );163 applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );164 mutateAll( applicationExpr->get_args(), *this );165 return applicationExpr;177 mutateAll( applicationExpr->get_results(), *this ); 178 applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) ); 179 mutateAll( applicationExpr->get_args(), *this ); 180 return applicationExpr; 166 181 } 167 182 168 183 Expression *Mutator::mutate( UntypedExpr *untypedExpr ) { 169 mutateAll( untypedExpr->get_results(), *this );170 mutateAll( untypedExpr->get_args(), *this );171 return untypedExpr;184 mutateAll( untypedExpr->get_results(), *this ); 185 mutateAll( untypedExpr->get_args(), *this ); 186 return untypedExpr; 172 187 } 173 188 174 189 Expression *Mutator::mutate( NameExpr *nameExpr ) { 175 mutateAll( nameExpr->get_results(), *this );176 return nameExpr;190 mutateAll( nameExpr->get_results(), *this ); 191 return nameExpr; 177 192 } 178 193 179 194 Expression *Mutator::mutate( AddressExpr *addressExpr ) { 180 mutateAll( addressExpr->get_results(), *this );181 addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );182 return addressExpr;195 mutateAll( addressExpr->get_results(), *this ); 196 addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) ); 197 return addressExpr; 183 198 } 184 199 185 200 Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) { 186 mutateAll( labelAddressExpr->get_results(), *this );187 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );188 return labelAddressExpr;201 mutateAll( labelAddressExpr->get_results(), *this ); 202 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) ); 203 return labelAddressExpr; 189 204 } 190 205 191 206 Expression *Mutator::mutate( CastExpr *castExpr ) { 192 mutateAll( castExpr->get_results(), *this );193 castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );194 return castExpr;207 mutateAll( castExpr->get_results(), *this ); 208 castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) ); 209 return castExpr; 195 210 } 196 211 197 212 Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) { 198 mutateAll( memberExpr->get_results(), *this );199 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );200 return memberExpr;213 mutateAll( memberExpr->get_results(), *this ); 214 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 215 return memberExpr; 201 216 } 202 217 203 218 Expression *Mutator::mutate( MemberExpr *memberExpr ) { 204 mutateAll( memberExpr->get_results(), *this );205 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );206 return memberExpr;219 mutateAll( memberExpr->get_results(), *this ); 220 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 221 return memberExpr; 207 222 } 208 223 209 224 Expression *Mutator::mutate( VariableExpr *variableExpr ) { 210 mutateAll( variableExpr->get_results(), *this );211 return variableExpr;225 mutateAll( variableExpr->get_results(), *this ); 226 return variableExpr; 212 227 } 213 228 214 229 Expression *Mutator::mutate( ConstantExpr *constantExpr ) { 215 mutateAll( constantExpr->get_results(), *this );230 mutateAll( constantExpr->get_results(), *this ); 216 231 // maybeMutate( constantExpr->get_constant(), *this ) 217 return constantExpr;232 return constantExpr; 218 233 } 219 234 220 235 Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) { 221 mutateAll( sizeofExpr->get_results(), *this );222 if ( sizeofExpr->get_isType() ) {223 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );224 } else {225 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );226 }227 return sizeofExpr;236 mutateAll( sizeofExpr->get_results(), *this ); 237 if ( sizeofExpr->get_isType() ) { 238 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) ); 239 } else { 240 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) ); 241 } 242 return sizeofExpr; 228 243 } 229 244 230 245 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 231 mutateAll( attrExpr->get_results(), *this );232 if ( attrExpr->get_isType() ) {233 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );234 } else {235 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );236 }237 return attrExpr;246 mutateAll( attrExpr->get_results(), *this ); 247 if ( attrExpr->get_isType() ) { 248 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) ); 249 } else { 250 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) ); 251 } 252 return attrExpr; 238 253 } 239 254 240 255 Expression *Mutator::mutate( LogicalExpr *logicalExpr ) { 241 mutateAll( logicalExpr->get_results(), *this );242 logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );243 logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );244 return logicalExpr;256 mutateAll( logicalExpr->get_results(), *this ); 257 logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) ); 258 logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) ); 259 return logicalExpr; 245 260 } 246 261 247 262 Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) { 248 mutateAll( conditionalExpr->get_results(), *this );249 conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );250 conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );251 conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) );252 return conditionalExpr;263 mutateAll( conditionalExpr->get_results(), *this ); 264 conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) ); 265 conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) ); 266 conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) ); 267 return conditionalExpr; 253 268 } 254 269 255 270 Expression *Mutator::mutate( CommaExpr *commaExpr ) { 256 mutateAll( commaExpr->get_results(), *this );257 commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );258 commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );259 return commaExpr;271 mutateAll( commaExpr->get_results(), *this ); 272 commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) ); 273 commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) ); 274 return commaExpr; 260 275 } 261 276 262 277 Expression *Mutator::mutate( TupleExpr *tupleExpr ) { 263 mutateAll( tupleExpr->get_results(), *this );264 mutateAll( tupleExpr->get_exprs(), *this );265 return tupleExpr;278 mutateAll( tupleExpr->get_results(), *this ); 279 mutateAll( tupleExpr->get_exprs(), *this ); 280 return tupleExpr; 266 281 } 267 282 268 283 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) { 269 mutateAll( tupleExpr->get_results(), *this );270 mutateAll( tupleExpr->get_exprs(), *this );271 return tupleExpr;284 mutateAll( tupleExpr->get_results(), *this ); 285 mutateAll( tupleExpr->get_exprs(), *this ); 286 return tupleExpr; 272 287 } 273 288 274 289 Expression *Mutator::mutate( TypeExpr *typeExpr ) { 275 mutateAll( typeExpr->get_results(), *this );276 typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );277 return typeExpr;290 mutateAll( typeExpr->get_results(), *this ); 291 typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) ); 292 return typeExpr; 278 293 } 279 294 280 295 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 281 mutateAll( valofExpr->get_results(), *this );282 return valofExpr;296 mutateAll( valofExpr->get_results(), *this ); 297 return valofExpr; 283 298 } 284 299 285 300 Type *Mutator::mutate( VoidType *voidType ) { 286 mutateAll( voidType->get_forall(), *this );287 return voidType;301 mutateAll( voidType->get_forall(), *this ); 302 return voidType; 288 303 } 289 304 290 305 Type *Mutator::mutate( BasicType *basicType ) { 291 mutateAll( basicType->get_forall(), *this );292 return basicType;306 mutateAll( basicType->get_forall(), *this ); 307 return basicType; 293 308 } 294 309 295 310 Type *Mutator::mutate( PointerType *pointerType ) { 296 mutateAll( pointerType->get_forall(), *this );297 pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );298 return pointerType;311 mutateAll( pointerType->get_forall(), *this ); 312 pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) ); 313 return pointerType; 299 314 } 300 315 301 316 Type *Mutator::mutate( ArrayType *arrayType ) { 302 mutateAll( arrayType->get_forall(), *this );303 arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) );304 arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) );305 return arrayType;317 mutateAll( arrayType->get_forall(), *this ); 318 arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) ); 319 arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) ); 320 return arrayType; 306 321 } 307 322 308 323 Type *Mutator::mutate( FunctionType *functionType ) { 309 mutateAll( functionType->get_forall(), *this );310 mutateAll( functionType->get_returnVals(), *this );311 mutateAll( functionType->get_parameters(), *this );312 return functionType;324 mutateAll( functionType->get_forall(), *this ); 325 mutateAll( functionType->get_returnVals(), *this ); 326 mutateAll( functionType->get_parameters(), *this ); 327 return functionType; 313 328 } 314 329 315 330 Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) { 316 mutateAll( aggregateUseType->get_forall(), *this );317 mutateAll( aggregateUseType->get_parameters(), *this );318 return aggregateUseType;331 mutateAll( aggregateUseType->get_forall(), *this ); 332 mutateAll( aggregateUseType->get_parameters(), *this ); 333 return aggregateUseType; 319 334 } 320 335 321 336 Type *Mutator::mutate( StructInstType *aggregateUseType ) { 322 handleReferenceToType( aggregateUseType );323 return aggregateUseType;337 handleReferenceToType( aggregateUseType ); 338 return aggregateUseType; 324 339 } 325 340 326 341 Type *Mutator::mutate( UnionInstType *aggregateUseType ) { 327 handleReferenceToType( aggregateUseType );328 return aggregateUseType;342 handleReferenceToType( aggregateUseType ); 343 return aggregateUseType; 329 344 } 330 345 331 346 Type *Mutator::mutate( EnumInstType *aggregateUseType ) { 332 handleReferenceToType( aggregateUseType );333 return aggregateUseType;347 handleReferenceToType( aggregateUseType ); 348 return aggregateUseType; 334 349 } 335 350 336 351 Type *Mutator::mutate( ContextInstType *aggregateUseType ) { 337 handleReferenceToType( aggregateUseType );338 mutateAll( aggregateUseType->get_members(), *this );339 return aggregateUseType;352 handleReferenceToType( aggregateUseType ); 353 mutateAll( aggregateUseType->get_members(), *this ); 354 return aggregateUseType; 340 355 } 341 356 342 357 Type *Mutator::mutate( TypeInstType *aggregateUseType ) { 343 handleReferenceToType( aggregateUseType );344 return aggregateUseType;358 handleReferenceToType( aggregateUseType ); 359 return aggregateUseType; 345 360 } 346 361 347 362 Type *Mutator::mutate( TupleType *tupleType ) { 348 mutateAll( tupleType->get_forall(), *this );349 mutateAll( tupleType->get_types(), *this );350 return tupleType;363 mutateAll( tupleType->get_forall(), *this ); 364 mutateAll( tupleType->get_types(), *this ); 365 return tupleType; 351 366 } 352 367 353 368 Type *Mutator::mutate( TypeofType *typeofType ) { 354 assert( typeofType->get_expr() );355 typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );356 return typeofType;369 assert( typeofType->get_expr() ); 370 typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) ); 371 return typeofType; 357 372 } 358 373 359 374 Type *Mutator::mutate( AttrType *attrType ) { 360 if ( attrType->get_isType() ) {361 assert( attrType->get_type() );362 attrType->set_type( attrType->get_type()->acceptMutator( *this ) );363 } else {364 assert( attrType->get_expr() );365 attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );366 }367 return attrType;375 if ( attrType->get_isType() ) { 376 assert( attrType->get_type() ); 377 attrType->set_type( attrType->get_type()->acceptMutator( *this ) ); 378 } else { 379 assert( attrType->get_expr() ); 380 attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) ); 381 } 382 return attrType; 368 383 } 369 384 370 385 Initializer *Mutator::mutate( SingleInit *singleInit ) { 371 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );372 return singleInit;386 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); 387 return singleInit; 373 388 } 374 389 375 390 Initializer *Mutator::mutate( ListInit *listInit ) { 376 mutateAll( listInit->get_designators(), *this );377 mutateAll( listInit->get_initializers(), *this );378 return listInit;391 mutateAll( listInit->get_designators(), *this ); 392 mutateAll( listInit->get_initializers(), *this ); 393 return listInit; 379 394 } 380 395 381 396 Subrange *Mutator::mutate( Subrange *subrange ) { 382 return subrange;397 return subrange; 383 398 } 384 399 385 400 Constant *Mutator::mutate( Constant *constant ) { 386 return constant; 387 } 401 return constant; 402 } 403 404 // Local Variables: // 405 // tab-width: 4 // 406 // mode: c++ // 407 // compile-command: "make install" // 408 // End: // -
translator/SynTree/Mutator.h
ra32b204 r0dd3a2f 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 // Mutator.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:12:28 2015 13 // Update Count : 3 14 // 1 15 #include <cassert> 2 16 … … 4 18 #include "SemanticError.h" 5 19 6 #ifndef SYNTREE_MUTATOR_H7 #define SYNTREE_MUTATOR_H20 #ifndef MUTATOR_H 21 #define MUTATOR_H 8 22 9 23 class Mutator { 10 24 protected: 11 Mutator();12 virtual ~Mutator();25 Mutator(); 26 virtual ~Mutator(); 13 27 public: 14 virtual ObjectDecl* mutate( ObjectDecl *objectDecl );15 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl );16 virtual Declaration* mutate( StructDecl *aggregateDecl );17 virtual Declaration* mutate( UnionDecl *aggregateDecl );18 virtual Declaration* mutate( EnumDecl *aggregateDecl );19 virtual Declaration* mutate( ContextDecl *aggregateDecl );20 virtual TypeDecl* mutate( TypeDecl *typeDecl );21 virtual Declaration* mutate( TypedefDecl *typeDecl );28 virtual ObjectDecl* mutate( ObjectDecl *objectDecl ); 29 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ); 30 virtual Declaration* mutate( StructDecl *aggregateDecl ); 31 virtual Declaration* mutate( UnionDecl *aggregateDecl ); 32 virtual Declaration* mutate( EnumDecl *aggregateDecl ); 33 virtual Declaration* mutate( ContextDecl *aggregateDecl ); 34 virtual TypeDecl* mutate( TypeDecl *typeDecl ); 35 virtual Declaration* mutate( TypedefDecl *typeDecl ); 22 36 23 virtual CompoundStmt* mutate( CompoundStmt *compoundStmt );24 virtual Statement* mutate( ExprStmt *exprStmt );25 virtual Statement* mutate( IfStmt *ifStmt );26 virtual Statement* mutate( WhileStmt *whileStmt );27 virtual Statement* mutate( ForStmt *forStmt );28 virtual Statement* mutate( SwitchStmt *switchStmt );29 virtual Statement* mutate( ChooseStmt *chooseStmt );30 virtual Statement* mutate( FallthruStmt *fallthruStmt );31 virtual Statement* mutate( CaseStmt *caseStmt );32 virtual Statement* mutate( BranchStmt *branchStmt );33 virtual Statement* mutate( ReturnStmt *returnStmt );34 virtual Statement* mutate( TryStmt *returnStmt );35 virtual Statement* mutate( CatchStmt *catchStmt );36 virtual Statement* mutate( FinallyStmt *catchStmt );37 virtual NullStmt* mutate( NullStmt *nullStmt );38 virtual Statement* mutate( DeclStmt *declStmt );37 virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ); 38 virtual Statement* mutate( ExprStmt *exprStmt ); 39 virtual Statement* mutate( IfStmt *ifStmt ); 40 virtual Statement* mutate( WhileStmt *whileStmt ); 41 virtual Statement* mutate( ForStmt *forStmt ); 42 virtual Statement* mutate( SwitchStmt *switchStmt ); 43 virtual Statement* mutate( ChooseStmt *chooseStmt ); 44 virtual Statement* mutate( FallthruStmt *fallthruStmt ); 45 virtual Statement* mutate( CaseStmt *caseStmt ); 46 virtual Statement* mutate( BranchStmt *branchStmt ); 47 virtual Statement* mutate( ReturnStmt *returnStmt ); 48 virtual Statement* mutate( TryStmt *returnStmt ); 49 virtual Statement* mutate( CatchStmt *catchStmt ); 50 virtual Statement* mutate( FinallyStmt *catchStmt ); 51 virtual NullStmt* mutate( NullStmt *nullStmt ); 52 virtual Statement* mutate( DeclStmt *declStmt ); 39 53 40 virtual Expression* mutate( ApplicationExpr *applicationExpr );41 virtual Expression* mutate( UntypedExpr *untypedExpr );42 virtual Expression* mutate( NameExpr *nameExpr );43 virtual Expression* mutate( AddressExpr *castExpr );44 virtual Expression* mutate( LabelAddressExpr *labAddressExpr );45 virtual Expression* mutate( CastExpr *castExpr );46 virtual Expression* mutate( UntypedMemberExpr *memberExpr );47 virtual Expression* mutate( MemberExpr *memberExpr );48 virtual Expression* mutate( VariableExpr *variableExpr );49 virtual Expression* mutate( ConstantExpr *constantExpr );50 virtual Expression* mutate( SizeofExpr *sizeofExpr );51 virtual Expression* mutate( AttrExpr *attrExpr );52 virtual Expression* mutate( LogicalExpr *logicalExpr );53 virtual Expression* mutate( ConditionalExpr *conditionalExpr );54 virtual Expression* mutate( CommaExpr *commaExpr );55 virtual Expression* mutate( TupleExpr *tupleExpr );56 virtual Expression* mutate( SolvedTupleExpr *tupleExpr );57 virtual Expression* mutate( TypeExpr *typeExpr );58 virtual Expression* mutate( UntypedValofExpr *valofExpr );54 virtual Expression* mutate( ApplicationExpr *applicationExpr ); 55 virtual Expression* mutate( UntypedExpr *untypedExpr ); 56 virtual Expression* mutate( NameExpr *nameExpr ); 57 virtual Expression* mutate( AddressExpr *castExpr ); 58 virtual Expression* mutate( LabelAddressExpr *labAddressExpr ); 59 virtual Expression* mutate( CastExpr *castExpr ); 60 virtual Expression* mutate( UntypedMemberExpr *memberExpr ); 61 virtual Expression* mutate( MemberExpr *memberExpr ); 62 virtual Expression* mutate( VariableExpr *variableExpr ); 63 virtual Expression* mutate( ConstantExpr *constantExpr ); 64 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 65 virtual Expression* mutate( AttrExpr *attrExpr ); 66 virtual Expression* mutate( LogicalExpr *logicalExpr ); 67 virtual Expression* mutate( ConditionalExpr *conditionalExpr ); 68 virtual Expression* mutate( CommaExpr *commaExpr ); 69 virtual Expression* mutate( TupleExpr *tupleExpr ); 70 virtual Expression* mutate( SolvedTupleExpr *tupleExpr ); 71 virtual Expression* mutate( TypeExpr *typeExpr ); 72 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 59 73 60 virtual Type* mutate( VoidType *basicType );61 virtual Type* mutate( BasicType *basicType );62 virtual Type* mutate( PointerType *pointerType );63 virtual Type* mutate( ArrayType *arrayType );64 virtual Type* mutate( FunctionType *functionType );65 virtual Type* mutate( StructInstType *aggregateUseType );66 virtual Type* mutate( UnionInstType *aggregateUseType );67 virtual Type* mutate( EnumInstType *aggregateUseType );68 virtual Type* mutate( ContextInstType *aggregateUseType );69 virtual Type* mutate( TypeInstType *aggregateUseType );70 virtual Type* mutate( TupleType *tupleType );71 virtual Type* mutate( TypeofType *typeofType );72 virtual Type* mutate( AttrType *attrType );74 virtual Type* mutate( VoidType *basicType ); 75 virtual Type* mutate( BasicType *basicType ); 76 virtual Type* mutate( PointerType *pointerType ); 77 virtual Type* mutate( ArrayType *arrayType ); 78 virtual Type* mutate( FunctionType *functionType ); 79 virtual Type* mutate( StructInstType *aggregateUseType ); 80 virtual Type* mutate( UnionInstType *aggregateUseType ); 81 virtual Type* mutate( EnumInstType *aggregateUseType ); 82 virtual Type* mutate( ContextInstType *aggregateUseType ); 83 virtual Type* mutate( TypeInstType *aggregateUseType ); 84 virtual Type* mutate( TupleType *tupleType ); 85 virtual Type* mutate( TypeofType *typeofType ); 86 virtual Type* mutate( AttrType *attrType ); 73 87 74 virtual Initializer* mutate( SingleInit *singleInit );75 virtual Initializer* mutate( ListInit *listInit );88 virtual Initializer* mutate( SingleInit *singleInit ); 89 virtual Initializer* mutate( ListInit *listInit ); 76 90 77 virtual Subrange *mutate( Subrange *subrange );91 virtual Subrange *mutate( Subrange *subrange ); 78 92 79 virtual Constant *mutate( Constant *constant );93 virtual Constant *mutate( Constant *constant ); 80 94 private: 81 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl );82 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl );83 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType );95 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl ); 96 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl ); 97 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType ); 84 98 }; 85 99 86 100 template< typename TreeType, typename MutatorType > 87 101 inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) { 88 if ( tree ) {89 TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );90 assert( newnode );91 return newnode;102 if ( tree ) { 103 TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) ); 104 assert( newnode ); 105 return newnode; 92 106 /// return tree->acceptMutator( mutator ); 93 } else {94 return 0;95 } 107 } else { 108 return 0; 109 } // if 96 110 } 97 111 98 112 template< typename Container, typename MutatorType > 99 113 inline void mutateAll( Container &container, MutatorType &mutator ) { 100 SemanticError errors;101 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {102 try {103 if ( *i ) {114 SemanticError errors; 115 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 116 try { 117 if ( *i ) { 104 118 /// *i = (*i)->acceptMutator( mutator ); 105 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );106 assert( *i );107 }108 } catch( SemanticError &e ) {109 errors.append( e );110 }111 } 112 if ( ! errors.isEmpty() ) {113 throw errors;114 } 119 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); 120 assert( *i ); 121 } // if 122 } catch( SemanticError &e ) { 123 errors.append( e ); 124 } // try 125 } // for 126 if ( ! errors.isEmpty() ) { 127 throw errors; 128 } // if 115 129 } 116 130 117 #endif // SYNTREE_MUTATOR_H131 #endif // MUTATOR_H 118 132 119 133 // Local Variables: // 134 // tab-width: 4 // 120 135 // mode: c++ // 121 // End: // 136 // compile-command: "make install" // 137 // End: // -
translator/SynTree/NamedTypeDecl.cc
ra32b204 r0dd3a2f 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 // NamedTypeDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:13:19 2015 13 // Update Count : 1 14 // 15 1 16 #include "Declaration.h" 2 17 #include "Type.h" 3 18 #include "utility.h" 4 19 5 6 20 NamedTypeDecl::NamedTypeDecl( const std::string &name, StorageClass sc, Type *base ) 7 : Parent( name, sc, LinkageSpec::Cforall ), base( base ) 8 {} 21 : Parent( name, sc, LinkageSpec::Cforall ), base( base ) {} 9 22 10 23 NamedTypeDecl::NamedTypeDecl( const TypeDecl &other ) 11 : Parent( other ), base( maybeClone( other.base ) ) 12 { 13 cloneAll( other.parameters, parameters ); 14 cloneAll( other.assertions, assertions ); 24 : Parent( other ), base( maybeClone( other.base ) ) { 25 cloneAll( other.parameters, parameters ); 26 cloneAll( other.assertions, assertions ); 15 27 } 16 28 17 29 NamedTypeDecl::~NamedTypeDecl() { 18 delete base;19 deleteAll( parameters );20 deleteAll( assertions );30 delete base; 31 deleteAll( parameters ); 32 deleteAll( assertions ); 21 33 } 22 34 23 35 void NamedTypeDecl::print( std::ostream &os, int indent ) const { 24 using namespace std;25 26 if ( get_name() != "" ) {27 os << get_name() << ": a ";28 } // if29 if ( get_storageClass() != NoStorageClass ) {30 os << storageClassName[ get_storageClass() ] << ' ';31 } // if32 os << typeString();33 if ( base ) {34 os << " for ";35 base->print( os, indent );36 } // if37 if ( ! parameters.empty() ) {38 os << endl << string( indent, ' ' ) << "with parameters" << endl;39 printAll( parameters, os, indent+2 );40 } // if41 if ( ! assertions.empty() ) {42 os << endl << string( indent, ' ' ) << "with assertions" << endl;43 printAll( assertions, os, indent+2 );44 } // if36 using namespace std; 37 38 if ( get_name() != "" ) { 39 os << get_name() << ": a "; 40 } // if 41 if ( get_storageClass() != NoStorageClass ) { 42 os << storageClassName[ get_storageClass() ] << ' '; 43 } // if 44 os << typeString(); 45 if ( base ) { 46 os << " for "; 47 base->print( os, indent ); 48 } // if 49 if ( ! parameters.empty() ) { 50 os << endl << string( indent, ' ' ) << "with parameters" << endl; 51 printAll( parameters, os, indent+2 ); 52 } // if 53 if ( ! assertions.empty() ) { 54 os << endl << string( indent, ' ' ) << "with assertions" << endl; 55 printAll( assertions, os, indent+2 ); 56 } // if 45 57 } 46 58 47 59 void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { 48 using namespace std;49 50 if ( get_name() != "" ) {51 os << get_name() << ": a ";52 } // if53 if ( get_storageClass() != NoStorageClass ) {54 os << storageClassName[ get_storageClass() ] << ' ';55 } // if56 os << typeString();57 if ( base ) {58 os << " for ";59 base->print( os, indent );60 } // if61 if ( ! parameters.empty() ) {62 os << endl << string( indent, ' ' ) << "with parameters" << endl;63 printAll( parameters, os, indent+2 );64 } // if60 using namespace std; 61 62 if ( get_name() != "" ) { 63 os << get_name() << ": a "; 64 } // if 65 if ( get_storageClass() != NoStorageClass ) { 66 os << storageClassName[ get_storageClass() ] << ' '; 67 } // if 68 os << typeString(); 69 if ( base ) { 70 os << " for "; 71 base->print( os, indent ); 72 } // if 73 if ( ! parameters.empty() ) { 74 os << endl << string( indent, ' ' ) << "with parameters" << endl; 75 printAll( parameters, os, indent+2 ); 76 } // if 65 77 } 66 78 67 79 std::string TypedefDecl::typeString() const { return "typedef"; } 80 81 // Local Variables: // 82 // tab-width: 4 // 83 // mode: c++ // 84 // compile-command: "make install" // 85 // End: // -
translator/SynTree/ObjectDecl.cc
ra32b204 r0dd3a2f 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 // ObjectDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:14:18 2015 13 // Update Count : 2 14 // 15 1 16 #include "Declaration.h" 2 17 #include "Type.h" … … 5 20 #include "utility.h" 6 21 7 8 22 ObjectDecl::ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ) 9 : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {23 : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) { 10 24 } 11 25 12 26 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 13 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {27 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { 14 28 } 15 29 16 30 ObjectDecl::~ObjectDecl() { 17 delete type;18 delete init;19 delete bitfieldWidth;31 delete type; 32 delete init; 33 delete bitfieldWidth; 20 34 } 21 35 22 36 void ObjectDecl::print( std::ostream &os, int indent ) const { 23 if ( get_name() != "" ) {24 os << get_name() << ": a ";25 } 37 if ( get_name() != "" ) { 38 os << get_name() << ": a "; 39 } // if 26 40 27 if ( get_linkage() != LinkageSpec::Cforall ) {28 os << LinkageSpec::toString( get_linkage() ) << " ";29 } 41 if ( get_linkage() != LinkageSpec::Cforall ) { 42 os << LinkageSpec::toString( get_linkage() ) << " "; 43 } // if 30 44 31 if ( get_storageClass() != NoStorageClass ) {32 os << storageClassName[ get_storageClass() ] << ' ';33 } 45 if ( get_storageClass() != NoStorageClass ) { 46 os << storageClassName[ get_storageClass() ] << ' '; 47 } // if 34 48 35 if ( get_type() ) {36 get_type()->print( os, indent );37 } else {38 os << "untyped entity ";39 } 49 if ( get_type() ) { 50 get_type()->print( os, indent ); 51 } else { 52 os << "untyped entity "; 53 } // if 40 54 41 if ( init ) {42 os << "with initializer ";43 init->print( os, indent );44 } 55 if ( init ) { 56 os << "with initializer "; 57 init->print( os, indent ); 58 } // if 45 59 46 if ( bitfieldWidth ) {47 os << "with bitfield width ";48 bitfieldWidth->print( os );49 } 60 if ( bitfieldWidth ) { 61 os << "with bitfield width "; 62 bitfieldWidth->print( os ); 63 } // if 50 64 } 51 65 52 66 void ObjectDecl::printShort( std::ostream &os, int indent ) const { 53 if ( get_name() != "" ) {54 os << get_name() << ": a ";55 } 67 if ( get_name() != "" ) { 68 os << get_name() << ": a "; 69 } // if 56 70 57 if ( get_storageClass() != NoStorageClass ) {58 os << storageClassName[ get_storageClass() ] << ' ';59 } 71 if ( get_storageClass() != NoStorageClass ) { 72 os << storageClassName[ get_storageClass() ] << ' '; 73 } // if 60 74 61 if ( get_type() ) {62 get_type()->print( os, indent );63 } else {64 os << "untyped entity ";65 } 75 if ( get_type() ) { 76 get_type()->print( os, indent ); 77 } else { 78 os << "untyped entity "; 79 } // if 66 80 67 if ( bitfieldWidth ) {68 os << "with bitfield width ";69 bitfieldWidth->print( os );70 } 81 if ( bitfieldWidth ) { 82 os << "with bitfield width "; 83 bitfieldWidth->print( os ); 84 } // if 71 85 } 86 87 // Local Variables: // 88 // tab-width: 4 // 89 // mode: c++ // 90 // compile-command: "make install" // 91 // End: // -
translator/SynTree/PointerType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: PointerType.cc,v 1.8 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // PointerType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:15:16 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" … … 10 18 #include "utility.h" 11 19 12 13 20 PointerType::PointerType( const Type::Qualifiers &tq, Type *base ) 14 : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) 15 { 16 base->set_isLvalue( false ); 21 : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) { 22 base->set_isLvalue( false ); 17 23 } 18 24 19 25 PointerType::PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ) 20 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) 21 { 22 base->set_isLvalue( false ); 26 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) { 27 base->set_isLvalue( false ); 23 28 } 24 29 25 30 PointerType::PointerType( const PointerType &other ) 26 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 27 isVarLen( other.isVarLen ), isStatic( other.isStatic ) 28 { 31 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 32 isVarLen( other.isVarLen ), isStatic( other.isStatic ) { 29 33 } 30 34 31 PointerType::~PointerType() 32 { 33 delete base; 34 delete dimension; 35 PointerType::~PointerType() { 36 delete base; 37 delete dimension; 35 38 } 36 39 37 void 38 PointerType::print( std::ostream &os, int indent ) const 39 { 40 Type::print( os, indent ); 41 os << "pointer to "; 42 if ( isStatic ) { 43 os << "static "; 44 } 45 if ( isVarLen ) { 46 os << "variable length array of "; 47 } else if ( dimension ) { 48 os << "array of "; 49 dimension->print( os, indent ); 50 } 51 if ( base ) { 52 base->print( os, indent ); 53 } 40 void PointerType::print( std::ostream &os, int indent ) const { 41 Type::print( os, indent ); 42 os << "pointer to "; 43 if ( isStatic ) { 44 os << "static "; 45 } // if 46 if ( isVarLen ) { 47 os << "variable length array of "; 48 } else if ( dimension ) { 49 os << "array of "; 50 dimension->print( os, indent ); 51 } // if 52 if ( base ) { 53 base->print( os, indent ); 54 } // if 54 55 } 55 56 57 // Local Variables: // 58 // tab-width: 4 // 59 // mode: c++ // 60 // compile-command: "make install" // 61 // End: // -
translator/SynTree/ReferenceToType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: ReferenceToType.cc,v 1.16 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // ReferenceToType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:49:00 2015 13 // Update Count : 2 14 // 7 15 8 16 #include <string> … … 15 23 #include "utility.h" 16 24 17 18 ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) 19 : Type( tq ), name( name ) 20 { 25 ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) { 21 26 } 22 27 23 ReferenceToType::ReferenceToType( const ReferenceToType &other ) 24 : Type( other ), name( other.name ) 25 { 28 ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { 26 29 cloneAll( other.parameters, parameters ); 27 30 } 28 31 29 ReferenceToType::~ReferenceToType() 30 { 32 ReferenceToType::~ReferenceToType() { 31 33 deleteAll( parameters ); 32 34 } 33 35 34 void 35 ReferenceToType::print( std::ostream &os, int indent ) const 36 { 36 void ReferenceToType::print( std::ostream &os, int indent ) const { 37 37 using std::endl; 38 38 … … 40 40 os << "instance of " << typeString() << " " << name << " "; 41 41 if ( ! parameters.empty() ) { 42 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;43 printAll( parameters, os, indent+2 );44 } 42 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 43 printAll( parameters, os, indent+2 ); 44 } // if 45 45 } 46 46 47 47 namespace { 48 49 void 50 doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) 51 {52 std::list< Declaration* > found;53 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 54 if ( (*i)->get_name() == name ) {55 found.push_back( *i);48 void doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) { 49 std::list< Declaration* > found; 50 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 51 if ( (*i)->get_name() == name ) { 52 found.push_back( *i ); 53 } // if 54 } // for 55 applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) ); 56 56 } 57 }58 applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );59 }60 61 57 } // namespace 62 58 63 59 std::string StructInstType::typeString() const { return "struct"; } 64 60 65 void 66 StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const 67 { 61 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 68 62 assert( baseStruct ); 69 63 doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); … … 72 66 std::string UnionInstType::typeString() const { return "union"; } 73 67 74 void 75 UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const 76 { 68 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 77 69 assert( baseUnion ); 78 70 doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); … … 83 75 std::string ContextInstType::typeString() const { return "context"; } 84 76 85 ContextInstType::ContextInstType( const ContextInstType &other ) 86 : Parent( other ) 87 { 77 ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) { 88 78 cloneAll( other.members, members ); 89 79 } 90 80 91 ContextInstType::~ContextInstType() 92 { 81 ContextInstType::~ContextInstType() { 93 82 deleteAll( members ); 94 83 } 95 84 96 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) 97 { 85 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { 98 86 set_baseType( baseType ); 99 87 } 100 88 101 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) 102 { 89 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { 103 90 } 104 91 105 void TypeInstType::set_baseType( TypeDecl *newValue ) 106 { 92 void TypeInstType::set_baseType( TypeDecl *newValue ) { 107 93 baseType = newValue; 108 94 isFtype = newValue->get_kind() == TypeDecl::Ftype; … … 111 97 std::string TypeInstType::typeString() const { return "type"; } 112 98 113 void 114 TypeInstType::print( std::ostream &os, int indent ) const 115 { 99 void TypeInstType::print( std::ostream &os, int indent ) const { 116 100 using std::endl; 117 101 … … 119 103 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) "; 120 104 if ( ! parameters.empty() ) { 121 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;122 printAll( parameters, os, indent+2 );123 } 105 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 106 printAll( parameters, os, indent+2 ); 107 } // if 124 108 } 125 109 110 // Local Variables: // 111 // tab-width: 4 // 112 // mode: c++ // 113 // compile-command: "make install" // 114 // End: // -
translator/SynTree/Statement.cc
ra32b204 r0dd3a2f 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 // Statement.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:55:19 2015 13 // Update Count : 2 14 // 15 1 16 #include <functional> 2 17 #include <algorithm> … … 13 28 using std::endl; 14 29 15 16 Statement::Statement(std::list<Label> _labels): 17 labels(_labels) {} 18 19 void Statement::print(std::ostream &, int indent) {} 30 Statement::Statement( std::list<Label> _labels ) : labels(_labels ) {} 31 32 void Statement::print( std::ostream &, int indent ) {} 20 33 21 34 Statement::~Statement() {} 22 35 23 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ): 24 Statement(_labels), expr(_expr) {} 36 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement(_labels ), expr(_expr ) {} 25 37 26 38 ExprStmt::~ExprStmt() {} 27 39 28 40 void ExprStmt::print( std::ostream &os, int indent ) { 29 os << "\r" << string(indent, ' ') << "Expression Statement:" << endl;30 expr->print(os, indent + 2);41 os << "\r" << string(indent, ' ') << "Expression Statement:" << endl; 42 expr->print( os, indent + 2 ); 31 43 } 32 44 33 45 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 34 46 35 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) 36 throw (SemanticError) : 37 Statement(labels), target(_target), type(_type) 38 { 39 //actually this is a syntactic error signaled by the parser 40 if (type == BranchStmt::Goto && target.size() == 0) 41 throw SemanticError("goto without target"); 42 } 43 44 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type) 45 throw (SemanticError) : 46 Statement(labels), computedTarget(_computedTarget), type(_type) 47 { 48 if (type != BranchStmt::Goto || computedTarget == 0) 49 throw SemanticError("Computed target not valid in branch statement"); 47 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) : 48 Statement( labels ), target(_target ), type(_type ) { 49 //actually this is a syntactic error signaled by the parser 50 if ( type == BranchStmt::Goto && target.size() == 0 ) 51 throw SemanticError("goto without target"); 52 } 53 54 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) : 55 Statement( labels ), computedTarget(_computedTarget ), type(_type ) { 56 if ( type != BranchStmt::Goto || computedTarget == 0 ) 57 throw SemanticError("Computed target not valid in branch statement"); 50 58 } 51 59 52 60 void BranchStmt::print( std::ostream &os, int indent ){ 53 os << "\r" << string(indent, ' ') << "Branch (" << brType[type] << ")" << endl ; 54 } 55 56 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : 57 Statement( labels ), expr( _expr ), isThrow( throwP ) {} 61 os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ; 62 } 63 64 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {} 58 65 59 66 ReturnStmt::~ReturnStmt() { 60 delete expr; 61 } 62 63 void ReturnStmt::print( std::ostream &os, int indent ){ 64 os << "\r" << std::string(indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 65 if (expr != 0) expr->print(os); 66 os << endl; 67 } 68 67 delete expr; 68 } 69 70 void ReturnStmt::print( std::ostream &os, int indent ) { 71 os << "\r" << std::string( indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 72 if ( expr != 0 ) expr->print( os ); 73 os << endl; 74 } 69 75 70 76 IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ): 71 Statement(_labels), condition(_condition), thenPart(_thenPart), elsePart(_elsePart) {}77 Statement(_labels ), condition(_condition ), thenPart(_thenPart ), elsePart(_elsePart ) {} 72 78 73 79 IfStmt::~IfStmt() {} 74 80 75 81 void IfStmt::print( std::ostream &os, int indent ){ 76 os << "\r" << string(indent, ' ') << "If on condition: " << endl ;77 condition->print(os, indent + 4);78 79 os << string(indent, ' ') << ".... and branches: " << endl;80 81 thenPart->print(os, indent + 4);82 83 if (elsePart != 0){84 elsePart->print(os, indent + 4);85 } 86 } 87 88 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches):89 Statement(_labels), condition(_condition), branches(_branches) 90 {}82 os << "\r" << string( indent, ' ') << "If on condition: " << endl ; 83 condition->print( os, indent + 4 ); 84 85 os << string( indent, ' ') << ".... and branches: " << endl; 86 87 thenPart->print( os, indent + 4 ); 88 89 if ( elsePart != 0 ) { 90 elsePart->print( os, indent + 4 ); 91 } // if 92 } 93 94 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): 95 Statement(_labels ), condition(_condition ), branches(_branches ) { 96 } 91 97 92 98 SwitchStmt::~SwitchStmt() { 93 delete condition; 94 // destroy branches 95 } 96 97 void SwitchStmt::add_case(CaseStmt *c) {} 98 99 void SwitchStmt::print(std::ostream &os, int indent) { 100 os << "\r" << string(indent, ' ') << "Switch on condition: "; 101 condition->print(os); 102 os << endl; 103 104 // branches 105 std::list<Statement *>::iterator i; 106 for (i = branches.begin(); i != branches.end(); i++) 107 (*i)->print(os, indent + 4); 108 109 //for_each(branches.begin(), branches.end(), mem_fun(bind1st(&Statement::print), os)); 110 } 111 112 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, 113 std::list<Statement *> &_statements, bool deflt ) 114 throw (SemanticError) : 115 Statement(_labels), condition(_condition), stmts(_statements), _isDefault(deflt) 116 { 117 if (isDefault() && condition != 0) 118 throw SemanticError("default with conditions"); 99 delete condition; 100 // destroy branches 101 } 102 103 void SwitchStmt::add_case( CaseStmt *c ) {} 104 105 void SwitchStmt::print( std::ostream &os, int indent ) { 106 os << "\r" << string( indent, ' ') << "Switch on condition: "; 107 condition->print( os ); 108 os << endl; 109 110 // branches 111 std::list<Statement *>::iterator i; 112 for ( i = branches.begin(); i != branches.end(); i++) 113 (*i )->print( os, indent + 4 ); 114 115 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); 116 } 117 118 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 119 Statement(_labels ), condition(_condition ), stmts(_statements ), _isDefault( deflt ) { 120 if ( isDefault() && condition != 0 ) 121 throw SemanticError("default with conditions"); 119 122 } 120 123 121 124 CaseStmt::~CaseStmt() { 122 delete condition;123 } 124 125 void CaseStmt::print( std::ostream &os, int indent) {126 os << "\r" << string(indent, ' ');127 128 if (isDefault())129 os << "Default ";130 else {131 os << "Case ";132 condition->print(os);133 } 134 135 os << endl;136 137 std::list<Statement *>::iterator i;138 for (i = stmts.begin(); i != stmts.end(); i++)139 (*i)->print(os, indent + 4);125 delete condition; 126 } 127 128 void CaseStmt::print( std::ostream &os, int indent ) { 129 os << "\r" << string( indent, ' '); 130 131 if ( isDefault()) 132 os << "Default "; 133 else { 134 os << "Case "; 135 condition->print( os ); 136 } // if 137 138 os << endl; 139 140 std::list<Statement *>::iterator i; 141 for ( i = stmts.begin(); i != stmts.end(); i++) 142 (*i )->print( os, indent + 4 ); 140 143 } 141 144 142 145 //ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {} 143 ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches):144 Statement(_labels), condition(_condition), branches(_branches) 145 {}146 ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): 147 Statement(_labels ), condition(_condition ), branches(_branches ) { 148 } 146 149 147 150 ChooseStmt::~ChooseStmt() { 148 delete condition; 149 } 150 151 void ChooseStmt::add_case(CaseStmt *c) {} 152 153 void ChooseStmt::print(std::ostream &os, int indent) { 154 os << "\r" << string(indent, ' ') << "Choose on condition: "; 155 condition->print(os); 156 os << endl; 157 158 // branches 159 std::list<Statement *>::iterator i; 160 for (i = branches.begin(); i != branches.end(); i++) 161 (*i)->print(os, indent + 4); 162 163 //for_each(branches.begin(), branches.end(), mem_fun(bind1st(&Statement::print), os)); 164 } 165 166 void FallthruStmt::print(std::ostream &os, int indent) { 167 os << "\r" << string(indent, ' ') << "Fall-through statement" << endl; 168 } 169 170 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, 171 Statement *body_, bool isDoWhile_ ): 172 Statement( labels ), condition(condition_), body(body_), isDoWhile(isDoWhile_) 173 {} 151 delete condition; 152 } 153 154 void ChooseStmt::add_case( CaseStmt *c ) {} 155 156 void ChooseStmt::print( std::ostream &os, int indent ) { 157 os << "\r" << string( indent, ' ') << "Choose on condition: "; 158 condition->print( os ); 159 os << endl; 160 161 // branches 162 std::list<Statement *>::iterator i; 163 for ( i = branches.begin(); i != branches.end(); i++) 164 (*i )->print( os, indent + 4 ); 165 166 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); 167 } 168 169 void FallthruStmt::print( std::ostream &os, int indent ) { 170 os << "\r" << string( indent, ' ') << "Fall-through statement" << endl; 171 } 172 173 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): 174 Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { 175 } 174 176 175 177 WhileStmt::~WhileStmt(){ 176 delete body;178 delete body; 177 179 } 178 180 179 181 void WhileStmt::print( std::ostream &os, int indent ){ 180 os << "\r" << string(indent, ' ') << "While on condition: " << endl ; 181 condition->print(os, indent + 4); 182 183 os << string(indent, ' ') << ".... with body: " << endl; 184 185 if (body != 0) body->print(os, indent + 4); 186 } 187 188 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, 189 Expression *condition_, Expression *increment_, Statement *body_ ): 190 Statement( labels ), initialization( initialization_ ), 191 condition( condition_ ), increment( increment_ ), body( body_ ) 192 { } 193 182 os << "\r" << string( indent, ' ') << "While on condition: " << endl ; 183 condition->print( os, indent + 4 ); 184 185 os << string( indent, ' ') << ".... with body: " << endl; 186 187 if ( body != 0 ) body->print( os, indent + 4 ); 188 } 189 190 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): 191 Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { 192 } 194 193 195 194 ForStmt::~ForStmt() { 196 delete initialization;197 delete condition;198 delete increment;199 delete body;195 delete initialization; 196 delete condition; 197 delete increment; 198 delete body; 200 199 } 201 200 202 201 void ForStmt::print( std::ostream &os, int indent ){ 203 os << "\r" << string(indent, ' ') << "For Statement" << endl ;204 205 os << "\r" << string(indent + 2, ' ') << "initialization: \n";206 if (initialization != 0)207 initialization->print(os, indent + 4);208 209 os << "\n\r" << string(indent + 2, ' ') << "condition: \n";210 if (condition != 0)211 condition->print(os, indent + 4);212 213 os << "\n\r" << string(indent + 2, ' ') << "increment: \n";214 if (increment != 0)215 increment->print(os, indent + 4);216 217 os << "\n\r" << string(indent + 2, ' ') << "statement block: \n";218 if (body != 0)219 body->print(os, indent + 4);220 221 os << endl;202 os << "\r" << string( indent, ' ') << "For Statement" << endl ; 203 204 os << "\r" << string( indent + 2, ' ') << "initialization: \n"; 205 if ( initialization != 0 ) 206 initialization->print( os, indent + 4 ); 207 208 os << "\n\r" << string( indent + 2, ' ') << "condition: \n"; 209 if ( condition != 0 ) 210 condition->print( os, indent + 4 ); 211 212 os << "\n\r" << string( indent + 2, ' ') << "increment: \n"; 213 if ( increment != 0 ) 214 increment->print( os, indent + 4 ); 215 216 os << "\n\r" << string( indent + 2, ' ') << "statement block: \n"; 217 if ( body != 0 ) 218 body->print( os, indent + 4 ); 219 220 os << endl; 222 221 } 223 222 224 223 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) : 225 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) 226 {}227 228 TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) {229 block = other.block;230 std::copy( other.handlers.begin(), other.handlers.end(), back_inserter(handlers) );231 finallyBlock = other.finallyBlock;224 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { 225 } 226 227 TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) { 228 block = other.block; 229 std::copy( other.handlers.begin(), other.handlers.end(), back_inserter( handlers ) ); 230 finallyBlock = other.finallyBlock; 232 231 } 233 232 234 233 TryStmt::~TryStmt(){ 235 delete block;234 delete block; 236 235 } 237 236 238 237 void TryStmt::print( std::ostream &os, int indent ) { 239 os << "\r" << string(indent, ' ') << "Try Statement" << endl;240 os << string(indent + 2, ' ') << "with block: " << endl;241 block->print(os, indent + 4);242 243 // handlers244 os << string(indent + 2, ' ') << "and handlers: " << endl;245 std::list<Statement *>::iterator i;246 for (i = handlers.begin(); i != handlers.end(); i++)247 (*i)->print(os, indent + 4);248 249 // finally block250 if ( finallyBlock != 0 ) {251 os << string(indent + 2, ' ') << "Finally block: " << endl;252 finallyBlock->print(os, indent + 4 );253 } 238 os << "\r" << string( indent, ' ') << "Try Statement" << endl; 239 os << string( indent + 2, ' ') << "with block: " << endl; 240 block->print( os, indent + 4 ); 241 242 // handlers 243 os << string( indent + 2, ' ') << "and handlers: " << endl; 244 std::list<Statement *>::iterator i; 245 for ( i = handlers.begin(); i != handlers.end(); i++) 246 (*i )->print( os, indent + 4 ); 247 248 // finally block 249 if ( finallyBlock != 0 ) { 250 os << string( indent + 2, ' ') << "Finally block: " << endl; 251 finallyBlock->print( os, indent + 4 ); 252 } // if 254 253 } 255 254 256 255 CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) : 257 Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) 258 {}256 Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) { 257 } 259 258 260 259 CatchStmt::~CatchStmt(){ 261 delete decl;262 delete body;260 delete decl; 261 delete body; 263 262 } 264 263 265 264 void CatchStmt::print( std::ostream &os, int indent ) { 266 os << "\r" << string(indent, ' ') << "Catch Statement" << endl; 267 268 os << "\r" << string(indent, ' ') << "... catching" << endl; 269 if ( decl ) { 270 decl->printShort( os, indent + 4 ); 271 os << endl; 272 } else if ( catchRest ) 273 os << "\r" << string(indent + 4 , ' ') << "the rest" << endl; 274 else 275 os << "\r" << string(indent + 4 , ' ') << ">>> Error: this catch clause must have a declaration <<<" << endl; 276 } 277 278 279 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : 280 Statement( labels ), block( _block ) 281 { 282 assert( labels.empty() ); // finally statement cannot be labeled 283 } 284 285 FinallyStmt::~FinallyStmt(){ 286 delete block; 265 os << "\r" << string( indent, ' ') << "Catch Statement" << endl; 266 267 os << "\r" << string( indent, ' ') << "... catching" << endl; 268 if ( decl ) { 269 decl->printShort( os, indent + 4 ); 270 os << endl; 271 } else if ( catchRest ) 272 os << "\r" << string( indent + 4 , ' ') << "the rest" << endl; 273 else 274 os << "\r" << string( indent + 4 , ' ') << ">>> Error: this catch clause must have a declaration <<<" << endl; 275 } 276 277 278 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { 279 assert( labels.empty() ); // finally statement cannot be labeled 280 } 281 282 FinallyStmt::~FinallyStmt() { 283 delete block; 287 284 } 288 285 289 286 void FinallyStmt::print( std::ostream &os, int indent ) { 290 os << "\r" << string(indent, ' ') << "Finally Statement" << endl;291 os << string(indent + 2, ' ') << "with block: " << endl;292 block->print(os, indent + 4);287 os << "\r" << string( indent, ' ') << "Finally Statement" << endl; 288 os << string( indent + 2, ' ') << "with block: " << endl; 289 block->print( os, indent + 4 ); 293 290 } 294 291 … … 298 295 299 296 void NullStmt::print( std::ostream &os, int indent ) { 300 os << "\r" << string(indent, ' ') << "Null Statement" << endl ; 301 } 302 303 304 305 /* 306 Local Variables: 307 compile-command: "cd ..; gmake" 308 End: 309 */ 297 os << "\r" << string( indent, ' ') << "Null Statement" << endl ; 298 } 299 300 // Local Variables: // 301 // tab-width: 4 // 302 // mode: c++ // 303 // compile-command: "make install" // 304 // End: // -
translator/SynTree/Statement.h
ra32b204 r0dd3a2f 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 // Statement.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:57:40 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef STATEMENT_H 2 17 #define STATEMENT_H … … 7 22 #include "Common/SemanticError.h" 8 23 9 10 class Statement 11 { 12 public: 13 Statement( std::list<Label> labels ); 14 virtual ~Statement(); 15 16 std::list<Label> & get_labels() { return labels; } 17 18 virtual Statement *clone() const = 0; 19 virtual void accept( Visitor &v ) = 0; 20 virtual Statement *acceptMutator( Mutator &m ) = 0; 21 virtual void print( std::ostream &os, int indent = 0 ); 22 23 protected: 24 std::list<Label> labels; 25 }; 26 27 class CompoundStmt : public Statement 28 { 29 public: 30 CompoundStmt( std::list<Label> labels ); 31 CompoundStmt( const CompoundStmt &other ); 32 virtual ~CompoundStmt(); 33 34 std::list<Statement*>& get_kids() { return kids; } 35 36 virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } 37 virtual void accept( Visitor &v ) { v.visit( this ); } 38 virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 39 virtual void print( std::ostream &os, int indent = 0 ); 40 41 private: 42 std::list<Statement*> kids; 43 }; 44 45 class ExprStmt : public Statement 46 { 47 public: 48 ExprStmt( std::list<Label> labels, Expression *expr ); 49 virtual ~ExprStmt(); 50 51 Expression *get_expr() { return expr; } 52 void set_expr( Expression *newValue ) { expr = newValue; } 53 54 virtual ExprStmt *clone() const { return new ExprStmt( *this ); } 55 virtual void accept( Visitor &v ) { v.visit( this ); } 56 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 57 virtual void print( std::ostream &os, int indent = 0 ); 58 59 private: 60 Expression *expr; 61 }; 62 63 class IfStmt : public Statement 64 { 65 public: 66 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 67 virtual ~IfStmt(); 68 69 Expression *get_condition() { return condition; } 70 void set_condition( Expression *newValue ) { condition = newValue; } 71 Statement *get_thenPart() { return thenPart; } 72 void set_thenPart( Statement *newValue ) { thenPart = newValue; } 73 Statement *get_elsePart() { return elsePart; } 74 void set_elsePart( Statement *newValue ) { elsePart = newValue; } 75 76 virtual IfStmt *clone() const { return new IfStmt( *this ); } 77 virtual void accept( Visitor &v ) { v.visit( this ); } 78 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 79 virtual void print( std::ostream &os, int indent = 0 ); 80 81 private: 82 Expression *condition; 83 Statement *thenPart; 84 Statement *elsePart; 85 }; 86 87 class SwitchStmt : public Statement 88 { 89 public: 90 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 91 virtual ~SwitchStmt(); 92 93 Expression *get_condition() { return condition; } 94 void set_condition( Expression *newValue ) { condition = newValue; } 95 96 std::list<Statement *>& get_branches() { return branches; } 97 void add_case( CaseStmt * ); 98 99 virtual void accept( Visitor &v ) { v.visit( this ); } 100 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 101 102 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); } 103 virtual void print( std::ostream &os, int indent = 0 ); 104 105 private: 106 Expression * condition; 107 std::list<Statement *> branches; // should be list of CaseStmt 108 }; 109 110 class ChooseStmt : public Statement 111 { 112 public: 113 ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 114 virtual ~ChooseStmt(); 115 116 Expression *get_condition() { return condition; } 117 void set_condition( Expression *newValue ) { condition = newValue; } 118 119 std::list<Statement *>& get_branches() { return branches; } 120 void add_case( CaseStmt * ); 121 122 123 virtual void accept( Visitor &v ) { v.visit( this ); } 124 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 125 126 virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); } 127 virtual void print( std::ostream &os, int indent = 0 ); 128 129 private: 130 Expression *condition; 131 std::list<Statement *> branches; // should be list of CaseStmt 24 class Statement { 25 public: 26 Statement( std::list<Label> labels ); 27 virtual ~Statement(); 28 29 std::list<Label> & get_labels() { return labels; } 30 31 virtual Statement *clone() const = 0; 32 virtual void accept( Visitor &v ) = 0; 33 virtual Statement *acceptMutator( Mutator &m ) = 0; 34 virtual void print( std::ostream &os, int indent = 0 ); 35 protected: 36 std::list<Label> labels; 37 }; 38 39 class CompoundStmt : public Statement { 40 public: 41 CompoundStmt( std::list<Label> labels ); 42 CompoundStmt( const CompoundStmt &other ); 43 virtual ~CompoundStmt(); 44 45 std::list<Statement*>& get_kids() { return kids; } 46 47 virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } 48 virtual void accept( Visitor &v ) { v.visit( this ); } 49 virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 50 virtual void print( std::ostream &os, int indent = 0 ); 51 private: 52 std::list<Statement*> kids; 53 }; 54 55 class ExprStmt : public Statement { 56 public: 57 ExprStmt( std::list<Label> labels, Expression *expr ); 58 virtual ~ExprStmt(); 59 60 Expression *get_expr() { return expr; } 61 void set_expr( Expression *newValue ) { expr = newValue; } 62 63 virtual ExprStmt *clone() const { return new ExprStmt( *this ); } 64 virtual void accept( Visitor &v ) { v.visit( this ); } 65 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 66 virtual void print( std::ostream &os, int indent = 0 ); 67 private: 68 Expression *expr; 69 }; 70 71 class IfStmt : public Statement { 72 public: 73 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 74 virtual ~IfStmt(); 75 76 Expression *get_condition() { return condition; } 77 void set_condition( Expression *newValue ) { condition = newValue; } 78 Statement *get_thenPart() { return thenPart; } 79 void set_thenPart( Statement *newValue ) { thenPart = newValue; } 80 Statement *get_elsePart() { return elsePart; } 81 void set_elsePart( Statement *newValue ) { elsePart = newValue; } 82 83 virtual IfStmt *clone() const { return new IfStmt( *this ); } 84 virtual void accept( Visitor &v ) { v.visit( this ); } 85 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 86 virtual void print( std::ostream &os, int indent = 0 ); 87 private: 88 Expression *condition; 89 Statement *thenPart; 90 Statement *elsePart; 91 }; 92 93 class SwitchStmt : public Statement { 94 public: 95 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 96 virtual ~SwitchStmt(); 97 98 Expression *get_condition() { return condition; } 99 void set_condition( Expression *newValue ) { condition = newValue; } 100 101 std::list<Statement *>& get_branches() { return branches; } 102 void add_case( CaseStmt * ); 103 104 virtual void accept( Visitor &v ) { v.visit( this ); } 105 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 106 107 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); } 108 virtual void print( std::ostream &os, int indent = 0 ); 109 private: 110 Expression * condition; 111 std::list<Statement *> branches; // should be list of CaseStmt 112 }; 113 114 class ChooseStmt : public Statement { 115 public: 116 ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 117 virtual ~ChooseStmt(); 118 119 Expression *get_condition() { return condition; } 120 void set_condition( Expression *newValue ) { condition = newValue; } 121 122 std::list<Statement *>& get_branches() { return branches; } 123 void add_case( CaseStmt * ); 124 125 virtual void accept( Visitor &v ) { v.visit( this ); } 126 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 127 128 virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); } 129 virtual void print( std::ostream &os, int indent = 0 ); 130 private: 131 Expression *condition; 132 std::list<Statement *> branches; // should be list of CaseStmt 132 133 }; 133 134 134 135 class FallthruStmt : public Statement { 135 public: 136 FallthruStmt( std::list<Label> labels ) : Statement( labels ) { } 137 138 virtual void accept( Visitor &v ) { v.visit( this ); } 139 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 140 141 virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); } 142 virtual void print( std::ostream &os, int indent = 0 ); 143 }; 144 145 class CaseStmt : public Statement 146 { 147 public: 148 CaseStmt( std::list<Label> labels, Expression *conditions, 149 std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 150 virtual ~CaseStmt(); 151 152 bool isDefault() { return _isDefault; } 153 void set_default(bool b) { _isDefault = b; } 154 155 Expression * &get_condition() { return condition; } 156 void set_condition( Expression *newValue ) { condition = newValue; } 157 158 std::list<Statement *> &get_statements() { return stmts; } 159 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } 160 161 virtual void accept( Visitor &v ) { v.visit( this ); } 162 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 163 164 virtual CaseStmt *clone() const { return new CaseStmt( *this ); } 165 virtual void print( std::ostream &os, int indent = 0 ); 166 167 private: 168 Expression * condition; 169 std::list<Statement *> stmts; 170 bool _isDefault; 171 }; 172 173 class WhileStmt : public Statement 174 { 175 public: 176 WhileStmt( std::list<Label> labels, Expression *condition, 177 Statement *body, bool isDoWhile = false ); 178 virtual ~WhileStmt(); 179 180 Expression *get_condition() { return condition; } 181 void set_condition( Expression *newValue ) { condition = newValue; } 182 Statement *get_body() { return body; } 183 void set_body( Statement *newValue ) { body = newValue; } 184 bool get_isDoWhile() { return isDoWhile; } 185 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 186 187 virtual WhileStmt *clone() const { return new WhileStmt( *this ); } 188 virtual void accept( Visitor &v ) { v.visit( this ); } 189 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 190 virtual void print( std::ostream &os, int indent = 0 ); 191 192 private: 193 Expression *condition; 194 Statement *body; 195 bool isDoWhile; 196 }; 197 198 class ForStmt : public Statement 199 { 200 public: 201 ForStmt( std::list<Label> labels, Statement *initialization = 0, 202 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 203 virtual ~ForStmt(); 204 205 Statement *get_initialization() { return initialization; } 206 void set_initialization( Statement *newValue ) { initialization = newValue; } 207 Expression *get_condition() { return condition; } 208 void set_condition( Expression *newValue ) { condition = newValue; } 209 Expression *get_increment() { return increment; } 210 void set_increment( Expression *newValue ) { increment = newValue; } 211 Statement *get_body() { return body; } 212 void set_body( Statement *newValue ) { body = newValue; } 213 214 virtual ForStmt *clone() const { return new ForStmt( *this ); } 215 virtual void accept( Visitor &v ) { v.visit( this ); } 216 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 217 virtual void print( std::ostream &os, int indent = 0 ); 218 219 private: 220 Statement *initialization; 221 Expression *condition; 222 Expression *increment; 223 Statement *body; 224 }; 225 226 class BranchStmt : public Statement 227 { 228 public: 229 230 enum Type { Goto = 0 , Break, Continue }; 231 232 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 233 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 234 virtual ~BranchStmt() {} 235 236 Label get_target() { return target; } 237 void set_target( Label newValue ) { target = newValue; } 238 239 Expression *get_computedTarget() { return computedTarget; } 240 void set_target( Expression * newValue ) { computedTarget = newValue; } 241 242 Type get_type() { return type; } 243 const char *get_typename() { return brType[ type ]; } 244 245 virtual BranchStmt *clone() const { return new BranchStmt( *this ); } 246 virtual void accept( Visitor &v ) { v.visit( this ); } 247 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 248 virtual void print( std::ostream &os, int indent = 0 ); 249 250 private: 251 static const char *brType[]; 252 Label target; 253 Expression *computedTarget; 254 Type type; 255 }; 256 257 class ReturnStmt : public Statement 258 { 259 public: 260 ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false ); 261 virtual ~ReturnStmt(); 262 263 Expression *get_expr() { return expr; } 264 void set_expr( Expression *newValue ) { expr = newValue; } 265 266 virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); } 267 virtual void accept( Visitor &v ) { v.visit( this ); } 268 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 269 virtual void print( std::ostream &os, int indent = 0 ); 270 271 private: 272 Expression *expr; 273 bool isThrow; 274 }; 275 276 277 class NullStmt : public CompoundStmt 278 { 279 public: 280 NullStmt(); 281 NullStmt( std::list<Label> labels ); 282 virtual ~NullStmt(); 283 284 virtual NullStmt *clone() const { return new NullStmt( *this ); } 285 virtual void accept( Visitor &v ) { v.visit( this ); } 286 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 287 virtual void print( std::ostream &os, int indent = 0 ); 288 289 private: 290 }; 291 292 class TryStmt : public Statement 293 { 294 public: 295 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 ); 296 TryStmt( const TryStmt &other ); 297 virtual ~TryStmt(); 298 299 CompoundStmt *get_block() const { return block; } 300 void set_block( CompoundStmt *newValue ) { block = newValue; } 301 std::list<Statement *>& get_catchers() { return handlers; } 302 303 FinallyStmt *get_finally() const { return finallyBlock; } 304 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } 305 306 virtual TryStmt *clone() const { return new TryStmt( *this ); } 307 virtual void accept( Visitor &v ) { v.visit( this ); } 308 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 309 virtual void print( std::ostream &os, int indent = 0 ); 310 311 private: 312 CompoundStmt *block; 313 std::list<Statement *> handlers; 314 FinallyStmt *finallyBlock; 136 public: 137 FallthruStmt( std::list<Label> labels ) : Statement( labels ) { } 138 139 virtual void accept( Visitor &v ) { v.visit( this ); } 140 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 141 142 virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); } 143 virtual void print( std::ostream &os, int indent = 0 ); 144 }; 145 146 class CaseStmt : public Statement { 147 public: 148 CaseStmt( std::list<Label> labels, Expression *conditions, 149 std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 150 virtual ~CaseStmt(); 151 152 bool isDefault() { return _isDefault; } 153 void set_default(bool b) { _isDefault = b; } 154 155 Expression * &get_condition() { return condition; } 156 void set_condition( Expression *newValue ) { condition = newValue; } 157 158 std::list<Statement *> &get_statements() { return stmts; } 159 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } 160 161 virtual void accept( Visitor &v ) { v.visit( this ); } 162 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 163 164 virtual CaseStmt *clone() const { return new CaseStmt( *this ); } 165 virtual void print( std::ostream &os, int indent = 0 ); 166 private: 167 Expression * condition; 168 std::list<Statement *> stmts; 169 bool _isDefault; 170 }; 171 172 class WhileStmt : public Statement { 173 public: 174 WhileStmt( std::list<Label> labels, Expression *condition, 175 Statement *body, bool isDoWhile = false ); 176 virtual ~WhileStmt(); 177 178 Expression *get_condition() { return condition; } 179 void set_condition( Expression *newValue ) { condition = newValue; } 180 Statement *get_body() { return body; } 181 void set_body( Statement *newValue ) { body = newValue; } 182 bool get_isDoWhile() { return isDoWhile; } 183 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 184 185 virtual WhileStmt *clone() const { return new WhileStmt( *this ); } 186 virtual void accept( Visitor &v ) { v.visit( this ); } 187 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 188 virtual void print( std::ostream &os, int indent = 0 ); 189 private: 190 Expression *condition; 191 Statement *body; 192 bool isDoWhile; 193 }; 194 195 class ForStmt : public Statement { 196 public: 197 ForStmt( std::list<Label> labels, Statement *initialization = 0, 198 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 199 virtual ~ForStmt(); 200 201 Statement *get_initialization() { return initialization; } 202 void set_initialization( Statement *newValue ) { initialization = newValue; } 203 Expression *get_condition() { return condition; } 204 void set_condition( Expression *newValue ) { condition = newValue; } 205 Expression *get_increment() { return increment; } 206 void set_increment( Expression *newValue ) { increment = newValue; } 207 Statement *get_body() { return body; } 208 void set_body( Statement *newValue ) { body = newValue; } 209 210 virtual ForStmt *clone() const { return new ForStmt( *this ); } 211 virtual void accept( Visitor &v ) { v.visit( this ); } 212 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 213 virtual void print( std::ostream &os, int indent = 0 ); 214 private: 215 Statement *initialization; 216 Expression *condition; 217 Expression *increment; 218 Statement *body; 219 }; 220 221 class BranchStmt : public Statement { 222 public: 223 enum Type { Goto = 0 , Break, Continue }; 224 225 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 226 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 227 virtual ~BranchStmt() {} 228 229 Label get_target() { return target; } 230 void set_target( Label newValue ) { target = newValue; } 231 232 Expression *get_computedTarget() { return computedTarget; } 233 void set_target( Expression * newValue ) { computedTarget = newValue; } 234 235 Type get_type() { return type; } 236 const char *get_typename() { return brType[ type ]; } 237 238 virtual BranchStmt *clone() const { return new BranchStmt( *this ); } 239 virtual void accept( Visitor &v ) { v.visit( this ); } 240 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 241 virtual void print( std::ostream &os, int indent = 0 ); 242 private: 243 static const char *brType[]; 244 Label target; 245 Expression *computedTarget; 246 Type type; 247 }; 248 249 class ReturnStmt : public Statement { 250 public: 251 ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false ); 252 virtual ~ReturnStmt(); 253 254 Expression *get_expr() { return expr; } 255 void set_expr( Expression *newValue ) { expr = newValue; } 256 257 virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); } 258 virtual void accept( Visitor &v ) { v.visit( this ); } 259 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 260 virtual void print( std::ostream &os, int indent = 0 ); 261 private: 262 Expression *expr; 263 bool isThrow; 264 }; 265 266 267 class NullStmt : public CompoundStmt { 268 public: 269 NullStmt(); 270 NullStmt( std::list<Label> labels ); 271 virtual ~NullStmt(); 272 273 virtual NullStmt *clone() const { return new NullStmt( *this ); } 274 virtual void accept( Visitor &v ) { v.visit( this ); } 275 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 276 virtual void print( std::ostream &os, int indent = 0 ); 277 278 private: 279 }; 280 281 class TryStmt : public Statement { 282 public: 283 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 ); 284 TryStmt( const TryStmt &other ); 285 virtual ~TryStmt(); 286 287 CompoundStmt *get_block() const { return block; } 288 void set_block( CompoundStmt *newValue ) { block = newValue; } 289 std::list<Statement *>& get_catchers() { return handlers; } 290 291 FinallyStmt *get_finally() const { return finallyBlock; } 292 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } 293 294 virtual TryStmt *clone() const { return new TryStmt( *this ); } 295 virtual void accept( Visitor &v ) { v.visit( this ); } 296 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 297 virtual void print( std::ostream &os, int indent = 0 ); 298 299 private: 300 CompoundStmt *block; 301 std::list<Statement *> handlers; 302 FinallyStmt *finallyBlock; 315 303 }; 316 304 317 class CatchStmt : public Statement 318 { 319 public: 320 CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false ); 321 virtual ~CatchStmt(); 322 323 Declaration *get_decl() { return decl; } 324 void set_decl( Declaration *newValue ) { decl = newValue; } 325 326 Statement *get_body() { return body; } 327 void set_body( Statement *newValue ) { body = newValue; } 328 329 virtual CatchStmt *clone() const { return new CatchStmt( *this ); } 330 virtual void accept( Visitor &v ) { v.visit( this ); } 331 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 332 virtual void print( std::ostream &os, int indent = 0 ); 333 334 private: 335 Declaration *decl; 336 Statement *body; 337 bool catchRest; 338 }; 339 340 class FinallyStmt : public Statement 341 { 342 public: 343 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 344 virtual ~FinallyStmt(); 345 346 CompoundStmt *get_block() const { return block; } 347 void set_block( CompoundStmt *newValue ) { block = newValue; } 348 349 virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); } 350 virtual void accept( Visitor &v ) { v.visit( this ); } 351 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 352 virtual void print( std::ostream &os, int indent = 0 ); 353 354 private: 355 CompoundStmt *block; 305 class CatchStmt : public Statement { 306 public: 307 CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false ); 308 virtual ~CatchStmt(); 309 310 Declaration *get_decl() { return decl; } 311 void set_decl( Declaration *newValue ) { decl = newValue; } 312 313 Statement *get_body() { return body; } 314 void set_body( Statement *newValue ) { body = newValue; } 315 316 virtual CatchStmt *clone() const { return new CatchStmt( *this ); } 317 virtual void accept( Visitor &v ) { v.visit( this ); } 318 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 319 virtual void print( std::ostream &os, int indent = 0 ); 320 321 private: 322 Declaration *decl; 323 Statement *body; 324 bool catchRest; 325 }; 326 327 class FinallyStmt : public Statement { 328 public: 329 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 330 virtual ~FinallyStmt(); 331 332 CompoundStmt *get_block() const { return block; } 333 void set_block( CompoundStmt *newValue ) { block = newValue; } 334 335 virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); } 336 virtual void accept( Visitor &v ) { v.visit( this ); } 337 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 338 virtual void print( std::ostream &os, int indent = 0 ); 339 private: 340 CompoundStmt *block; 356 341 }; 357 342 358 343 359 344 // represents a declaration that occurs as part of a compound statement 360 class DeclStmt : public Statement 361 { 362 public: 363 DeclStmt( std::list<Label> labels, Declaration *decl ); 364 DeclStmt( const DeclStmt &other ); 365 virtual ~DeclStmt(); 366 367 Declaration *get_decl() { return decl; } 368 void set_decl( Declaration *newValue ) { decl = newValue; } 369 370 virtual DeclStmt *clone() const { return new DeclStmt( *this ); } 371 virtual void accept( Visitor &v ) { v.visit( this ); } 372 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 373 virtual void print( std::ostream &os, int indent = 0 ); 374 375 private: 376 Declaration *decl; 377 }; 378 379 380 381 #endif /* #ifndef STATEMENT_H */ 382 383 /* 384 Local Variables: 385 mode: c++ 386 End: 387 */ 345 class DeclStmt : public Statement { 346 public: 347 DeclStmt( std::list<Label> labels, Declaration *decl ); 348 DeclStmt( const DeclStmt &other ); 349 virtual ~DeclStmt(); 350 351 Declaration *get_decl() { return decl; } 352 void set_decl( Declaration *newValue ) { decl = newValue; } 353 354 virtual DeclStmt *clone() const { return new DeclStmt( *this ); } 355 virtual void accept( Visitor &v ) { v.visit( this ); } 356 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 357 virtual void print( std::ostream &os, int indent = 0 ); 358 private: 359 Declaration *decl; 360 }; 361 362 #endif // STATEMENT_H 363 364 // Local Variables: // 365 // tab-width: 4 // 366 // mode: c++ // 367 // compile-command: "make install" // 368 // End: // -
translator/SynTree/SynTree.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: SynTree.h,v 1.22 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 * Forward declarations for syntax tree classes, so that they can be mutually 7 * interdependent 8 */ 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 // SynTree.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:58:22 2015 13 // Update Count : 1 14 // 9 15 10 16 #ifndef SYNTREE_H … … 15 21 #include <map> 16 22 #include <iostream> 17 18 23 19 24 class Declaration; … … 102 107 class TypeSubstitution; 103 108 109 #endif // SYNTREE_H 104 110 105 #endif /* #ifndef SYNTREE_H */ 111 // Local Variables: // 112 // tab-width: 4 // 113 // mode: c++ // 114 // compile-command: "make install" // 115 // End: // -
translator/SynTree/TupleExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TupleExpr.cc,v 1.11 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // TupleExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:59:19 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Expression.h" 9 17 #include "utility.h" 10 18 11 12 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) 13 { 19 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) { 14 20 } 15 21 16 TupleExpr::TupleExpr( const TupleExpr &other ) 17 : Expression( other ) 18 { 19 cloneAll( other.exprs, exprs ); 22 TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) { 23 cloneAll( other.exprs, exprs ); 20 24 } 21 25 22 TupleExpr::~TupleExpr() 23 { 24 deleteAll( exprs ); 26 TupleExpr::~TupleExpr() { 27 deleteAll( exprs ); 25 28 } 26 29 27 void 28 TupleExpr::print( std::ostream &os, int indent ) const 29 { 30 os << std::string( indent, ' ' ) << "Tuple:" << std::endl; 31 printAll( exprs, os, indent+2 ); 32 Expression::print( os, indent ); 30 void TupleExpr::print( std::ostream &os, int indent ) const { 31 os << std::string( indent, ' ' ) << "Tuple:" << std::endl; 32 printAll( exprs, os, indent+2 ); 33 Expression::print( os, indent ); 33 34 } 34 35 35 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) 36 : Expression( _aname ) 37 { 38 std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs)); 36 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) { 37 std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs)); 39 38 } 40 39 41 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) 42 : Expression( other ) 43 { 44 cloneAll( other.exprs, exprs ); 40 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) { 41 cloneAll( other.exprs, exprs ); 45 42 } 46 43 47 void 48 SolvedTupleExpr::print( std::ostream &os, int indent ) const 49 { 50 os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl; 51 printAll( exprs, os, indent+2 ); 52 Expression::print( os, indent ); 44 void SolvedTupleExpr::print( std::ostream &os, int indent ) const { 45 os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl; 46 printAll( exprs, os, indent+2 ); 47 Expression::print( os, indent ); 53 48 } 54 49 50 // Local Variables: // 51 // tab-width: 4 // 52 // mode: c++ // 53 // compile-command: "make install" // 54 // End: // -
translator/SynTree/TupleType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TupleType.cc,v 1.6 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // TupleType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:00:01 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" 9 17 #include "utility.h" 10 18 11 12 TupleType::TupleType( const Type::Qualifiers &tq ) 13 : Type( tq ) 14 { 19 TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq ) { 15 20 } 16 21 17 TupleType::TupleType( const TupleType& other ) 18 : Type( other ) 19 { 20 cloneAll( other.types, types ); 22 TupleType::TupleType( const TupleType& other ) : Type( other ) { 23 cloneAll( other.types, types ); 21 24 } 22 25 23 TupleType::~TupleType() 24 { 25 deleteAll( types ); 26 TupleType::~TupleType() { 27 deleteAll( types ); 26 28 } 27 29 28 void 29 TupleType::print( std::ostream &os, int indent ) const 30 { 31 Type::print( os, indent ); 32 os << "tuple of types" << std::endl; 33 printAll( types, os, indent+2 ); 30 void TupleType::print( std::ostream &os, int indent ) const { 31 Type::print( os, indent ); 32 os << "tuple of types" << std::endl; 33 printAll( types, os, indent+2 ); 34 34 } 35 35 36 // Local Variables: // 37 // tab-width: 4 // 38 // mode: c++ // 39 // compile-command: "make install" // 40 // End: // -
translator/SynTree/Type.cc
ra32b204 r0dd3a2f 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 // Type.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:00:29 2015 13 // Update Count : 1 14 // 15 1 16 #include "SynTree.h" 2 17 #include "Visitor.h" … … 41 56 void Type::print( std::ostream &os, int indent ) const { 42 57 if ( ! forall.empty() ) { 43 os << "forall" << std::endl;44 printAll( forall, os, indent + 4 );45 os << std::string( indent+2, ' ' );58 os << "forall" << std::endl; 59 printAll( forall, os, indent + 4 ); 60 os << std::string( indent+2, ' ' ); 46 61 } // if 47 62 if ( tq.isConst ) { 48 os << "const ";63 os << "const "; 49 64 } // if 50 65 if ( tq.isVolatile ) { 51 os << "volatile ";66 os << "volatile "; 52 67 } // if 53 68 if ( tq.isRestrict ) { 54 os << "restrict ";69 os << "restrict "; 55 70 } // if 56 71 if ( tq.isLvalue ) { 57 os << "lvalue ";72 os << "lvalue "; 58 73 } // if 59 74 if ( tq.isAtomic ) { 60 os << "_Atomic ";75 os << "_Atomic "; 61 76 } // if 62 77 } 78 79 // Local Variables: // 80 // tab-width: 4 // 81 // mode: c++ // 82 // compile-command: "make install" // 83 // End: // -
translator/SynTree/Type.h
ra32b204 r0dd3a2f 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 // Type.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:01:40 2015 13 // Update Count : 1 14 // 15 1 16 #ifndef TYPE_H 2 17 #define TYPE_H … … 6 21 #include "Mutator.h" 7 22 8 9 23 class Type { 10 24 public: 11 struct Qualifiers {12 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}13 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}14 15 Qualifiers &operator+=( const Qualifiers &other );16 Qualifiers &operator-=( const Qualifiers &other );17 Qualifiers operator+( const Type::Qualifiers &other );18 bool operator==( const Qualifiers &other );19 bool operator!=( const Qualifiers &other );20 bool operator<=( const Qualifiers &other );21 bool operator>=( const Qualifiers &other );22 bool operator<( const Qualifiers &other );23 bool operator>( const Qualifiers &other );24 25 bool isConst;26 bool isVolatile;27 bool isRestrict;28 bool isLvalue;29 bool isAtomic;30 bool isAttribute;31 };32 33 Type( const Qualifiers &tq );34 Type( const Type &other );35 virtual ~Type();36 37 Qualifiers &get_qualifiers() { return tq; }38 bool get_isConst() { return tq.isConst; }39 bool get_isVolatile() { return tq.isVolatile; }40 bool get_isRestrict() { return tq.isRestrict; }41 bool get_isLvalue() { return tq.isLvalue; }42 bool get_isAtomic() { return tq.isAtomic; }43 bool get_isAttribute() { return tq.isAttribute; }44 void set_isConst( bool newValue ) { tq.isConst = newValue; }45 void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; }46 void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }47 void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }48 void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }49 void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }50 std::list<TypeDecl*>& get_forall() { return forall; }51 52 virtual Type *clone() const = 0;53 virtual void accept( Visitor &v ) = 0;54 virtual Type *acceptMutator( Mutator &m ) = 0;55 virtual void print( std::ostream &os, int indent = 0 ) const;56 private: 57 Qualifiers tq;58 std::list<TypeDecl*> forall;25 struct Qualifiers { 26 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {} 27 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {} 28 29 Qualifiers &operator+=( const Qualifiers &other ); 30 Qualifiers &operator-=( const Qualifiers &other ); 31 Qualifiers operator+( const Type::Qualifiers &other ); 32 bool operator==( const Qualifiers &other ); 33 bool operator!=( const Qualifiers &other ); 34 bool operator<=( const Qualifiers &other ); 35 bool operator>=( const Qualifiers &other ); 36 bool operator<( const Qualifiers &other ); 37 bool operator>( const Qualifiers &other ); 38 39 bool isConst; 40 bool isVolatile; 41 bool isRestrict; 42 bool isLvalue; 43 bool isAtomic; 44 bool isAttribute; 45 }; 46 47 Type( const Qualifiers &tq ); 48 Type( const Type &other ); 49 virtual ~Type(); 50 51 Qualifiers &get_qualifiers() { return tq; } 52 bool get_isConst() { return tq.isConst; } 53 bool get_isVolatile() { return tq.isVolatile; } 54 bool get_isRestrict() { return tq.isRestrict; } 55 bool get_isLvalue() { return tq.isLvalue; } 56 bool get_isAtomic() { return tq.isAtomic; } 57 bool get_isAttribute() { return tq.isAttribute; } 58 void set_isConst( bool newValue ) { tq.isConst = newValue; } 59 void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; } 60 void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; } 61 void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; } 62 void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; } 63 void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; } 64 std::list<TypeDecl*>& get_forall() { return forall; } 65 66 virtual Type *clone() const = 0; 67 virtual void accept( Visitor &v ) = 0; 68 virtual Type *acceptMutator( Mutator &m ) = 0; 69 virtual void print( std::ostream &os, int indent = 0 ) const; 70 private: 71 Qualifiers tq; 72 std::list<TypeDecl*> forall; 59 73 }; 60 74 61 75 class VoidType : public Type { 62 76 public: 63 VoidType( const Type::Qualifiers &tq );64 65 virtual VoidType *clone() const { return new VoidType( *this ); }66 virtual void accept( Visitor &v ) { v.visit( this ); }67 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }68 virtual void print( std::ostream &os, int indent = 0 ) const;77 VoidType( const Type::Qualifiers &tq ); 78 79 virtual VoidType *clone() const { return new VoidType( *this ); } 80 virtual void accept( Visitor &v ) { v.visit( this ); } 81 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 82 virtual void print( std::ostream &os, int indent = 0 ) const; 69 83 }; 70 84 71 85 class BasicType : public Type { 72 86 public: 73 enum Kind {74 Bool,75 Char,76 SignedChar,77 UnsignedChar,78 ShortSignedInt,79 ShortUnsignedInt,80 SignedInt,81 UnsignedInt,82 LongSignedInt,83 LongUnsignedInt,84 LongLongSignedInt,85 LongLongUnsignedInt,86 Float,87 Double,88 LongDouble,89 FloatComplex,90 DoubleComplex,91 LongDoubleComplex,92 FloatImaginary,93 DoubleImaginary,94 LongDoubleImaginary,95 NUMBER_OF_BASIC_TYPES96 };97 98 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind99 100 BasicType( const Type::Qualifiers &tq, Kind bt );101 102 Kind get_kind() { return kind; }103 void set_kind( Kind newValue ) { kind = newValue; }104 105 virtual BasicType *clone() const { return new BasicType( *this ); }106 virtual void accept( Visitor &v ) { v.visit( this ); }107 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }108 virtual void print( std::ostream &os, int indent = 0 ) const;109 110 bool isInteger() const;111 private: 112 Kind kind;87 enum Kind { 88 Bool, 89 Char, 90 SignedChar, 91 UnsignedChar, 92 ShortSignedInt, 93 ShortUnsignedInt, 94 SignedInt, 95 UnsignedInt, 96 LongSignedInt, 97 LongUnsignedInt, 98 LongLongSignedInt, 99 LongLongUnsignedInt, 100 Float, 101 Double, 102 LongDouble, 103 FloatComplex, 104 DoubleComplex, 105 LongDoubleComplex, 106 FloatImaginary, 107 DoubleImaginary, 108 LongDoubleImaginary, 109 NUMBER_OF_BASIC_TYPES 110 }; 111 112 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind 113 114 BasicType( const Type::Qualifiers &tq, Kind bt ); 115 116 Kind get_kind() { return kind; } 117 void set_kind( Kind newValue ) { kind = newValue; } 118 119 virtual BasicType *clone() const { return new BasicType( *this ); } 120 virtual void accept( Visitor &v ) { v.visit( this ); } 121 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 122 virtual void print( std::ostream &os, int indent = 0 ) const; 123 124 bool isInteger() const; 125 private: 126 Kind kind; 113 127 }; 114 128 115 129 class PointerType : public Type { 116 130 public: 117 PointerType( const Type::Qualifiers &tq, Type *base );118 PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );119 PointerType( const PointerType& );120 virtual ~PointerType();121 122 Type *get_base() { return base; }123 void set_base( Type *newValue ) { base = newValue; }124 Expression *get_dimension() { return dimension; }125 void set_dimension( Expression *newValue ) { dimension = newValue; }126 bool get_isVarLen() { return isVarLen; }127 void set_isVarLen( bool newValue ) { isVarLen = newValue; }128 bool get_isStatic() { return isStatic; }129 void set_isStatic( bool newValue ) { isStatic = newValue; }130 131 virtual PointerType *clone() const { return new PointerType( *this ); }132 virtual void accept( Visitor &v ) { v.visit( this ); }133 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }134 virtual void print( std::ostream &os, int indent = 0 ) const;135 private: 136 Type *base;137 138 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )139 Expression *dimension;140 bool isVarLen;141 bool isStatic;131 PointerType( const Type::Qualifiers &tq, Type *base ); 132 PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); 133 PointerType( const PointerType& ); 134 virtual ~PointerType(); 135 136 Type *get_base() { return base; } 137 void set_base( Type *newValue ) { base = newValue; } 138 Expression *get_dimension() { return dimension; } 139 void set_dimension( Expression *newValue ) { dimension = newValue; } 140 bool get_isVarLen() { return isVarLen; } 141 void set_isVarLen( bool newValue ) { isVarLen = newValue; } 142 bool get_isStatic() { return isStatic; } 143 void set_isStatic( bool newValue ) { isStatic = newValue; } 144 145 virtual PointerType *clone() const { return new PointerType( *this ); } 146 virtual void accept( Visitor &v ) { v.visit( this ); } 147 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 148 virtual void print( std::ostream &os, int indent = 0 ) const; 149 private: 150 Type *base; 151 152 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] ) 153 Expression *dimension; 154 bool isVarLen; 155 bool isStatic; 142 156 }; 143 157 144 158 class ArrayType : public Type { 145 159 public: 146 ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );147 ArrayType( const ArrayType& );148 virtual ~ArrayType();149 150 Type *get_base() { return base; }151 void set_base( Type *newValue ) { base = newValue; }152 Expression *get_dimension() { return dimension; }153 void set_dimension( Expression *newValue ) { dimension = newValue; }154 bool get_isVarLen() { return isVarLen; }155 void set_isVarLen( bool newValue ) { isVarLen = newValue; }156 bool get_isStatic() { return isStatic; }157 void set_isStatic( bool newValue ) { isStatic = newValue; }158 159 virtual ArrayType *clone() const { return new ArrayType( *this ); }160 virtual void accept( Visitor &v ) { v.visit( this ); }161 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }162 virtual void print( std::ostream &os, int indent = 0 ) const;163 private: 164 Type *base;165 Expression *dimension;166 bool isVarLen;167 bool isStatic;160 ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); 161 ArrayType( const ArrayType& ); 162 virtual ~ArrayType(); 163 164 Type *get_base() { return base; } 165 void set_base( Type *newValue ) { base = newValue; } 166 Expression *get_dimension() { return dimension; } 167 void set_dimension( Expression *newValue ) { dimension = newValue; } 168 bool get_isVarLen() { return isVarLen; } 169 void set_isVarLen( bool newValue ) { isVarLen = newValue; } 170 bool get_isStatic() { return isStatic; } 171 void set_isStatic( bool newValue ) { isStatic = newValue; } 172 173 virtual ArrayType *clone() const { return new ArrayType( *this ); } 174 virtual void accept( Visitor &v ) { v.visit( this ); } 175 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 176 virtual void print( std::ostream &os, int indent = 0 ) const; 177 private: 178 Type *base; 179 Expression *dimension; 180 bool isVarLen; 181 bool isStatic; 168 182 }; 169 183 170 184 class FunctionType : public Type { 171 185 public: 172 FunctionType( const Type::Qualifiers &tq, bool isVarArgs );173 FunctionType( const FunctionType& );174 virtual ~FunctionType();175 176 std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }177 std::list<DeclarationWithType*>& get_parameters() { return parameters; }178 bool get_isVarArgs() { return isVarArgs; }179 void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }180 181 virtual FunctionType *clone() const { return new FunctionType( *this ); }182 virtual void accept( Visitor &v ) { v.visit( this ); }183 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }184 virtual void print( std::ostream &os, int indent = 0 ) const;185 private: 186 std::list<DeclarationWithType*> returnVals;187 std::list<DeclarationWithType*> parameters;188 189 // does the function accept a variable number of arguments following the arguments190 // specified in the parameters list. This could be because of191 // - an ellipsis in a prototype declaration192 // - an unprototyped declaration193 bool isVarArgs;186 FunctionType( const Type::Qualifiers &tq, bool isVarArgs ); 187 FunctionType( const FunctionType& ); 188 virtual ~FunctionType(); 189 190 std::list<DeclarationWithType*>& get_returnVals() { return returnVals; } 191 std::list<DeclarationWithType*>& get_parameters() { return parameters; } 192 bool get_isVarArgs() { return isVarArgs; } 193 void set_isVarArgs( bool newValue ) { isVarArgs = newValue; } 194 195 virtual FunctionType *clone() const { return new FunctionType( *this ); } 196 virtual void accept( Visitor &v ) { v.visit( this ); } 197 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 198 virtual void print( std::ostream &os, int indent = 0 ) const; 199 private: 200 std::list<DeclarationWithType*> returnVals; 201 std::list<DeclarationWithType*> parameters; 202 203 // does the function accept a variable number of arguments following the arguments 204 // specified in the parameters list. This could be because of 205 // - an ellipsis in a prototype declaration 206 // - an unprototyped declaration 207 bool isVarArgs; 194 208 }; 195 209 196 210 class ReferenceToType : public Type { 197 211 public: 198 ReferenceToType( const Type::Qualifiers &tq, const std::string &name );199 ReferenceToType( const ReferenceToType &other );200 virtual ~ReferenceToType();201 202 std::string get_name() const { return name; }203 void set_name( std::string newValue ) { name = newValue; }204 std::list< Expression* >& get_parameters() { return parameters; }205 206 virtual ReferenceToType *clone() const = 0;207 virtual void accept( Visitor &v ) = 0;208 virtual Type *acceptMutator( Mutator &m ) = 0;209 virtual void print( std::ostream &os, int indent = 0 ) const;212 ReferenceToType( const Type::Qualifiers &tq, const std::string &name ); 213 ReferenceToType( const ReferenceToType &other ); 214 virtual ~ReferenceToType(); 215 216 std::string get_name() const { return name; } 217 void set_name( std::string newValue ) { name = newValue; } 218 std::list< Expression* >& get_parameters() { return parameters; } 219 220 virtual ReferenceToType *clone() const = 0; 221 virtual void accept( Visitor &v ) = 0; 222 virtual Type *acceptMutator( Mutator &m ) = 0; 223 virtual void print( std::ostream &os, int indent = 0 ) const; 210 224 protected: 211 virtual std::string typeString() const = 0;212 std::list< Expression* > parameters;213 private: 214 std::string name;225 virtual std::string typeString() const = 0; 226 std::list< Expression* > parameters; 227 private: 228 std::string name; 215 229 }; 216 230 217 231 class StructInstType : public ReferenceToType { 218 typedef ReferenceToType Parent; 219 public: 220 StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} 221 StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} 222 223 StructDecl *get_baseStruct() const { return baseStruct; } 224 void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } 225 226 // a utility function 227 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 228 229 virtual StructInstType *clone() const { return new StructInstType( *this ); } 230 virtual void accept( Visitor &v ) { v.visit( this ); } 231 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 232 233 private: 234 virtual std::string typeString() const; 235 236 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, 237 // where the structure used in this type is actually defined 238 StructDecl *baseStruct; 232 typedef ReferenceToType Parent; 233 public: 234 StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} 235 StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} 236 237 StructDecl *get_baseStruct() const { return baseStruct; } 238 void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } 239 240 // a utility function 241 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 242 243 virtual StructInstType *clone() const { return new StructInstType( *this ); } 244 virtual void accept( Visitor &v ) { v.visit( this ); } 245 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 246 private: 247 virtual std::string typeString() const; 248 249 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, 250 // where the structure used in this type is actually defined 251 StructDecl *baseStruct; 239 252 }; 240 253 241 254 class UnionInstType : public ReferenceToType { 242 typedef ReferenceToType Parent;243 public: 244 UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}245 UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}246 247 UnionDecl *get_baseUnion() const { return baseUnion; }248 void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }249 250 // a utility function251 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;252 253 virtual UnionInstType *clone() const { return new UnionInstType( *this ); }254 virtual void accept( Visitor &v ) { v.visit( this ); }255 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }256 private: 257 virtual std::string typeString() const;258 259 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,260 // where the union used in this type is actually defined261 UnionDecl *baseUnion;255 typedef ReferenceToType Parent; 256 public: 257 UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {} 258 UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {} 259 260 UnionDecl *get_baseUnion() const { return baseUnion; } 261 void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; } 262 263 // a utility function 264 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 265 266 virtual UnionInstType *clone() const { return new UnionInstType( *this ); } 267 virtual void accept( Visitor &v ) { v.visit( this ); } 268 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 269 private: 270 virtual std::string typeString() const; 271 272 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, 273 // where the union used in this type is actually defined 274 UnionDecl *baseUnion; 262 275 }; 263 276 264 277 class EnumInstType : public ReferenceToType { 265 typedef ReferenceToType Parent; 266 public: 267 EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 268 EnumInstType( const EnumInstType &other ) : Parent( other ) {} 269 270 virtual EnumInstType *clone() const { return new EnumInstType( *this ); } 271 virtual void accept( Visitor &v ) { v.visit( this ); } 272 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 273 274 private: 275 virtual std::string typeString() const; 278 typedef ReferenceToType Parent; 279 public: 280 EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 281 EnumInstType( const EnumInstType &other ) : Parent( other ) {} 282 283 virtual EnumInstType *clone() const { return new EnumInstType( *this ); } 284 virtual void accept( Visitor &v ) { v.visit( this ); } 285 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 286 private: 287 virtual std::string typeString() const; 276 288 }; 277 289 278 290 class ContextInstType : public ReferenceToType { 279 typedef ReferenceToType Parent;280 public: 281 ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}282 ContextInstType( const ContextInstType &other );283 ~ContextInstType();284 285 std::list< Declaration* >& get_members() { return members; }286 287 virtual ContextInstType *clone() const { return new ContextInstType( *this ); }288 virtual void accept( Visitor &v ) { v.visit( this ); }289 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }290 private: 291 virtual std::string typeString() const;292 293 // this member is filled in by the validate pass, which instantiates the members of the correponding294 // aggregate with the actual type parameters specified for this use of the context295 std::list< Declaration* > members;291 typedef ReferenceToType Parent; 292 public: 293 ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 294 ContextInstType( const ContextInstType &other ); 295 ~ContextInstType(); 296 297 std::list< Declaration* >& get_members() { return members; } 298 299 virtual ContextInstType *clone() const { return new ContextInstType( *this ); } 300 virtual void accept( Visitor &v ) { v.visit( this ); } 301 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 302 private: 303 virtual std::string typeString() const; 304 305 // this member is filled in by the validate pass, which instantiates the members of the correponding 306 // aggregate with the actual type parameters specified for this use of the context 307 std::list< Declaration* > members; 296 308 }; 297 309 298 310 class TypeInstType : public ReferenceToType { 299 typedef ReferenceToType Parent;300 public: 301 TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );302 TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );303 TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}304 305 TypeDecl *get_baseType() const { return baseType; }306 void set_baseType( TypeDecl *newValue );307 bool get_isFtype() const { return isFtype; }308 void set_isFtype( bool newValue ) { isFtype = newValue; }309 310 virtual TypeInstType *clone() const { return new TypeInstType( *this ); }311 virtual void accept( Visitor &v ) { v.visit( this ); }312 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }313 virtual void print( std::ostream &os, int indent = 0 ) const;314 private: 315 virtual std::string typeString() const;316 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,317 // where the type used here is actually defined318 TypeDecl *baseType;319 bool isFtype;311 typedef ReferenceToType Parent; 312 public: 313 TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ); 314 TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ); 315 TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {} 316 317 TypeDecl *get_baseType() const { return baseType; } 318 void set_baseType( TypeDecl *newValue ); 319 bool get_isFtype() const { return isFtype; } 320 void set_isFtype( bool newValue ) { isFtype = newValue; } 321 322 virtual TypeInstType *clone() const { return new TypeInstType( *this ); } 323 virtual void accept( Visitor &v ) { v.visit( this ); } 324 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 325 virtual void print( std::ostream &os, int indent = 0 ) const; 326 private: 327 virtual std::string typeString() const; 328 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, 329 // where the type used here is actually defined 330 TypeDecl *baseType; 331 bool isFtype; 320 332 }; 321 333 322 334 class TupleType : public Type { 323 335 public: 324 TupleType( const Type::Qualifiers &tq );325 TupleType( const TupleType& );326 virtual ~TupleType();327 328 std::list<Type*>& get_types() { return types; }329 330 virtual TupleType *clone() const { return new TupleType( *this ); }331 virtual void accept( Visitor &v ) { v.visit( this ); }332 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }333 virtual void print( std::ostream &os, int indent = 0 ) const;334 private: 335 std::list<Type*> types;336 TupleType( const Type::Qualifiers &tq ); 337 TupleType( const TupleType& ); 338 virtual ~TupleType(); 339 340 std::list<Type*>& get_types() { return types; } 341 342 virtual TupleType *clone() const { return new TupleType( *this ); } 343 virtual void accept( Visitor &v ) { v.visit( this ); } 344 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 345 virtual void print( std::ostream &os, int indent = 0 ) const; 346 private: 347 std::list<Type*> types; 336 348 }; 337 349 338 350 class TypeofType : public Type { 339 351 public: 340 TypeofType( const Type::Qualifiers &tq, Expression *expr );341 TypeofType( const TypeofType& );342 virtual ~TypeofType();343 344 Expression *get_expr() const { return expr; }345 void set_expr( Expression *newValue ) { expr = newValue; }346 347 virtual TypeofType *clone() const { return new TypeofType( *this ); }348 virtual void accept( Visitor &v ) { v.visit( this ); }349 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }350 virtual void print( std::ostream &os, int indent = 0 ) const;351 private: 352 Expression *expr;352 TypeofType( const Type::Qualifiers &tq, Expression *expr ); 353 TypeofType( const TypeofType& ); 354 virtual ~TypeofType(); 355 356 Expression *get_expr() const { return expr; } 357 void set_expr( Expression *newValue ) { expr = newValue; } 358 359 virtual TypeofType *clone() const { return new TypeofType( *this ); } 360 virtual void accept( Visitor &v ) { v.visit( this ); } 361 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 362 virtual void print( std::ostream &os, int indent = 0 ) const; 363 private: 364 Expression *expr; 353 365 }; 354 366 355 367 class AttrType : public Type { 356 368 public: 357 AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ); 358 AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ); 359 AttrType( const AttrType& ); 360 virtual ~AttrType(); 361 362 std::string get_name() const { return name; } 363 void set_name( const std::string &newValue ) { name = newValue; } 364 Expression *get_expr() const { return expr; } 365 void set_expr( Expression *newValue ) { expr = newValue; } 366 Type *get_type() const { return type; } 367 void set_type( Type *newValue ) { type = newValue; } 368 bool get_isType() const { return isType; } 369 void set_isType( bool newValue ) { isType = newValue; } 370 371 virtual AttrType *clone() const { return new AttrType( *this ); } 372 virtual void accept( Visitor &v ) { v.visit( this ); } 373 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 374 virtual void print( std::ostream &os, int indent = 0 ) const; 375 376 private: 377 std::string name; 378 Expression *expr; 379 Type *type; 380 bool isType; 369 AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ); 370 AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ); 371 AttrType( const AttrType& ); 372 virtual ~AttrType(); 373 374 std::string get_name() const { return name; } 375 void set_name( const std::string &newValue ) { name = newValue; } 376 Expression *get_expr() const { return expr; } 377 void set_expr( Expression *newValue ) { expr = newValue; } 378 Type *get_type() const { return type; } 379 void set_type( Type *newValue ) { type = newValue; } 380 bool get_isType() const { return isType; } 381 void set_isType( bool newValue ) { isType = newValue; } 382 383 virtual AttrType *clone() const { return new AttrType( *this ); } 384 virtual void accept( Visitor &v ) { v.visit( this ); } 385 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 386 virtual void print( std::ostream &os, int indent = 0 ) const; 387 private: 388 std::string name; 389 Expression *expr; 390 Type *type; 391 bool isType; 381 392 }; 382 393 383 394 inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { 384 isConst |= other.isConst;385 isVolatile |= other.isVolatile;386 isRestrict |= other.isRestrict;387 isLvalue |= other.isLvalue;388 isAtomic |= other.isAtomic;389 return *this;395 isConst |= other.isConst; 396 isVolatile |= other.isVolatile; 397 isRestrict |= other.isRestrict; 398 isLvalue |= other.isLvalue; 399 isAtomic |= other.isAtomic; 400 return *this; 390 401 } 391 402 392 403 inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) { 393 if ( other.isConst ) isConst = 0;394 if ( other.isVolatile ) isVolatile = 0;395 if ( other.isRestrict ) isRestrict = 0;396 if ( other.isAtomic ) isAtomic = 0;397 return *this;404 if ( other.isConst ) isConst = 0; 405 if ( other.isVolatile ) isVolatile = 0; 406 if ( other.isRestrict ) isRestrict = 0; 407 if ( other.isAtomic ) isAtomic = 0; 408 return *this; 398 409 } 399 410 400 411 inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) { 401 Qualifiers q = other;402 q += *this;403 return q;412 Qualifiers q = other; 413 q += *this; 414 return q; 404 415 } 405 416 406 417 inline bool Type::Qualifiers::operator==( const Qualifiers &other ) { 407 return isConst == other.isConst408 && isVolatile == other.isVolatile409 && isRestrict == other.isRestrict418 return isConst == other.isConst 419 && isVolatile == other.isVolatile 420 && isRestrict == other.isRestrict 410 421 // && isLvalue == other.isLvalue 411 && isAtomic == other.isAtomic;422 && isAtomic == other.isAtomic; 412 423 } 413 424 414 425 inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) { 415 return isConst != other.isConst416 || isVolatile != other.isVolatile417 || isRestrict != other.isRestrict426 return isConst != other.isConst 427 || isVolatile != other.isVolatile 428 || isRestrict != other.isRestrict 418 429 // || isLvalue != other.isLvalue 419 || isAtomic != other.isAtomic;430 || isAtomic != other.isAtomic; 420 431 } 421 432 422 433 inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) { 423 return isConst <= other.isConst424 && isVolatile <= other.isVolatile425 && isRestrict <= other.isRestrict434 return isConst <= other.isConst 435 && isVolatile <= other.isVolatile 436 && isRestrict <= other.isRestrict 426 437 // && isLvalue >= other.isLvalue 427 && isAtomic == other.isAtomic;438 && isAtomic == other.isAtomic; 428 439 } 429 440 430 441 inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) { 431 return isConst >= other.isConst432 && isVolatile >= other.isVolatile433 && isRestrict >= other.isRestrict442 return isConst >= other.isConst 443 && isVolatile >= other.isVolatile 444 && isRestrict >= other.isRestrict 434 445 // && isLvalue <= other.isLvalue 435 && isAtomic == other.isAtomic;446 && isAtomic == other.isAtomic; 436 447 } 437 448 438 449 inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) { 439 return operator!=( other ) && operator<=( other );450 return operator!=( other ) && operator<=( other ); 440 451 } 441 452 442 453 inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) { 443 return operator!=( other ) && operator>=( other );454 return operator!=( other ) && operator>=( other ); 444 455 } 445 456 446 457 #endif // TYPE_H 458 459 // Local Variables: // 460 // tab-width: 4 // 461 // mode: c++ // 462 // compile-command: "make install" // 463 // End: // -
translator/SynTree/TypeDecl.cc
ra32b204 r0dd3a2f 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 // TypeDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:02:11 2015 13 // Update Count : 1 14 // 15 1 16 #include "Declaration.h" 2 17 #include "Type.h" 3 18 #include "utility.h" 4 19 5 6 TypeDecl::TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ) 7 : Parent( name, sc, type ), kind( kind ) 8 { 20 TypeDecl::TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ) : Parent( name, sc, type ), kind( kind ) { 9 21 } 10 22 11 TypeDecl::TypeDecl( const TypeDecl &other ) 12 : Parent( other ), kind( other.kind ) 13 { 23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ) { 14 24 } 15 25 16 std::string 17 TypeDecl::typeString() const 18 { 19 static const char *kindNames[] = { "type", "incomplete type", "function type" }; 20 return kindNames[ kind ]; 26 std::string TypeDecl::typeString() const { 27 static const char *kindNames[] = { "type", "incomplete type", "function type" }; 28 return kindNames[ kind ]; 21 29 } 22 30 31 // Local Variables: // 32 // tab-width: 4 // 33 // mode: c++ // 34 // compile-command: "make install" // 35 // End: // -
translator/SynTree/TypeExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeExpr.cc,v 1.4 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // TypeExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:03:15 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Expression.h" … … 10 18 #include "utility.h" 11 19 12 13 TypeExpr::TypeExpr( Type *type ) 14 : type( type ) 15 { 20 TypeExpr::TypeExpr( Type *type ) : type( type ) { 16 21 } 17 22 18 TypeExpr::TypeExpr( const TypeExpr &other ) 19 : type( maybeClone( other.type ) ) 20 { 23 TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) { 21 24 } 22 25 23 TypeExpr::~TypeExpr() 24 { 25 delete type; 26 TypeExpr::~TypeExpr() { 27 delete type; 26 28 } 27 29 28 void 29 TypeExpr::print( std::ostream &os, int indent ) const 30 { 31 if ( type ) type->print( os, indent ); 32 Expression::print( os, indent ); 30 void TypeExpr::print( std::ostream &os, int indent ) const { 31 if ( type ) type->print( os, indent ); 32 Expression::print( os, indent ); 33 33 } 34 34 35 // Local Variables: // 36 // tab-width: 4 // 37 // mode: c++ // 38 // compile-command: "make install" // 39 // End: // -
translator/SynTree/TypeSubstitution.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeSubstitution.cc,v 1.9 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // TypeSubstitution.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:10:04 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" 9 17 #include "TypeSubstitution.h" 10 18 11 12 TypeSubstitution::TypeSubstitution() 13 { 19 TypeSubstitution::TypeSubstitution() { 14 20 } 15 21 16 TypeSubstitution::TypeSubstitution( const TypeSubstitution &other ) 17 { 18 initialize( other, *this ); 22 TypeSubstitution::TypeSubstitution( const TypeSubstitution &other ) { 23 initialize( other, *this ); 19 24 } 20 25 21 TypeSubstitution::~TypeSubstitution() 22 { 23 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 24 delete( i->second ); 25 } 26 for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 27 delete( i->second ); 28 } 26 TypeSubstitution::~TypeSubstitution() { 27 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 28 delete( i->second ); 29 } 30 for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 31 delete( i->second ); 32 } 29 33 } 30 34 31 TypeSubstitution & 32 TypeSubstitution::operator=( const TypeSubstitution &other ) 33 { 34 if ( this == &other ) return *this; 35 initialize( other, *this ); 36 return *this; 35 TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) { 36 if ( this == &other ) return *this; 37 initialize( other, *this ); 38 return *this; 37 39 } 38 40 39 void 40 TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) 41 { 42 dest.typeEnv.clear(); 43 dest.varEnv.clear(); 44 dest.add( src ); 41 void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) { 42 dest.typeEnv.clear(); 43 dest.varEnv.clear(); 44 dest.add( src ); 45 45 } 46 46 47 void 48 TypeSubstitution::add( const TypeSubstitution &other ) 49 { 50 for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) { 51 typeEnv[ i->first ] = i->second->clone(); 52 } 53 for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) { 54 varEnv[ i->first ] = i->second->clone(); 55 } 47 void TypeSubstitution::add( const TypeSubstitution &other ) { 48 for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) { 49 typeEnv[ i->first ] = i->second->clone(); 50 } // for 51 for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) { 52 varEnv[ i->first ] = i->second->clone(); 53 } // for 56 54 } 57 55 58 void 59 TypeSubstitution::add( std::string formalType, Type *actualType ) 60 { 61 TypeEnvType::iterator i = typeEnv.find( formalType ); 62 if ( i != typeEnv.end() ) { 63 delete i->second; 64 } 65 typeEnv[ formalType ] = actualType->clone(); 56 void TypeSubstitution::add( std::string formalType, Type *actualType ) { 57 TypeEnvType::iterator i = typeEnv.find( formalType ); 58 if ( i != typeEnv.end() ) { 59 delete i->second; 60 } // if 61 typeEnv[ formalType ] = actualType->clone(); 66 62 } 67 63 68 void 69 TypeSubstitution::remove( std::string formalType ) 70 { 71 TypeEnvType::iterator i = typeEnv.find( formalType ); 72 if ( i != typeEnv.end() ) { 73 delete i->second; 74 typeEnv.erase( formalType ); 75 } 64 void TypeSubstitution::remove( std::string formalType ) { 65 TypeEnvType::iterator i = typeEnv.find( formalType ); 66 if ( i != typeEnv.end() ) { 67 delete i->second; 68 typeEnv.erase( formalType ); 69 } // if 76 70 } 77 71 78 Type * 79 TypeSubstitution::lookup( std::string formalType ) const 80 { 81 TypeEnvType::const_iterator i = typeEnv.find( formalType ); 82 if ( i == typeEnv.end() ) { 83 return 0; 84 } else { 85 return i->second; 86 } 72 Type *TypeSubstitution::lookup( std::string formalType ) const { 73 TypeEnvType::const_iterator i = typeEnv.find( formalType ); 74 if ( i == typeEnv.end() ) { 75 return 0; 76 } else { 77 return i->second; 78 } // if 87 79 } 88 80 89 bool 90 TypeSubstitution::empty() const 91 { 92 return typeEnv.empty() && varEnv.empty(); 81 bool TypeSubstitution::empty() const { 82 return typeEnv.empty() && varEnv.empty(); 93 83 } 94 84 95 void 96 TypeSubstitution::normalize() 97 { 98 do { 99 subCount = 0; 100 freeOnly = true; 101 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 102 i->second = i->second->acceptMutator( *this ); 103 } 104 } while ( subCount ); 85 void TypeSubstitution::normalize() { 86 do { 87 subCount = 0; 88 freeOnly = true; 89 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 90 i->second = i->second->acceptMutator( *this ); 91 } 92 } while ( subCount ); 105 93 } 106 94 107 Type* 108 TypeSubstitution::mutate(TypeInstType *inst) 109 { 110 BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() ); 111 if ( bound != boundVars.end() ) return inst; 112 113 TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() ); 114 if ( i == typeEnv.end() ) { 115 return inst; 116 } else { 95 Type * TypeSubstitution::mutate( TypeInstType *inst ) { 96 BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() ); 97 if ( bound != boundVars.end() ) return inst; 98 99 TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() ); 100 if ( i == typeEnv.end() ) { 101 return inst; 102 } else { 117 103 /// std::cout << "found " << inst->get_name() << ", replacing with "; 118 104 /// i->second->print( std::cout ); 119 105 /// std::cout << std::endl; 120 subCount++;121 Type *newtype = i->second->clone();122 newtype->get_qualifiers() += inst->get_qualifiers();123 delete inst;124 return newtype;125 } 106 subCount++; 107 Type *newtype = i->second->clone(); 108 newtype->get_qualifiers() += inst->get_qualifiers(); 109 delete inst; 110 return newtype; 111 } // if 126 112 } 127 113 128 Expression* 129 TypeSubstitution::mutate(NameExpr *nameExpr) 130 { 131 VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() ); 132 if ( i == varEnv.end() ) { 133 return nameExpr; 134 } else { 135 subCount++; 136 delete nameExpr; 137 return i->second->clone(); 138 } 114 Expression * TypeSubstitution::mutate( NameExpr *nameExpr ) { 115 VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() ); 116 if ( i == varEnv.end() ) { 117 return nameExpr; 118 } else { 119 subCount++; 120 delete nameExpr; 121 return i->second->clone(); 122 } // if 139 123 } 140 124 141 125 template< typename TypeClass > 142 Type * 143 TypeSubstitution::handleType( TypeClass *type ) 144 { 145 BoundVarsType oldBoundVars( boundVars ); 146 if ( freeOnly ) { 147 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 148 boundVars.insert( (*tyvar)->get_name() ); 149 } 150 } 151 Type *ret = Mutator::mutate( type ); 152 boundVars = oldBoundVars; 153 return ret; 126 Type *TypeSubstitution::handleType( TypeClass *type ) { 127 BoundVarsType oldBoundVars( boundVars ); 128 if ( freeOnly ) { 129 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 130 boundVars.insert( (*tyvar )->get_name() ); 131 } // for 132 } // if 133 Type *ret = Mutator::mutate( type ); 134 boundVars = oldBoundVars; 135 return ret; 154 136 } 155 137 156 Type* 157 TypeSubstitution::mutate(VoidType *basicType) 158 { 159 return handleType( basicType ); 138 Type * TypeSubstitution::mutate( VoidType *basicType ) { 139 return handleType( basicType ); 160 140 } 161 141 162 Type* 163 TypeSubstitution::mutate(BasicType *basicType) 164 { 165 return handleType( basicType ); 142 Type * TypeSubstitution::mutate( BasicType *basicType ) { 143 return handleType( basicType ); 166 144 } 167 145 168 Type* 169 TypeSubstitution::mutate(PointerType *pointerType) 170 { 171 return handleType( pointerType ); 146 Type * TypeSubstitution::mutate( PointerType *pointerType ) { 147 return handleType( pointerType ); 172 148 } 173 149 174 Type* 175 TypeSubstitution::mutate(ArrayType *arrayType) 176 { 177 return handleType( arrayType ); 150 Type * TypeSubstitution::mutate( ArrayType *arrayType ) { 151 return handleType( arrayType ); 178 152 } 179 153 180 Type* 181 TypeSubstitution::mutate(FunctionType *functionType) 182 { 183 return handleType( functionType ); 154 Type * TypeSubstitution::mutate( FunctionType *functionType ) { 155 return handleType( functionType ); 184 156 } 185 157 186 Type* 187 TypeSubstitution::mutate(StructInstType *aggregateUseType) 188 { 189 return handleType( aggregateUseType ); 158 Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) { 159 return handleType( aggregateUseType ); 190 160 } 191 161 192 Type* 193 TypeSubstitution::mutate(UnionInstType *aggregateUseType) 194 { 195 return handleType( aggregateUseType ); 162 Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) { 163 return handleType( aggregateUseType ); 196 164 } 197 165 198 Type* 199 TypeSubstitution::mutate(EnumInstType *aggregateUseType) 200 { 201 return handleType( aggregateUseType ); 166 Type * TypeSubstitution::mutate( EnumInstType *aggregateUseType ) { 167 return handleType( aggregateUseType ); 202 168 } 203 169 204 Type* 205 TypeSubstitution::mutate(ContextInstType *aggregateUseType) 206 { 207 return handleType( aggregateUseType ); 170 Type * TypeSubstitution::mutate( ContextInstType *aggregateUseType ) { 171 return handleType( aggregateUseType ); 208 172 } 209 173 210 Type* 211 TypeSubstitution::mutate(TupleType *tupleType) 212 { 213 return handleType( tupleType ); 174 Type * TypeSubstitution::mutate( TupleType *tupleType ) { 175 return handleType( tupleType ); 214 176 } 215 177 216 void 217 TypeSubstitution::print( std::ostream &os, int indent ) const 218 { 219 os << std::string( indent, ' ' ) << "Types:" << std::endl; 220 for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 221 os << std::string( indent+2, ' ' ) << i->first << " -> "; 222 i->second->print( os, indent+4 ); 223 os << std::endl; 224 } 225 os << std::string( indent, ' ' ) << "Non-types:" << std::endl; 226 for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 227 os << std::string( indent+2, ' ' ) << i->first << " -> "; 228 i->second->print( os, indent+4 ); 229 os << std::endl; 230 } 178 void TypeSubstitution::print( std::ostream &os, int indent ) const { 179 os << std::string( indent, ' ' ) << "Types:" << std::endl; 180 for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 181 os << std::string( indent+2, ' ' ) << i->first << " -> "; 182 i->second->print( os, indent+4 ); 183 os << std::endl; 184 } // for 185 os << std::string( indent, ' ' ) << "Non-types:" << std::endl; 186 for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 187 os << std::string( indent+2, ' ' ) << i->first << " -> "; 188 i->second->print( os, indent+4 ); 189 os << std::endl; 190 } // for 231 191 } 232 192 193 // Local Variables: // 194 // tab-width: 4 // 195 // mode: c++ // 196 // compile-command: "make install" // 197 // End: // -
translator/SynTree/TypeSubstitution.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeSubstitution.h,v 1.9 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 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 // TypeSubstitution.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:12:30 2015 13 // Update Count : 1 14 // 7 15 8 #ifndef SYNTREE_TYPESUBSTITUTION_H9 #define SYNTREE_TYPESUBSTITUTION_H16 #ifndef TYPESUBSTITUTION_H 17 #define TYPESUBSTITUTION_H 10 18 11 19 #include <map> … … 17 25 #include "SynTree/Expression.h" 18 26 27 class TypeSubstitution : public Mutator { 28 typedef Mutator Parent; 29 public: 30 TypeSubstitution(); 31 template< typename FormalIterator, typename ActualIterator > 32 TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 33 TypeSubstitution( const TypeSubstitution &other ); 34 virtual ~TypeSubstitution(); 35 36 TypeSubstitution &operator=( const TypeSubstitution &other ); 37 38 template< typename SynTreeClass > int apply( SynTreeClass *&input ); 39 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ); 40 41 void add( std::string formalType, Type *actualType ); 42 void add( const TypeSubstitution &other ); 43 void remove( std::string formalType ); 44 Type *lookup( std::string formalType ) const; 45 bool empty() const; 46 47 template< typename FormalIterator, typename ActualIterator > 48 void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 49 50 template< typename TypeInstListIterator > 51 void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ); 52 53 void normalize(); 19 54 20 class TypeSubstitution : public Mutator 21 { 22 typedef Mutator Parent; 23 24 public: 25 TypeSubstitution(); 26 template< typename FormalIterator, typename ActualIterator > 27 TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 28 TypeSubstitution( const TypeSubstitution &other ); 29 virtual ~TypeSubstitution(); 30 31 TypeSubstitution &operator=( const TypeSubstitution &other ); 32 33 template< typename SynTreeClass > int apply( SynTreeClass *&input ); 34 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ); 35 36 void add( std::string formalType, Type *actualType ); 37 void add( const TypeSubstitution &other ); 38 void remove( std::string formalType ); 39 Type *lookup( std::string formalType ) const; 40 bool empty() const; 41 42 template< typename FormalIterator, typename ActualIterator > 43 void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 44 45 template< typename TypeInstListIterator > 46 void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ); 47 48 void normalize(); 55 void print( std::ostream &os, int indent = 0 ) const; 56 TypeSubstitution *clone() const { return new TypeSubstitution( *this ); } 57 private: 58 virtual Type* mutate(TypeInstType *aggregateUseType); 59 virtual Expression* mutate(NameExpr *nameExpr); 60 61 template< typename TypeClass > Type *handleType( TypeClass *type ); 62 63 virtual Type* mutate(VoidType *basicType); 64 virtual Type* mutate(BasicType *basicType); 65 virtual Type* mutate(PointerType *pointerType); 66 virtual Type* mutate(ArrayType *arrayType); 67 virtual Type* mutate(FunctionType *functionType); 68 virtual Type* mutate(StructInstType *aggregateUseType); 69 virtual Type* mutate(UnionInstType *aggregateUseType); 70 virtual Type* mutate(EnumInstType *aggregateUseType); 71 virtual Type* mutate(ContextInstType *aggregateUseType); 72 virtual Type* mutate(TupleType *tupleType); 73 74 // TODO: worry about traversing into a forall-qualified function type or type decl with assertions 75 76 void initialize( const TypeSubstitution &src, TypeSubstitution &dest ); 49 77 50 void print( std::ostream &os, int indent = 0 ) const; 51 TypeSubstitution *clone() const { return new TypeSubstitution( *this ); } 52 53 private: 54 virtual Type* mutate(TypeInstType *aggregateUseType); 55 virtual Expression* mutate(NameExpr *nameExpr); 56 57 template< typename TypeClass > Type *handleType( TypeClass *type ); 58 59 virtual Type* mutate(VoidType *basicType); 60 virtual Type* mutate(BasicType *basicType); 61 virtual Type* mutate(PointerType *pointerType); 62 virtual Type* mutate(ArrayType *arrayType); 63 virtual Type* mutate(FunctionType *functionType); 64 virtual Type* mutate(StructInstType *aggregateUseType); 65 virtual Type* mutate(UnionInstType *aggregateUseType); 66 virtual Type* mutate(EnumInstType *aggregateUseType); 67 virtual Type* mutate(ContextInstType *aggregateUseType); 68 virtual Type* mutate(TupleType *tupleType); 69 70 // TODO: worry about traversing into a forall-qualified function type or type decl with assertions 71 72 void initialize( const TypeSubstitution &src, TypeSubstitution &dest ); 73 74 typedef std::map< std::string, Type* > TypeEnvType; 75 typedef std::map< std::string, Expression* > VarEnvType; 76 typedef std::set< std::string > BoundVarsType; 77 TypeEnvType typeEnv; 78 VarEnvType varEnv; 79 BoundVarsType boundVars; 80 int subCount; 81 bool freeOnly; 78 typedef std::map< std::string, Type* > TypeEnvType; 79 typedef std::map< std::string, Expression* > VarEnvType; 80 typedef std::set< std::string > BoundVarsType; 81 TypeEnvType typeEnv; 82 VarEnvType varEnv; 83 BoundVarsType boundVars; 84 int subCount; 85 bool freeOnly; 82 86 }; 83 87 84 88 template< typename FormalIterator, typename ActualIterator > 85 void 86 TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) 87 { 88 // FormalIterator points to a TypeDecl 89 // ActualIterator points to a Type 90 FormalIterator formalIt = formalBegin; 91 ActualIterator actualIt = actualBegin; 92 for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) { 93 if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) { 94 if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) { 95 if ( formal->get_name() != "" ) { 96 TypeEnvType::iterator i = typeEnv.find( formal->get_name() ); 97 if ( i != typeEnv.end() ) { 98 delete i->second; 99 } 100 typeEnv[ formal->get_name() ] = actual->get_type()->clone(); 101 } 102 } else { 103 throw SemanticError( "Attempt to provide non-type parameter for type parameter", formal ); 104 } 105 } else { 106 // TODO: type check the formal and actual parameters 107 if ( (*formalIt)->get_name() != "" ) { 108 varEnv[ (*formalIt)->get_name() ] = (*actualIt)->clone(); 109 } 110 } 111 } 89 void TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) { 90 // FormalIterator points to a TypeDecl 91 // ActualIterator points to a Type 92 FormalIterator formalIt = formalBegin; 93 ActualIterator actualIt = actualBegin; 94 for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) { 95 if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) { 96 if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) { 97 if ( formal->get_name() != "" ) { 98 TypeEnvType::iterator i = typeEnv.find( formal->get_name() ); 99 if ( i != typeEnv.end() ) { 100 delete i->second; 101 } // if 102 typeEnv[ formal->get_name() ] = actual->get_type()->clone(); 103 } // if 104 } else { 105 throw SemanticError( "Attempt to provide non-type parameter for type parameter", formal ); 106 } // if 107 } else { 108 // TODO: type check the formal and actual parameters 109 if ( (*formalIt)->get_name() != "" ) { 110 varEnv[ (*formalIt)->get_name() ] = (*actualIt)->clone(); 111 } // if 112 } // if 113 } // for 112 114 } 113 115 … … 115 117 TypeSubstitution::TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) 116 118 { 117 add( formalBegin, formalEnd, actualBegin );119 add( formalBegin, formalEnd, actualBegin ); 118 120 } 119 121 120 122 template< typename SynTreeClass > 121 int 122 TypeSubstitution::apply( SynTreeClass *&input ) 123 { 124 assert( input ); 125 subCount = 0; 126 freeOnly = false; 127 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 128 assert( input ); 123 int TypeSubstitution::apply( SynTreeClass *&input ) { 124 assert( input ); 125 subCount = 0; 126 freeOnly = false; 127 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 128 assert( input ); 129 129 /// std::cout << "substitution result is: "; 130 130 /// newType->print( std::cout ); 131 131 /// std::cout << std::endl; 132 return subCount;132 return subCount; 133 133 } 134 134 135 135 template< typename SynTreeClass > 136 int 137 TypeSubstitution::applyFree( SynTreeClass *&input ) 138 { 139 assert( input ); 140 subCount = 0; 141 freeOnly = true; 142 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 143 assert( input ); 136 int TypeSubstitution::applyFree( SynTreeClass *&input ) { 137 assert( input ); 138 subCount = 0; 139 freeOnly = true; 140 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 141 assert( input ); 144 142 /// std::cout << "substitution result is: "; 145 143 /// newType->print( std::cout ); 146 144 /// std::cout << std::endl; 147 return subCount;145 return subCount; 148 146 } 149 147 150 148 template< typename TypeInstListIterator > 151 void 152 TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) 153 { 154 while ( begin != end ) { 155 TypeEnvType::iterator cur = typeEnv.find( (*begin++)->get_name() ); 156 if ( cur != typeEnv.end() ) { 157 result.typeEnv[ cur->first ] = cur->second; 158 typeEnv.erase( cur ); 159 } 160 } 149 void TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) { 150 while ( begin != end ) { 151 TypeEnvType::iterator cur = typeEnv.find( (*begin++)->get_name() ); 152 if ( cur != typeEnv.end() ) { 153 result.typeEnv[ cur->first ] = cur->second; 154 typeEnv.erase( cur ); 155 } // if 156 } // while 161 157 } 162 158 163 159 // helper function 164 160 template< typename FormalIterator, typename ActualIterator, typename MemberIterator, typename OutputIterator > 165 void 166 applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out ) 167 { 168 // Instantiate each member of the context given the actual parameters specified, and store the 169 // instantiations for use by the indexer 161 void applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out ) { 162 // Instantiate each member of the context given the actual parameters specified, and store the 163 // instantiations for use by the indexer 170 164 171 TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual );172 for ( std::list< Declaration* >::iterator i = memberBegin; i != memberEnd; ++i ) {173 Declaration *newdecl = (*i)->clone();174 sub.apply( newdecl );175 *out++ = newdecl;176 } 165 TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual ); 166 for ( std::list< Declaration* >::iterator i = memberBegin; i != memberEnd; ++i ) { 167 Declaration *newdecl = (*i)->clone(); 168 sub.apply( newdecl ); 169 *out++ = newdecl; 170 } // for 177 171 } 178 172 173 #endif // TYPESUBSTITUTION_H 179 174 180 #endif /* #ifndef SYNTREE_TYPESUBSTITUTION_H */ 175 // Local Variables: // 176 // tab-width: 4 // 177 // mode: c++ // 178 // compile-command: "make install" // 179 // End: // -
translator/SynTree/TypeofType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeofType.cc,v 1.3 2005/08/29 20:59:27 rcbilson Exp $ 5 * 6 */ 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 // TypeofType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:13:29 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" … … 10 18 #include "utility.h" 11 19 12 13 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr ) 14 : Type( tq ), expr( expr ) 15 { 20 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr ) : Type( tq ), expr( expr ) { 16 21 } 17 22 18 TypeofType::TypeofType( const TypeofType &other ) 19 : Type( other ), expr( maybeClone( other.expr ) ) 20 { 23 TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) { 21 24 } 22 25 23 TypeofType::~TypeofType() 24 { 25 delete expr; 26 TypeofType::~TypeofType() { 27 delete expr; 26 28 } 27 29 28 void 29 TypeofType::print( std::ostream &os, int indent ) const 30 { 31 Type::print( os, indent ); 32 os << "type-of expression "; 33 if ( expr ) { 34 expr->print( os, indent ); 35 } 30 void TypeofType::print( std::ostream &os, int indent ) const { 31 Type::print( os, indent ); 32 os << "type-of expression "; 33 if ( expr ) { 34 expr->print( os, indent ); 35 } 36 36 } 37 37 38 // Local Variables: // 39 // tab-width: 4 // 40 // mode: c++ // 41 // compile-command: "make install" // 42 // End: // -
translator/SynTree/Visitor.cc
ra32b204 r0dd3a2f 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 // Visitor.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:14:51 2015 13 // Update Count : 2 14 // 15 1 16 #include <cassert> 2 17 #include "Visitor.h" … … 8 23 #include "Constant.h" 9 24 10 11 25 Visitor::Visitor() {} 12 26 13 27 Visitor::~Visitor() {} 14 28 15 void Visitor::visit(ObjectDecl *objectDecl) { 16 maybeAccept( objectDecl->get_type(), *this ); 17 maybeAccept( objectDecl->get_init(), *this ); 18 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 19 } 20 21 void Visitor::visit(FunctionDecl *functionDecl) { 22 maybeAccept( functionDecl->get_functionType(), *this ); 23 acceptAll( functionDecl->get_oldDecls(), *this ); 24 maybeAccept( functionDecl->get_statements(), *this ); 25 } 26 27 void Visitor::visit(AggregateDecl *aggregateDecl) { 28 acceptAll( aggregateDecl->get_parameters(), *this ); 29 acceptAll( aggregateDecl->get_members(), *this ); 30 } 31 32 void Visitor::visit(StructDecl *aggregateDecl) { 33 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 34 } 35 36 void Visitor::visit(UnionDecl *aggregateDecl) { 37 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 38 } 39 40 void Visitor::visit(EnumDecl *aggregateDecl) { 41 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 42 } 43 44 void Visitor::visit(ContextDecl *aggregateDecl) { 45 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 46 } 47 48 void Visitor::visit(NamedTypeDecl *typeDecl) { 49 acceptAll( typeDecl->get_parameters(), *this ); 50 acceptAll( typeDecl->get_assertions(), *this ); 51 maybeAccept( typeDecl->get_base(), *this ); 52 } 53 54 void Visitor::visit(TypeDecl *typeDecl) { 55 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 56 } 57 58 void Visitor::visit(TypedefDecl *typeDecl) { 59 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 60 } 61 62 void Visitor::visit(CompoundStmt *compoundStmt) { 63 acceptAll( compoundStmt->get_kids(), *this ); 64 } 65 66 void Visitor::visit(ExprStmt *exprStmt) { 67 maybeAccept( exprStmt->get_expr(), *this ); 68 } 69 70 void Visitor::visit(IfStmt *ifStmt) { 71 maybeAccept( ifStmt->get_condition(), *this ); 72 maybeAccept( ifStmt->get_thenPart(), *this ); 73 maybeAccept( ifStmt->get_elsePart(), *this ); 74 } 75 76 void Visitor::visit(WhileStmt *whileStmt) { 77 maybeAccept( whileStmt->get_condition(), *this ); 78 maybeAccept( whileStmt->get_body(), *this ); 79 } 80 81 void Visitor::visit(ForStmt *forStmt) { 82 // ForStmt still needs to be fixed 83 maybeAccept( forStmt->get_initialization(), *this ); 84 maybeAccept( forStmt->get_condition(), *this ); 85 maybeAccept( forStmt->get_increment(), *this ); 86 maybeAccept( forStmt->get_body(), *this ); 87 } 88 89 void Visitor::visit(SwitchStmt *switchStmt) { 90 maybeAccept( switchStmt->get_condition(), *this ); 91 acceptAll( switchStmt->get_branches(), *this ); 92 } 93 94 void Visitor::visit(ChooseStmt *switchStmt) { 95 maybeAccept( switchStmt->get_condition(), *this ); 96 acceptAll( switchStmt->get_branches(), *this ); 97 } 98 99 void Visitor::visit(FallthruStmt *fallthruStmt){} 100 101 void Visitor::visit(CaseStmt *caseStmt) { 102 maybeAccept( caseStmt->get_condition(), *this ); 103 acceptAll( caseStmt->get_statements(), *this ); 104 } 105 106 void Visitor::visit(BranchStmt *branchStmt) { 107 } 108 109 void Visitor::visit(ReturnStmt *returnStmt) { 110 maybeAccept( returnStmt->get_expr(), *this ); 111 } 112 113 void Visitor::visit(TryStmt *tryStmt) { 114 maybeAccept( tryStmt->get_block(), *this ); 115 acceptAll( tryStmt->get_catchers(), *this ); 116 } 117 118 void Visitor::visit(CatchStmt *catchStmt) { 119 maybeAccept( catchStmt->get_decl(), *this ); 120 maybeAccept( catchStmt->get_body(), *this ); 121 } 122 123 void Visitor::visit(FinallyStmt *finalStmt) { 124 maybeAccept( finalStmt->get_block(), *this ); 125 } 126 127 void Visitor::visit(NullStmt *nullStmt) { 128 } 129 130 void Visitor::visit(DeclStmt *declStmt) { 131 maybeAccept( declStmt->get_decl(), *this ); 132 } 133 134 void Visitor::visit(ApplicationExpr *applicationExpr) { 135 acceptAll( applicationExpr->get_results(), *this ); 136 maybeAccept( applicationExpr->get_function(), *this ); 137 acceptAll( applicationExpr->get_args(), *this ); 138 } 139 140 void Visitor::visit(UntypedExpr *untypedExpr) { 141 acceptAll( untypedExpr->get_results(), *this ); 142 acceptAll( untypedExpr->get_args(), *this ); 143 } 144 145 void Visitor::visit(NameExpr *nameExpr) { 146 acceptAll( nameExpr->get_results(), *this ); 147 } 148 149 void Visitor::visit(AddressExpr *addressExpr) { 150 acceptAll( addressExpr->get_results(), *this ); 151 maybeAccept( addressExpr->get_arg(), *this ); 152 } 153 154 void Visitor::visit(LabelAddressExpr *labAddressExpr) { 155 acceptAll( labAddressExpr->get_results(), *this ); 156 maybeAccept( labAddressExpr->get_arg(), *this ); 157 } 158 159 void Visitor::visit(CastExpr *castExpr) { 160 acceptAll( castExpr->get_results(), *this ); 161 maybeAccept( castExpr->get_arg(), *this ); 162 } 163 164 void Visitor::visit(UntypedMemberExpr *memberExpr) { 165 acceptAll( memberExpr->get_results(), *this ); 166 maybeAccept( memberExpr->get_aggregate(), *this ); 167 } 168 169 void Visitor::visit(MemberExpr *memberExpr) { 170 acceptAll( memberExpr->get_results(), *this ); 171 maybeAccept( memberExpr->get_aggregate(), *this ); 172 } 173 174 void Visitor::visit(VariableExpr *variableExpr) { 175 acceptAll( variableExpr->get_results(), *this ); 176 } 177 178 void Visitor::visit(ConstantExpr *constantExpr) { 179 acceptAll( constantExpr->get_results(), *this ); 180 maybeAccept( constantExpr->get_constant(), *this ); 181 } 182 183 void Visitor::visit(SizeofExpr *sizeofExpr) { 184 acceptAll( sizeofExpr->get_results(), *this ); 185 if ( sizeofExpr->get_isType() ) { 186 maybeAccept( sizeofExpr->get_type(), *this ); 187 } else { 188 maybeAccept( sizeofExpr->get_expr(), *this ); 189 } 190 } 191 192 void Visitor::visit(AttrExpr *attrExpr) { 193 acceptAll( attrExpr->get_results(), *this ); 194 if ( attrExpr->get_isType() ) { 195 maybeAccept( attrExpr->get_type(), *this ); 196 } else { 197 maybeAccept( attrExpr->get_expr(), *this ); 198 } 199 } 200 201 void Visitor::visit(LogicalExpr *logicalExpr) { 202 acceptAll( logicalExpr->get_results(), *this ); 203 maybeAccept( logicalExpr->get_arg1(), *this ); 204 maybeAccept( logicalExpr->get_arg2(), *this ); 205 } 206 207 void Visitor::visit(ConditionalExpr *conditionalExpr) { 208 acceptAll( conditionalExpr->get_results(), *this ); 209 maybeAccept( conditionalExpr->get_arg1(), *this ); 210 maybeAccept( conditionalExpr->get_arg2(), *this ); 211 maybeAccept( conditionalExpr->get_arg3(), *this ); 212 } 213 214 void Visitor::visit(CommaExpr *commaExpr) { 215 acceptAll( commaExpr->get_results(), *this ); 216 maybeAccept( commaExpr->get_arg1(), *this ); 217 maybeAccept( commaExpr->get_arg2(), *this ); 218 } 219 220 void Visitor::visit(TupleExpr *tupleExpr) { 221 acceptAll( tupleExpr->get_results(), *this ); 222 acceptAll( tupleExpr->get_exprs(), *this ); 223 } 224 225 void Visitor::visit(SolvedTupleExpr *tupleExpr) { 226 acceptAll( tupleExpr->get_results(), *this ); 227 acceptAll( tupleExpr->get_exprs(), *this ); 228 } 229 230 void Visitor::visit(TypeExpr *typeExpr) { 231 acceptAll( typeExpr->get_results(), *this ); 232 maybeAccept( typeExpr->get_type(), *this ); 233 } 234 235 void Visitor::visit(UntypedValofExpr *valofExpr) { 236 acceptAll( valofExpr->get_results(), *this ); 237 maybeAccept( valofExpr->get_body(), *this ); 238 } 239 240 void Visitor::visit(VoidType *voidType) { 241 acceptAll( voidType->get_forall(), *this ); 242 } 243 244 void Visitor::visit(BasicType *basicType) { 245 acceptAll( basicType->get_forall(), *this ); 246 } 247 248 void Visitor::visit(PointerType *pointerType) { 249 acceptAll( pointerType->get_forall(), *this ); 250 maybeAccept( pointerType->get_base(), *this ); 251 } 252 253 void Visitor::visit(ArrayType *arrayType) { 254 acceptAll( arrayType->get_forall(), *this ); 255 maybeAccept( arrayType->get_dimension(), *this ); 256 maybeAccept( arrayType->get_base(), *this ); 257 } 258 259 void Visitor::visit(FunctionType *functionType) { 260 acceptAll( functionType->get_forall(), *this ); 261 acceptAll( functionType->get_returnVals(), *this ); 262 acceptAll( functionType->get_parameters(), *this ); 263 } 264 265 void Visitor::visit(ReferenceToType *aggregateUseType) { 266 acceptAll( aggregateUseType->get_forall(), *this ); 267 acceptAll( aggregateUseType->get_parameters(), *this ); 268 } 269 270 void Visitor::visit(StructInstType *aggregateUseType) { 271 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 272 } 273 274 void Visitor::visit(UnionInstType *aggregateUseType) { 275 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 276 } 277 278 void Visitor::visit(EnumInstType *aggregateUseType) { 279 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 280 } 281 282 void Visitor::visit(ContextInstType *aggregateUseType) { 283 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 284 acceptAll( aggregateUseType->get_members(), *this ); 285 } 286 287 void Visitor::visit(TypeInstType *aggregateUseType) { 288 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 289 } 290 291 void Visitor::visit(TupleType *tupleType) { 292 acceptAll( tupleType->get_forall(), *this ); 293 acceptAll( tupleType->get_types(), *this ); 294 } 295 296 void Visitor::visit(TypeofType *typeofType) { 297 assert( typeofType->get_expr() ); 298 typeofType->get_expr()->accept( *this ); 299 } 300 301 void Visitor::visit(AttrType *attrType) { 302 if ( attrType->get_isType() ) { 303 assert( attrType->get_type() ); 304 attrType->get_type()->accept( *this ); 305 } else { 306 assert( attrType->get_expr() ); 307 attrType->get_expr()->accept( *this ); 308 } 309 } 310 311 void Visitor::visit(SingleInit *singleInit) { 312 singleInit->get_value()->accept( *this ); 313 } 314 315 void Visitor::visit(ListInit *listInit) { 316 acceptAll( listInit->get_designators(), *this ); 317 acceptAll( listInit->get_initializers(), *this ); 318 } 319 320 void Visitor::visit(Subrange *subrange) {} 321 322 void Visitor::visit(Constant *constant) {} 29 void Visitor::visit( ObjectDecl *objectDecl ) { 30 maybeAccept( objectDecl->get_type(), *this ); 31 maybeAccept( objectDecl->get_init(), *this ); 32 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 33 } 34 35 void Visitor::visit( FunctionDecl *functionDecl ) { 36 maybeAccept( functionDecl->get_functionType(), *this ); 37 acceptAll( functionDecl->get_oldDecls(), *this ); 38 maybeAccept( functionDecl->get_statements(), *this ); 39 } 40 41 void Visitor::visit( AggregateDecl *aggregateDecl ) { 42 acceptAll( aggregateDecl->get_parameters(), *this ); 43 acceptAll( aggregateDecl->get_members(), *this ); 44 } 45 46 void Visitor::visit( StructDecl *aggregateDecl ) { 47 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 48 } 49 50 void Visitor::visit( UnionDecl *aggregateDecl ) { 51 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 52 } 53 54 void Visitor::visit( EnumDecl *aggregateDecl ) { 55 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 56 } 57 58 void Visitor::visit( ContextDecl *aggregateDecl ) { 59 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 60 } 61 62 void Visitor::visit( NamedTypeDecl *typeDecl ) { 63 acceptAll( typeDecl->get_parameters(), *this ); 64 acceptAll( typeDecl->get_assertions(), *this ); 65 maybeAccept( typeDecl->get_base(), *this ); 66 } 67 68 void Visitor::visit( TypeDecl *typeDecl ) { 69 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 70 } 71 72 void Visitor::visit( TypedefDecl *typeDecl ) { 73 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 74 } 75 76 void Visitor::visit( CompoundStmt *compoundStmt ) { 77 acceptAll( compoundStmt->get_kids(), *this ); 78 } 79 80 void Visitor::visit( ExprStmt *exprStmt ) { 81 maybeAccept( exprStmt->get_expr(), *this ); 82 } 83 84 void Visitor::visit( IfStmt *ifStmt ) { 85 maybeAccept( ifStmt->get_condition(), *this ); 86 maybeAccept( ifStmt->get_thenPart(), *this ); 87 maybeAccept( ifStmt->get_elsePart(), *this ); 88 } 89 90 void Visitor::visit( WhileStmt *whileStmt ) { 91 maybeAccept( whileStmt->get_condition(), *this ); 92 maybeAccept( whileStmt->get_body(), *this ); 93 } 94 95 void Visitor::visit( ForStmt *forStmt ) { 96 // ForStmt still needs to be fixed 97 maybeAccept( forStmt->get_initialization(), *this ); 98 maybeAccept( forStmt->get_condition(), *this ); 99 maybeAccept( forStmt->get_increment(), *this ); 100 maybeAccept( forStmt->get_body(), *this ); 101 } 102 103 void Visitor::visit( SwitchStmt *switchStmt ) { 104 maybeAccept( switchStmt->get_condition(), *this ); 105 acceptAll( switchStmt->get_branches(), *this ); 106 } 107 108 void Visitor::visit( ChooseStmt *switchStmt ) { 109 maybeAccept( switchStmt->get_condition(), *this ); 110 acceptAll( switchStmt->get_branches(), *this ); 111 } 112 113 void Visitor::visit( FallthruStmt *fallthruStmt ){} 114 115 void Visitor::visit( CaseStmt *caseStmt ) { 116 maybeAccept( caseStmt->get_condition(), *this ); 117 acceptAll( caseStmt->get_statements(), *this ); 118 } 119 120 void Visitor::visit( BranchStmt *branchStmt ) { 121 } 122 123 void Visitor::visit( ReturnStmt *returnStmt ) { 124 maybeAccept( returnStmt->get_expr(), *this ); 125 } 126 127 void Visitor::visit( TryStmt *tryStmt ) { 128 maybeAccept( tryStmt->get_block(), *this ); 129 acceptAll( tryStmt->get_catchers(), *this ); 130 } 131 132 void Visitor::visit( CatchStmt *catchStmt ) { 133 maybeAccept( catchStmt->get_decl(), *this ); 134 maybeAccept( catchStmt->get_body(), *this ); 135 } 136 137 void Visitor::visit( FinallyStmt *finalStmt ) { 138 maybeAccept( finalStmt->get_block(), *this ); 139 } 140 141 void Visitor::visit( NullStmt *nullStmt ) { 142 } 143 144 void Visitor::visit( DeclStmt *declStmt ) { 145 maybeAccept( declStmt->get_decl(), *this ); 146 } 147 148 void Visitor::visit( ApplicationExpr *applicationExpr ) { 149 acceptAll( applicationExpr->get_results(), *this ); 150 maybeAccept( applicationExpr->get_function(), *this ); 151 acceptAll( applicationExpr->get_args(), *this ); 152 } 153 154 void Visitor::visit( UntypedExpr *untypedExpr ) { 155 acceptAll( untypedExpr->get_results(), *this ); 156 acceptAll( untypedExpr->get_args(), *this ); 157 } 158 159 void Visitor::visit( NameExpr *nameExpr ) { 160 acceptAll( nameExpr->get_results(), *this ); 161 } 162 163 void Visitor::visit( AddressExpr *addressExpr ) { 164 acceptAll( addressExpr->get_results(), *this ); 165 maybeAccept( addressExpr->get_arg(), *this ); 166 } 167 168 void Visitor::visit( LabelAddressExpr *labAddressExpr ) { 169 acceptAll( labAddressExpr->get_results(), *this ); 170 maybeAccept( labAddressExpr->get_arg(), *this ); 171 } 172 173 void Visitor::visit( CastExpr *castExpr ) { 174 acceptAll( castExpr->get_results(), *this ); 175 maybeAccept( castExpr->get_arg(), *this ); 176 } 177 178 void Visitor::visit( UntypedMemberExpr *memberExpr ) { 179 acceptAll( memberExpr->get_results(), *this ); 180 maybeAccept( memberExpr->get_aggregate(), *this ); 181 } 182 183 void Visitor::visit( MemberExpr *memberExpr ) { 184 acceptAll( memberExpr->get_results(), *this ); 185 maybeAccept( memberExpr->get_aggregate(), *this ); 186 } 187 188 void Visitor::visit( VariableExpr *variableExpr ) { 189 acceptAll( variableExpr->get_results(), *this ); 190 } 191 192 void Visitor::visit( ConstantExpr *constantExpr ) { 193 acceptAll( constantExpr->get_results(), *this ); 194 maybeAccept( constantExpr->get_constant(), *this ); 195 } 196 197 void Visitor::visit( SizeofExpr *sizeofExpr ) { 198 acceptAll( sizeofExpr->get_results(), *this ); 199 if ( sizeofExpr->get_isType() ) { 200 maybeAccept( sizeofExpr->get_type(), *this ); 201 } else { 202 maybeAccept( sizeofExpr->get_expr(), *this ); 203 } 204 } 205 206 void Visitor::visit( AttrExpr *attrExpr ) { 207 acceptAll( attrExpr->get_results(), *this ); 208 if ( attrExpr->get_isType() ) { 209 maybeAccept( attrExpr->get_type(), *this ); 210 } else { 211 maybeAccept( attrExpr->get_expr(), *this ); 212 } 213 } 214 215 void Visitor::visit( LogicalExpr *logicalExpr ) { 216 acceptAll( logicalExpr->get_results(), *this ); 217 maybeAccept( logicalExpr->get_arg1(), *this ); 218 maybeAccept( logicalExpr->get_arg2(), *this ); 219 } 220 221 void Visitor::visit( ConditionalExpr *conditionalExpr ) { 222 acceptAll( conditionalExpr->get_results(), *this ); 223 maybeAccept( conditionalExpr->get_arg1(), *this ); 224 maybeAccept( conditionalExpr->get_arg2(), *this ); 225 maybeAccept( conditionalExpr->get_arg3(), *this ); 226 } 227 228 void Visitor::visit( CommaExpr *commaExpr ) { 229 acceptAll( commaExpr->get_results(), *this ); 230 maybeAccept( commaExpr->get_arg1(), *this ); 231 maybeAccept( commaExpr->get_arg2(), *this ); 232 } 233 234 void Visitor::visit( TupleExpr *tupleExpr ) { 235 acceptAll( tupleExpr->get_results(), *this ); 236 acceptAll( tupleExpr->get_exprs(), *this ); 237 } 238 239 void Visitor::visit( SolvedTupleExpr *tupleExpr ) { 240 acceptAll( tupleExpr->get_results(), *this ); 241 acceptAll( tupleExpr->get_exprs(), *this ); 242 } 243 244 void Visitor::visit( TypeExpr *typeExpr ) { 245 acceptAll( typeExpr->get_results(), *this ); 246 maybeAccept( typeExpr->get_type(), *this ); 247 } 248 249 void Visitor::visit( UntypedValofExpr *valofExpr ) { 250 acceptAll( valofExpr->get_results(), *this ); 251 maybeAccept( valofExpr->get_body(), *this ); 252 } 253 254 void Visitor::visit( VoidType *voidType ) { 255 acceptAll( voidType->get_forall(), *this ); 256 } 257 258 void Visitor::visit( BasicType *basicType ) { 259 acceptAll( basicType->get_forall(), *this ); 260 } 261 262 void Visitor::visit( PointerType *pointerType ) { 263 acceptAll( pointerType->get_forall(), *this ); 264 maybeAccept( pointerType->get_base(), *this ); 265 } 266 267 void Visitor::visit( ArrayType *arrayType ) { 268 acceptAll( arrayType->get_forall(), *this ); 269 maybeAccept( arrayType->get_dimension(), *this ); 270 maybeAccept( arrayType->get_base(), *this ); 271 } 272 273 void Visitor::visit( FunctionType *functionType ) { 274 acceptAll( functionType->get_forall(), *this ); 275 acceptAll( functionType->get_returnVals(), *this ); 276 acceptAll( functionType->get_parameters(), *this ); 277 } 278 279 void Visitor::visit( ReferenceToType *aggregateUseType ) { 280 acceptAll( aggregateUseType->get_forall(), *this ); 281 acceptAll( aggregateUseType->get_parameters(), *this ); 282 } 283 284 void Visitor::visit( StructInstType *aggregateUseType ) { 285 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 286 } 287 288 void Visitor::visit( UnionInstType *aggregateUseType ) { 289 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 290 } 291 292 void Visitor::visit( EnumInstType *aggregateUseType ) { 293 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 294 } 295 296 void Visitor::visit( ContextInstType *aggregateUseType ) { 297 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 298 acceptAll( aggregateUseType->get_members(), *this ); 299 } 300 301 void Visitor::visit( TypeInstType *aggregateUseType ) { 302 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 303 } 304 305 void Visitor::visit( TupleType *tupleType ) { 306 acceptAll( tupleType->get_forall(), *this ); 307 acceptAll( tupleType->get_types(), *this ); 308 } 309 310 void Visitor::visit( TypeofType *typeofType ) { 311 assert( typeofType->get_expr() ); 312 typeofType->get_expr()->accept( *this ); 313 } 314 315 void Visitor::visit( AttrType *attrType ) { 316 if ( attrType->get_isType() ) { 317 assert( attrType->get_type() ); 318 attrType->get_type()->accept( *this ); 319 } else { 320 assert( attrType->get_expr() ); 321 attrType->get_expr()->accept( *this ); 322 } // if 323 } 324 325 void Visitor::visit( SingleInit *singleInit ) { 326 singleInit->get_value()->accept( *this ); 327 } 328 329 void Visitor::visit( ListInit *listInit ) { 330 acceptAll( listInit->get_designators(), *this ); 331 acceptAll( listInit->get_initializers(), *this ); 332 } 333 334 void Visitor::visit( Subrange *subrange ) {} 335 336 void Visitor::visit( Constant *constant ) {} 337 // Local Variables: // 338 // tab-width: 4 // 339 // mode: c++ // 340 // compile-command: "make install" // 341 // End: // -
translator/SynTree/Visitor.h
ra32b204 r0dd3a2f 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 // Visitor.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:15:55 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef VISITOR_H 2 17 #define VISITOR_H … … 6 21 #include "CompilerError.h" 7 22 8 9 23 class Visitor { 10 24 protected: 11 Visitor();12 virtual ~Visitor();25 Visitor(); 26 virtual ~Visitor(); 13 27 public: 14 virtual void visit( ObjectDecl *objectDecl );15 virtual void visit( FunctionDecl *functionDecl );16 virtual void visit( StructDecl *aggregateDecl );17 virtual void visit( UnionDecl *aggregateDecl );18 virtual void visit( EnumDecl *aggregateDecl );19 virtual void visit( ContextDecl *aggregateDecl );20 virtual void visit( TypeDecl *typeDecl );21 virtual void visit( TypedefDecl *typeDecl );28 virtual void visit( ObjectDecl *objectDecl ); 29 virtual void visit( FunctionDecl *functionDecl ); 30 virtual void visit( StructDecl *aggregateDecl ); 31 virtual void visit( UnionDecl *aggregateDecl ); 32 virtual void visit( EnumDecl *aggregateDecl ); 33 virtual void visit( ContextDecl *aggregateDecl ); 34 virtual void visit( TypeDecl *typeDecl ); 35 virtual void visit( TypedefDecl *typeDecl ); 22 36 23 virtual void visit( CompoundStmt *compoundStmt );24 virtual void visit( ExprStmt *exprStmt );25 virtual void visit( IfStmt *ifStmt );26 virtual void visit( WhileStmt *whileStmt );27 virtual void visit( ForStmt *forStmt );28 virtual void visit( SwitchStmt *switchStmt );29 virtual void visit( ChooseStmt *switchStmt );30 virtual void visit( FallthruStmt *switchStmt );31 virtual void visit( CaseStmt *caseStmt );32 virtual void visit( BranchStmt *branchStmt );33 virtual void visit( ReturnStmt *returnStmt );34 virtual void visit( TryStmt *tryStmt );35 virtual void visit( CatchStmt *catchStmt );36 virtual void visit( FinallyStmt *finallyStmt );37 virtual void visit( NullStmt *nullStmt );38 virtual void visit( DeclStmt *declStmt );37 virtual void visit( CompoundStmt *compoundStmt ); 38 virtual void visit( ExprStmt *exprStmt ); 39 virtual void visit( IfStmt *ifStmt ); 40 virtual void visit( WhileStmt *whileStmt ); 41 virtual void visit( ForStmt *forStmt ); 42 virtual void visit( SwitchStmt *switchStmt ); 43 virtual void visit( ChooseStmt *switchStmt ); 44 virtual void visit( FallthruStmt *switchStmt ); 45 virtual void visit( CaseStmt *caseStmt ); 46 virtual void visit( BranchStmt *branchStmt ); 47 virtual void visit( ReturnStmt *returnStmt ); 48 virtual void visit( TryStmt *tryStmt ); 49 virtual void visit( CatchStmt *catchStmt ); 50 virtual void visit( FinallyStmt *finallyStmt ); 51 virtual void visit( NullStmt *nullStmt ); 52 virtual void visit( DeclStmt *declStmt ); 39 53 40 virtual void visit( ApplicationExpr *applicationExpr );41 virtual void visit( UntypedExpr *untypedExpr );42 virtual void visit( NameExpr *nameExpr );43 virtual void visit( CastExpr *castExpr );44 virtual void visit( AddressExpr *addressExpr );45 virtual void visit( LabelAddressExpr *labAddressExpr );46 virtual void visit( UntypedMemberExpr *memberExpr );47 virtual void visit( MemberExpr *memberExpr );48 virtual void visit( VariableExpr *variableExpr );49 virtual void visit( ConstantExpr *constantExpr );50 virtual void visit( SizeofExpr *sizeofExpr );51 virtual void visit( AttrExpr *attrExpr );52 virtual void visit( LogicalExpr *logicalExpr );53 virtual void visit( ConditionalExpr *conditionalExpr );54 virtual void visit( CommaExpr *commaExpr );55 virtual void visit( TupleExpr *tupleExpr );56 virtual void visit( SolvedTupleExpr *tupleExpr );57 virtual void visit( TypeExpr *typeExpr );58 virtual void visit( UntypedValofExpr *valofExpr );54 virtual void visit( ApplicationExpr *applicationExpr ); 55 virtual void visit( UntypedExpr *untypedExpr ); 56 virtual void visit( NameExpr *nameExpr ); 57 virtual void visit( CastExpr *castExpr ); 58 virtual void visit( AddressExpr *addressExpr ); 59 virtual void visit( LabelAddressExpr *labAddressExpr ); 60 virtual void visit( UntypedMemberExpr *memberExpr ); 61 virtual void visit( MemberExpr *memberExpr ); 62 virtual void visit( VariableExpr *variableExpr ); 63 virtual void visit( ConstantExpr *constantExpr ); 64 virtual void visit( SizeofExpr *sizeofExpr ); 65 virtual void visit( AttrExpr *attrExpr ); 66 virtual void visit( LogicalExpr *logicalExpr ); 67 virtual void visit( ConditionalExpr *conditionalExpr ); 68 virtual void visit( CommaExpr *commaExpr ); 69 virtual void visit( TupleExpr *tupleExpr ); 70 virtual void visit( SolvedTupleExpr *tupleExpr ); 71 virtual void visit( TypeExpr *typeExpr ); 72 virtual void visit( UntypedValofExpr *valofExpr ); 59 73 60 virtual void visit( VoidType *basicType );61 virtual void visit( BasicType *basicType );62 virtual void visit( PointerType *pointerType );63 virtual void visit( ArrayType *arrayType );64 virtual void visit( FunctionType *functionType );65 virtual void visit( StructInstType *aggregateUseType );66 virtual void visit( UnionInstType *aggregateUseType );67 virtual void visit( EnumInstType *aggregateUseType );68 virtual void visit( ContextInstType *aggregateUseType );69 virtual void visit( TypeInstType *aggregateUseType );70 virtual void visit( TupleType *tupleType );71 virtual void visit( TypeofType *typeofType );72 virtual void visit( AttrType *attrType );74 virtual void visit( VoidType *basicType ); 75 virtual void visit( BasicType *basicType ); 76 virtual void visit( PointerType *pointerType ); 77 virtual void visit( ArrayType *arrayType ); 78 virtual void visit( FunctionType *functionType ); 79 virtual void visit( StructInstType *aggregateUseType ); 80 virtual void visit( UnionInstType *aggregateUseType ); 81 virtual void visit( EnumInstType *aggregateUseType ); 82 virtual void visit( ContextInstType *aggregateUseType ); 83 virtual void visit( TypeInstType *aggregateUseType ); 84 virtual void visit( TupleType *tupleType ); 85 virtual void visit( TypeofType *typeofType ); 86 virtual void visit( AttrType *attrType ); 73 87 74 virtual void visit( SingleInit *singleInit );75 virtual void visit( ListInit *listInit );88 virtual void visit( SingleInit *singleInit ); 89 virtual void visit( ListInit *listInit ); 76 90 77 virtual void visit( Subrange *subrange );91 virtual void visit( Subrange *subrange ); 78 92 79 virtual void visit( Constant *constant );93 virtual void visit( Constant *constant ); 80 94 private: 81 virtual void visit( AggregateDecl *aggregateDecl );82 virtual void visit( NamedTypeDecl *typeDecl );83 virtual void visit( ReferenceToType *aggregateUseType );95 virtual void visit( AggregateDecl *aggregateDecl ); 96 virtual void visit( NamedTypeDecl *typeDecl ); 97 virtual void visit( ReferenceToType *aggregateUseType ); 84 98 }; 85 99 86 100 template< typename TreeType, typename VisitorType > 87 101 inline void maybeAccept( TreeType *tree, VisitorType &visitor ) { 88 if ( tree ) {89 tree->accept( visitor );90 }102 if ( tree ) { 103 tree->accept( visitor ); 104 } 91 105 } 92 106 93 107 template< typename Container, typename VisitorType > 94 108 inline void acceptAll( Container &container, VisitorType &visitor ) { 95 SemanticError errors; 96 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 97 try { 98 if ( *i ) { 99 (*i)->accept( visitor ); 100 } 101 } catch( SemanticError &e ) { 102 errors.append( e ); 109 SemanticError errors; 110 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 111 try { 112 if ( *i ) { 113 (*i)->accept( visitor ); 114 } 115 } catch( SemanticError &e ) { 116 errors.append( e ); 117 } 103 118 } 104 } 105 if ( ! errors.isEmpty() ) { 106 throw errors; 107 } 119 if ( ! errors.isEmpty() ) { 120 throw errors; 121 } 108 122 } 109 123 110 124 template< typename Container, typename VisitorType > 111 125 void acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around ) { 112 SemanticError errors;113 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {114 try {115 if ( *i ) {116 VisitorType *v = new VisitorType;117 (*i)->accept( *v );126 SemanticError errors; 127 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 128 try { 129 if ( *i ) { 130 VisitorType *v = new VisitorType; 131 (*i)->accept( *v ); 118 132 119 typename Container::iterator nxt = i; nxt++; // forward_iterator120 if ( nxt == container.end() )121 visitor += *v;122 else123 visitor += *v + around;133 typename Container::iterator nxt = i; nxt++; // forward_iterator 134 if ( nxt == container.end() ) 135 visitor += *v; 136 else 137 visitor += *v + around; 124 138 125 delete v;126 }127 } catch( SemanticError &e ) {128 errors.append( e );129 }130 } 131 if ( ! errors.isEmpty() ) {132 throw errors;133 } 139 delete v; 140 } // if 141 } catch( SemanticError &e ) { 142 errors.append( e ); 143 } // try 144 } // for 145 if ( ! errors.isEmpty() ) { 146 throw errors; 147 } // if 134 148 } 135 149 136 150 #endif // VISITOR_H 151 152 // Local Variables: // 153 // tab-width: 4 // 154 // mode: c++ // 155 // compile-command: "make install" // 156 // End: // -
translator/SynTree/VoidType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: VoidType.cc,v 1.3 2005/08/29 20:59:27 rcbilson Exp $ 5 * 6 */ 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 // VoidType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:16:42 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Type.h" 9 17 10 11 VoidType::VoidType( const Type::Qualifiers &tq ) 12 : Type( tq ) 13 { 18 VoidType::VoidType( const Type::Qualifiers &tq ) : Type( tq ) { 14 19 } 15 20 16 void 17 VoidType::print( std::ostream &os, int indent ) const 18 { 19 Type::print( os, indent ); 20 os << "void "; 21 void VoidType::print( std::ostream &os, int indent ) const { 22 Type::print( os, indent ); 23 os << "void "; 21 24 } 22 25 26 // Local Variables: // 27 // tab-width: 4 // 28 // mode: c++ // 29 // compile-command: "make install" // 30 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.