Changeset b067d9b for src/SynTree
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/SynTree
- Files:
-
- 35 edited
-
AddressExpr.cc (modified) (2 diffs)
-
AggregateDecl.cc (modified) (2 diffs)
-
ApplicationExpr.cc (modified) (4 diffs)
-
ArrayType.cc (modified) (1 diff)
-
Attribute.cc (modified) (1 diff)
-
Attribute.h (modified) (1 diff)
-
BaseSyntaxNode.h (modified) (4 diffs)
-
BasicType.cc (modified) (2 diffs)
-
CommaExpr.cc (modified) (3 diffs)
-
Constant.cc (modified) (5 diffs)
-
Constant.h (modified) (4 diffs)
-
DeclReplacer.cc (modified) (5 diffs)
-
DeclReplacer.h (modified) (1 diff)
-
Declaration.cc (modified) (2 diffs)
-
Declaration.h (modified) (17 diffs)
-
Expression.cc (modified) (52 diffs)
-
Expression.h (modified) (53 diffs)
-
FunctionDecl.cc (modified) (1 diff)
-
FunctionType.cc (modified) (1 diff)
-
Initializer.h (modified) (5 diffs)
-
Label.h (modified) (1 diff)
-
Mutator.h (modified) (7 diffs)
-
ObjectDecl.cc (modified) (1 diff)
-
ReferenceToType.cc (modified) (7 diffs)
-
Statement.cc (modified) (1 diff)
-
Statement.h (modified) (23 diffs)
-
SynTree.h (modified) (8 diffs)
-
TupleExpr.cc (modified) (5 diffs)
-
Type.cc (modified) (6 diffs)
-
Type.h (modified) (30 diffs)
-
TypeSubstitution.cc (modified) (3 diffs)
-
TypeSubstitution.h (modified) (11 diffs)
-
TypeofType.cc (modified) (2 diffs)
-
Visitor.h (modified) (3 diffs)
-
module.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AddressExpr.cc
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 23:54:44 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T ue Apr 26 12:35:13 201613 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 28 13:13:38 2019 13 // Update Count : 10 14 14 // 15 15 … … 42 42 AddressExpr::AddressExpr( Expression *arg ) : Expression(), arg( arg ) { 43 43 if ( arg->result ) { 44 if ( arg-> result->get_lvalue() ) {44 if ( arg->get_lvalue() ) { 45 45 // lvalue, retains all layers of reference and gains a pointer inside the references 46 46 set_result( addrType( arg->result ) ); 47 47 } else { 48 48 // taking address of non-lvalue -- must be a reference, loses one layer of reference 49 ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( arg->result ); 50 set_result( addrType( refType->base ) ); 49 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( arg->result ) ) { 50 set_result( addrType( refType->base ) ); 51 } else { 52 SemanticError( arg->result, "Attempt to take address of non-lvalue expression: " ); 53 } // if 51 54 } 52 // result of & is never an lvalue53 get_result()->set_lvalue( false );54 55 } 55 56 } -
src/SynTree/AggregateDecl.cc
r7951100 rb067d9b 86 86 std::string TraitDecl::typeString() const { return "trait"; } 87 87 88 namespace {89 long long int getConstValue( Expression * expr ) {90 if ( CastExpr * castExpr = dynamic_cast< CastExpr * > ( expr ) ) {91 return getConstValue( castExpr->arg );92 } else if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) {93 return constExpr->intValue();94 // can be -1, +1, etc.95 // } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) {96 // if ( untypedExpr-> )97 } else {98 assertf( false, "Unhandled expression type in getConstValue for enumerators: %s", toString( expr ).c_str() );99 }100 }101 }102 103 88 bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) { 104 89 if ( enumValues.empty() ) { … … 108 93 if ( field->init ) { 109 94 SingleInit * init = strict_dynamic_cast< SingleInit * >( field->init ); 110 currentValue = getConstValue( init->value ); 95 auto result = eval( init->value ); 96 if ( ! result.second ) SemanticError( init->location, toString( "Non-constexpr in initialization of enumerator: ", field ) ); 97 currentValue = result.first; 111 98 } 112 99 assertf( enumValues.count( field->name ) == 0, "Enum %s has multiple members with the name %s", name.c_str(), field->name.c_str() ); -
src/SynTree/ApplicationExpr.cc
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Apr 26 12:41:06 201613 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Aug 12 14:28:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 25 25 #include "Declaration.h" // for Declaration 26 26 #include "Expression.h" // for ParamEntry, ApplicationExpr, Expression 27 #include "InitTweak/InitTweak.h" // for getFunction 27 28 #include "ResolvExpr/typeops.h" // for extractResultType 28 29 #include "Type.h" // for Type, PointerType, FunctionType 29 30 31 ParamEntry::ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr ) 32 : decl( decl ), declptr( declptr ), actualType( actualType ), formalType( formalType ), expr( expr ) { 33 } 34 30 35 ParamEntry::ParamEntry( const ParamEntry &other ) : 31 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) { 32 } 33 34 ParamEntry &ParamEntry::operator=( const ParamEntry &other ) { 35 if ( &other == this ) return *this; 36 decl = other.decl; 37 // xxx - this looks like a memory leak 38 actualType = maybeClone( other.actualType ); 39 formalType = maybeClone( other.formalType ); 40 expr = maybeClone( other.expr ); 41 *inferParams = *other.inferParams; 42 return *this; 36 decl( other.decl ), declptr( maybeClone( other.declptr ) ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) { 43 37 } 44 38 45 39 ParamEntry::~ParamEntry() { 40 delete declptr; 46 41 delete actualType; 47 42 delete formalType; … … 50 45 51 46 ParamEntry::ParamEntry( ParamEntry && other ) : 52 decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ), inferParams( std::move( other.inferParams ) ) { 53 other.actualType = nullptr; 54 other.formalType = nullptr; 55 other.expr = nullptr; 47 decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ) { 48 new (&other) ParamEntry(); 56 49 } 57 50 58 51 ParamEntry & ParamEntry::operator=( ParamEntry && other ) { 59 52 if ( &other == this ) return *this; 60 delete actualType; 61 delete formalType; 62 delete expr; 63 decl = other.decl; 64 actualType = other.actualType; 65 formalType = other.formalType; 66 expr = other.expr; 67 other.actualType = nullptr; 68 other.formalType = nullptr; 69 other.expr = nullptr; 70 inferParams = std::move( other.inferParams ); 53 this->~ParamEntry(); 54 new (this) ParamEntry(other.decl, other.declptr, other.actualType, other.formalType, other.expr); 55 new (&other) ParamEntry(); 56 71 57 return *this; 72 58 } … … 91 77 } 92 78 79 bool ApplicationExpr::get_lvalue() const { 80 // from src/GenPoly/Lvalue.cc: isIntrinsicReference 81 static std::set<std::string> lvalueFunctions = { "*?", "?[?]" }; 82 if ( const DeclarationWithType * func = InitTweak::getFunction( this ) ) { 83 return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name); 84 } 85 return false; 86 } 87 93 88 void ApplicationExpr::print( std::ostream &os, Indenter indent ) const { 94 89 os << "Application of" << std::endl << indent+1; -
src/SynTree/ArrayType.cc
r7951100 rb067d9b 26 26 ArrayType::ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes ) 27 27 : Type( tq, attributes ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) { 28 base->set_lvalue( false );29 28 } 30 29 -
src/SynTree/Attribute.cc
r7951100 rb067d9b 21 21 #include "Expression.h" // for Expression 22 22 23 Attribute::Attribute( const Attribute &other ) : name( other.name ) {23 Attribute::Attribute( const Attribute &other ) : BaseSyntaxNode( other ), name( other.name ) { 24 24 cloneAll( other.parameters, parameters ); 25 25 } -
src/SynTree/Attribute.h
r7951100 rb067d9b 50 50 Attribute * clone() const override { return new Attribute( *this ); } 51 51 virtual void accept( Visitor & v ) override { v.visit( this ); } 52 virtual void accept( Visitor & v ) const override { v.visit( this ); } 52 53 virtual Attribute * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 53 54 virtual void print( std::ostream & os, Indenter indent = {} ) const override; -
src/SynTree/BaseSyntaxNode.h
r7951100 rb067d9b 9 9 // Author : Thierry Delisle 10 10 // Created On : Tue Feb 14 07:44:20 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 17 13:44:0013 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 10 16:13:49 2019 13 // Update Count : 4 14 14 // 15 15 … … 18 18 #include "Common/CodeLocation.h" 19 19 #include "Common/Indenter.h" 20 #include "Common/Stats.h" 21 20 22 class Visitor; 21 23 class Mutator; … … 23 25 class BaseSyntaxNode { 24 26 public: 27 static Stats::Counters::SimpleCounter* new_nodes; 28 25 29 CodeLocation location; 30 31 BaseSyntaxNode() { ++*new_nodes; } 32 BaseSyntaxNode( const BaseSyntaxNode & o ) : location(o.location) { ++*new_nodes; } 33 BaseSyntaxNode & operator=( const BaseSyntaxNode & ) = default; 26 34 27 35 virtual ~BaseSyntaxNode() {} … … 29 37 virtual BaseSyntaxNode * clone() const = 0; 30 38 virtual void accept( Visitor & v ) = 0; 39 virtual void accept( Visitor & v ) const = 0; 31 40 virtual BaseSyntaxNode * acceptMutator( Mutator & m ) = 0; 32 /// Notes:33 /// * each node is responsible for indenting its children.34 /// * Expressions should not finish with a newline, since the expression's parent has better information.41 /// Notes: 42 /// * each node is responsible for indenting its children. 43 /// * Expressions should not finish with a newline, since the expression's parent has better information. 35 44 virtual void print( std::ostream & os, Indenter indent = {} ) const = 0; 36 void print( std::ostream & os, unsigned int indent ) {37 print( os, Indenter{ Indenter::tabsize, indent });38 }39 45 }; 40 46 -
src/SynTree/BasicType.cc
r7951100 rb067d9b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 25 14:14:03 201713 // Update Count : 1 112 // Last Modified On : Sun Aug 4 21:07:44 2019 13 // Update Count : 13 14 14 // 15 15 … … 30 30 31 31 bool BasicType::isInteger() const { 32 switch ( kind ) { 33 case Bool: 34 case Char: 35 case SignedChar: 36 case UnsignedChar: 37 case ShortSignedInt: 38 case ShortUnsignedInt: 39 case SignedInt: 40 case UnsignedInt: 41 case LongSignedInt: 42 case LongUnsignedInt: 43 case LongLongSignedInt: 44 case LongLongUnsignedInt: 45 case SignedInt128: 46 case UnsignedInt128: 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 case Float80: 58 case Float128: 59 return false; 60 case NUMBER_OF_BASIC_TYPES: 61 assert( false ); 62 } // switch 63 assert( false ); 64 return false; 32 return kind <= UnsignedInt128; 65 33 } 66 34 -
src/SynTree/CommaExpr.cc
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon May 02 15:19:44201613 // Update Count : 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Arg 12 16:11:00 2016 13 // Update Count : 2 14 14 // 15 15 … … 23 23 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2 ) 24 24 : Expression(), arg1( arg1 ), arg2( arg2 ) { 25 // xxx - result of a comma expression is never an lvalue, so should set lvalue26 // to false on all result types. Actually doing this causes some strange things27 // to happen in later passes (particularly, Specialize, Lvalue, and Box). This needs to be looked into.28 25 set_result( maybeClone( arg2->get_result() ) ); 29 // get_type->set_isLvalue( false );30 26 } 31 27 … … 37 33 delete arg1; 38 34 delete arg2; 35 } 36 37 bool CommaExpr::get_lvalue() const { 38 // This is wrong by C, but the current implementation uses it. 39 // (ex: Specialize, Lvalue and Box) 40 return arg2->get_lvalue(); 39 41 } 40 42 -
src/SynTree/Constant.cc
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Jul 14 14:50:00 201713 // Update Count : 2911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:11:22 2019 13 // Update Count : 32 14 14 // 15 15 … … 19 19 20 20 #include "Constant.h" 21 #include "Expression.h" // for ConstantExpr 21 22 #include "Type.h" // for BasicType, Type, Type::Qualifiers, PointerType 22 23 23 Constant::Constant( Type * type, std::string rep, unsigned long long val ) : type( type ), rep( rep ), val( val ) {} 24 Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {} 24 Constant::Constant( Type * type, std::string rep, std::optional<unsigned long long> ival ) : type( type ), rep( rep ), ival( ival ) {} 25 25 26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) {26 Constant::Constant( const Constant &other ) : BaseSyntaxNode( other ), rep( other.rep ), ival( other.ival ) { 27 27 type = other.type->clone(); 28 28 } … … 34 34 } 35 35 36 Constant Constant::from_char( char c ) {37 return Constant( new BasicType( Type::Qualifiers(), BasicType::Char ), std::to_string( c ), (unsigned long long int)c );38 }39 40 36 Constant Constant::from_int( int i ) { 41 37 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i ); … … 44 40 Constant Constant::from_ulong( unsigned long i ) { 45 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i ); 46 }47 48 Constant Constant::from_double( double d ) {49 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d );50 42 } 51 43 … … 63 55 unsigned long long Constant::get_ival() const { 64 56 assertf( strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve ival from non-integer constant." ); 65 return val.ival; 66 } 67 68 double Constant::get_dval() const { 69 assertf( ! strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve dval from integer constant." ); 70 return val.dval; 57 return ival.value(); 71 58 } 72 59 73 60 void Constant::print( std::ostream &os, Indenter ) const { 74 os << "(" << rep << " " << val.ival;61 os << "(" << rep << " " << (ival ? toString(ival.value()) : "") ; 75 62 if ( type ) { 76 63 os << ": "; -
src/SynTree/Constant.h
r7951100 rb067d9b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:54:46 201713 // Update Count : 1 712 // Last Modified On : Wed Jul 10 15:57:38 2019 13 // Update Count : 19 14 14 // 15 15 … … 18 18 #include <iosfwd> // for ostream 19 19 #include <string> // for string 20 #include <optional> // for optional 20 21 21 22 #include "BaseSyntaxNode.h" … … 27 28 class Constant : public BaseSyntaxNode { 28 29 public: 29 Constant( Type * type, std::string rep, unsigned long long val ); 30 Constant( Type * type, std::string rep, double val ); 30 Constant( Type * type, std::string rep, std::optional<unsigned long long> i ); 31 31 Constant( const Constant & other ); 32 Constant & operator=( const Constant & ) = default; 32 33 virtual ~Constant(); 33 34 34 virtual Constant * clone() const { return new Constant( *this ); }35 virtual Constant * clone() const override { return new Constant( *this ); } 35 36 36 37 Type * get_type() { return type; } … … 39 40 void set_value( std::string newValue ) { rep = newValue; } 40 41 unsigned long long get_ival() const; 41 double get_dval() const;42 42 43 43 /// generates a boolean constant of the given bool 44 44 static Constant from_bool( bool b ); 45 /// generates a char constant of the given char46 static Constant from_char( char c );47 45 /// generates an integer constant of the given int 48 46 static Constant from_int( int i ); 49 47 /// generates an integer constant of the given unsigned long int 50 48 static Constant from_ulong( unsigned long i ); 51 /// generates a floating point constant of the given double52 static Constant from_double( double d );53 49 54 50 /// generates a null pointer value for the given type. void * if omitted. 55 51 static Constant null( Type * ptrtype = nullptr ); 56 52 57 virtual void accept( Visitor & v ) { v.visit( this ); } 58 virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); } 59 virtual void print( std::ostream & os, Indenter indent = 0 ) const; 60 private: 53 virtual void accept( Visitor & v ) override { v.visit( this ); } 54 virtual void accept( Visitor & v ) const override { v.visit( this ); } 55 virtual Constant * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 56 virtual void print( std::ostream & os, Indenter indent = 0 ) const override; 57 61 58 Type * type; 62 59 std::string rep; 63 union Val { 64 unsigned long long ival; 65 double dval; 66 Val( unsigned long long ival ) : ival( ival ) {} 67 Val( double dval ) : dval( dval ) {} 68 } val; 60 std::optional<unsigned long long> ival; 69 61 }; 70 62 -
src/SynTree/DeclReplacer.cc
r7951100 rb067d9b 30 30 bool debug; 31 31 public: 32 size_t replaced; 33 34 public: 32 35 DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 33 36 … … 38 41 void previsit( TypeInstType * inst ); 39 42 }; 43 44 /// Mutator that replaces uses of declarations with arbitrary expressions, according to the supplied mapping 45 struct ExprDeclReplacer { 46 private: 47 const ExprMap & exprMap; 48 bool debug; 49 public: 50 size_t replaced; 51 52 public: 53 ExprDeclReplacer( const ExprMap & exprMap, bool debug = false ); 54 55 // replace variable with new node from expr map 56 Expression * postmutate( VariableExpr * varExpr ); 57 }; 40 58 } 41 59 42 voidreplace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {60 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 43 61 PassVisitor<DeclReplacer> replacer( declMap, typeMap, debug ); 44 62 maybeAccept( node, replacer ); 63 return replacer.pass.replaced; 45 64 } 46 65 47 voidreplace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {66 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) { 48 67 TypeMap typeMap; 49 re place( node, declMap, typeMap, debug );68 return replace( node, declMap, typeMap, debug ); 50 69 } 51 70 52 voidreplace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {71 size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) { 53 72 DeclMap declMap; 54 replace( node, declMap, typeMap, debug ); 73 return replace( node, declMap, typeMap, debug ); 74 } 75 76 size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) { 77 PassVisitor<ExprDeclReplacer> replacer( exprMap, debug ); 78 node = maybeMutate( node, replacer ); 79 return replacer.pass.replaced; 55 80 } 56 81 57 82 namespace { 58 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ) {}83 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ), replaced( 0 ) {} 59 84 60 85 // replace variable with new node from decl map … … 62 87 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 63 88 if ( declMap.count( varExpr->var ) ) { 89 replaced++; 64 90 auto replacement = declMap.at( varExpr->var ); 65 91 if ( debug ) { … … 72 98 void DeclReplacer::previsit( TypeInstType * inst ) { 73 99 if ( typeMap.count( inst->baseType ) ) { 100 replaced++; 74 101 auto replacement = typeMap.at( inst->baseType ); 75 102 if ( debug ) { … … 79 106 } 80 107 } 108 109 ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ), replaced( 0 ) {} 110 111 Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) { 112 if ( exprMap.count( varExpr->var ) ) { 113 replaced++; 114 Expression * replacement = exprMap.at( varExpr->var )->clone(); 115 if ( debug ) { 116 std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)replacement << " " << replacement << std::endl; 117 } 118 std::swap( varExpr->env, replacement->env ); 119 delete varExpr; 120 return replacement; 121 } 122 return varExpr; 123 } 81 124 } 82 125 } // namespace VarExprReplacer -
src/SynTree/DeclReplacer.h
r7951100 rb067d9b 26 26 typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap; 27 27 typedef std::map< TypeDecl *, TypeDecl * > TypeMap; 28 typedef std::map< DeclarationWithType *, Expression * > ExprMap; 28 29 29 void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ); 30 void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false ); 31 void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 30 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false ); 31 size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false ); 32 size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 33 34 size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false); 35 36 template<typename T> 37 size_t replace( T *& node, const ExprMap & exprMap, bool debug = false ) { 38 if ( ! node ) return 0ul; 39 BaseSyntaxNode * arg = node; 40 size_t replaced = replace( arg, exprMap, debug ); 41 node = dynamic_cast<T *>( arg ); 42 assertf( node, "DeclReplacer fundamentally changed the type of its argument." ); 43 return replaced; 44 } 32 45 } 33 46 -
src/SynTree/Declaration.cc
r7951100 rb067d9b 27 27 28 28 static UniqueId lastUniqueId = 0; 29 typedef std::map< UniqueId, Declaration* > IdMapType;30 static IdMapType idMap;31 29 32 30 Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) 33 : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0) {31 : name( name ), linkage( linkage ), uniqueId( 0 ), storageClasses( scs ) { 34 32 } 35 33 36 34 Declaration::Declaration( const Declaration &other ) 37 : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId) {35 : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), uniqueId( other.uniqueId ), storageClasses( other.storageClasses ) { 38 36 } 39 37 … … 45 43 if ( uniqueId ) return; 46 44 uniqueId = ++lastUniqueId; 47 idMap[ uniqueId ] = this;48 45 } 49 50 Declaration *Declaration::declFromId( UniqueId id ) {51 IdMapType::const_iterator i = idMap.find( id );52 return i != idMap.end() ? i->second : 0;53 }54 55 void Declaration::dumpIds( std::ostream &os ) {56 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {57 os << i->first << " -> ";58 i->second->printShort( os );59 os << std::endl;60 } // for61 }62 63 46 64 47 AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) { -
src/SynTree/Declaration.h
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Sep 3 19:24:06 201713 // Update Count : 13 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 2 10:47:00 2019 13 // Update Count : 135 14 14 // 15 15 … … 19 19 #include <iosfwd> // for ostream 20 20 #include <list> // for list 21 #include <unordered_map> // for unordered_map 21 22 #include <string> // for string, operator+, allocator, to_string 22 23 … … 62 63 void fixUniqueId( void ); 63 64 virtual Declaration *clone() const override = 0; 64 virtual void accept( Visitor &v ) override = 0; 65 virtual void accept( Visitor & v ) override = 0; 66 virtual void accept( Visitor & v ) const override = 0; 65 67 virtual Declaration *acceptMutator( Mutator &m ) override = 0; 66 68 virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0; 67 69 virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0; 68 70 69 static void dumpIds( std::ostream &os ); 70 static Declaration *declFromId( UniqueId id ); 71 72 private: 71 UniqueId uniqueId; 73 72 Type::StorageClasses storageClasses; 74 UniqueId uniqueId; 73 private: 75 74 }; 76 75 … … 141 140 142 141 virtual ObjectDecl *clone() const override { return new ObjectDecl( *this ); } 143 virtual void accept( Visitor &v ) override { v.visit( this ); } 142 virtual void accept( Visitor & v ) override { v.visit( this ); } 143 virtual void accept( Visitor & v ) const override { v.visit( this ); } 144 144 virtual DeclarationWithType *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 145 145 virtual void print( std::ostream &os, Indenter indent = {} ) const override; … … 166 166 CompoundStmt *get_statements() const { return statements; } 167 167 void set_statements( CompoundStmt *newValue ) { statements = newValue; } 168 bool has_body() const { return NULL != statements; } 168 169 169 170 static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements ); 170 171 171 172 virtual FunctionDecl *clone() const override { return new FunctionDecl( *this ); } 172 virtual void accept( Visitor &v ) override { v.visit( this ); } 173 virtual void accept( Visitor & v ) override { v.visit( this ); } 174 virtual void accept( Visitor & v ) const override { v.visit( this ); } 173 175 virtual DeclarationWithType *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 174 176 virtual void print( std::ostream &os, Indenter indent = {} ) const override; … … 202 204 typedef NamedTypeDecl Parent; 203 205 public: 204 enum Kind { Dtype, Ftype, Ttype };206 enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS }; 205 207 206 208 Type * init; … … 211 213 TypeDecl::Kind kind; 212 214 bool isComplete; 215 213 216 Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {} 214 217 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {} 215 218 Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {} 219 Data( const Data& d1, const Data& d2 ) 220 : kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {} 221 216 222 bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; } 217 223 bool operator!=(const Data & other) const { return !(*this == other);} … … 235 241 236 242 virtual TypeDecl *clone() const override { return new TypeDecl( *this ); } 237 virtual void accept( Visitor & v ) override { v.visit( this ); }238 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); }239 virtual void print( std::ostream &os, Indenter indent = {} ) const override;240 241 private: 243 virtual void accept( Visitor & v ) override { v.visit( this ); } 244 virtual void accept( Visitor & v ) const override { v.visit( this ); } 245 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 246 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 247 242 248 Kind kind; 243 249 }; … … 254 260 255 261 virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); } 256 virtual void accept( Visitor &v ) override { v.visit( this ); } 262 virtual void accept( Visitor & v ) override { v.visit( this ); } 263 virtual void accept( Visitor & v ) const override { v.visit( this ); } 257 264 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 258 265 private: … … 266 273 bool body; 267 274 std::list< Attribute * > attributes; 275 AggregateDecl * parent = nullptr; 268 276 269 277 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ); … … 280 288 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } 281 289 282 virtual void print( std::ostream &os, Indenter indent = {} ) const override ;290 virtual void print( std::ostream &os, Indenter indent = {} ) const override final; 283 291 virtual void printShort( std::ostream &os, Indenter indent = {} ) const override; 284 292 protected: … … 297 305 298 306 virtual StructDecl *clone() const override { return new StructDecl( *this ); } 299 virtual void accept( Visitor & v ) override { v.visit( this ); }300 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); }301 private: 307 virtual void accept( Visitor & v ) override { v.visit( this ); } 308 virtual void accept( Visitor & v ) const override { v.visit( this ); } 309 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 302 310 DeclarationNode::Aggregate kind; 311 private: 303 312 virtual std::string typeString() const override; 304 313 }; … … 311 320 312 321 virtual UnionDecl *clone() const override { return new UnionDecl( *this ); } 313 virtual void accept( Visitor &v ) override { v.visit( this ); } 322 virtual void accept( Visitor & v ) override { v.visit( this ); } 323 virtual void accept( Visitor & v ) const override { v.visit( this ); } 314 324 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 315 325 private: … … 326 336 327 337 virtual EnumDecl *clone() const override { return new EnumDecl( *this ); } 328 virtual void accept( Visitor &v ) override { v.visit( this ); } 329 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 330 private: 331 std::map< std::string, long long int > enumValues; 338 virtual void accept( Visitor & v ) override { v.visit( this ); } 339 virtual void accept( Visitor & v ) const override { v.visit( this ); } 340 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 341 private: 342 std::unordered_map< std::string, long long int > enumValues; 332 343 virtual std::string typeString() const override; 333 344 }; … … 342 353 343 354 virtual TraitDecl *clone() const override { return new TraitDecl( *this ); } 344 virtual void accept( Visitor &v ) override { v.visit( this ); } 345 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 346 private: 347 virtual std::string typeString() const override; 355 virtual void accept( Visitor & v ) override { v.visit( this ); } 356 virtual void accept( Visitor & v ) const override { v.visit( this ); } 357 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 358 private: 359 virtual std::string typeString() const override; 360 }; 361 362 class WithStmt : public Declaration { 363 public: 364 std::list< Expression * > exprs; 365 Statement * stmt; 366 367 WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 368 WithStmt( const WithStmt & other ); 369 virtual ~WithStmt(); 370 371 virtual WithStmt * clone() const override { return new WithStmt( *this ); } 372 virtual void accept( Visitor & v ) override { v.visit( this ); } 373 virtual void accept( Visitor & v ) const override { v.visit( this ); } 374 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 375 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 376 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override { print(os, indent); } 348 377 }; 349 378 … … 360 389 361 390 virtual AsmDecl *clone() const override { return new AsmDecl( *this ); } 362 virtual void accept( Visitor &v ) override { v.visit( this ); } 391 virtual void accept( Visitor & v ) override { v.visit( this ); } 392 virtual void accept( Visitor & v ) const override { v.visit( this ); } 363 393 virtual AsmDecl *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 364 394 virtual void print( std::ostream &os, Indenter indent = {} ) const override; … … 376 406 377 407 virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 378 virtual void accept( Visitor &v ) override { v.visit( this ); } 408 virtual void accept( Visitor & v ) override { v.visit( this ); } 409 virtual void accept( Visitor & v ) const override { v.visit( this ); } 379 410 virtual StaticAssertDecl * acceptMutator( Mutator &m ) override { return m.mutate( this ); } 380 411 virtual void print( std::ostream &os, Indenter indent = {} ) const override; -
src/SynTree/Expression.cc
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T ue Jul 25 14:15:47 201713 // Update Count : 5411 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 15 13:43:00 2019 13 // Update Count : 64 14 14 // 15 15 … … 19 19 #include <iostream> // for ostream, operator<<, basic_ostream 20 20 #include <list> // for list, _List_iterator, list<>::co... 21 #include <set> // for set 21 22 22 23 #include "Common/utility.h" // for maybeClone, cloneAll, deleteAll … … 33 34 #include "GenPoly/Lvalue.h" 34 35 35 void printInferParams( const InferredParams & inferParams, std::ostream & os, Indenter indent, int level ) {36 void printInferParams( const InferredParams & inferParams, std::ostream & os, Indenter indent, int level ) { 36 37 if ( ! inferParams.empty() ) { 37 38 os << indent << "with inferred parameters " << level << ":" << std::endl; 38 39 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 39 40 os << indent+1; 40 Declaration::declFromId( i->second.decl )->printShort( os, indent+1 ); 41 assert(i->second.declptr); 42 i->second.declptr->printShort( os, indent+1 ); 41 43 os << std::endl; 42 printInferParams( *i->second.inferParams, os, indent+1, level+1 );44 printInferParams( i->second.expr->inferParams, os, indent+1, level+1 ); 43 45 } // for 44 46 } // if … … 47 49 Expression::Expression() : result( 0 ), env( 0 ) {} 48 50 49 Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ) { 50 } 51 Expression::Expression( const Expression & other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ), resnSlots( other.resnSlots ) {} 51 52 52 53 void Expression::spliceInferParams( Expression * other ) { … … 55 56 inferParams[p.first] = std::move( p.second ); 56 57 } 58 resnSlots.insert( resnSlots.end(), other->resnSlots.begin(), other->resnSlots.end() ); 57 59 } 58 60 … … 62 64 } 63 65 64 void Expression::print( std::ostream &os, Indenter indent ) const { 66 bool Expression::get_lvalue() const { 67 return false; 68 } 69 70 void Expression::print( std::ostream & os, Indenter indent ) const { 65 71 printInferParams( inferParams, os, indent+1, 0 ); 66 72 … … 79 85 } 80 86 81 ConstantExpr::ConstantExpr( const ConstantExpr & other) : Expression( other ), constant( other.constant ) {87 ConstantExpr::ConstantExpr( const ConstantExpr & other) : Expression( other ), constant( other.constant ) { 82 88 } 83 89 84 90 ConstantExpr::~ConstantExpr() {} 85 91 86 void ConstantExpr::print( std::ostream & os, Indenter indent ) const {92 void ConstantExpr::print( std::ostream & os, Indenter indent ) const { 87 93 os << "constant expression " ; 88 94 constant.print( os ); … … 103 109 } 104 110 111 VariableExpr::VariableExpr() : Expression(), var( nullptr ) {} 112 105 113 VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) { 106 114 assert( var ); 107 115 assert( var->get_type() ); 108 116 Type * type = var->get_type()->clone(); 109 type->set_lvalue( true );110 117 111 118 // xxx - doesn't quite work yet - get different alternatives with the same cost … … 117 124 // long long int value; 118 125 // if ( decl->valueOf( var, value ) ) { 119 // type->set_lvalue( false ); 126 // type->set_lvalue( false ); // Would have to move to get_lvalue. 120 127 // } 121 128 // } … … 124 131 } 125 132 126 VariableExpr::VariableExpr( const VariableExpr & other ) : Expression( other ), var( other.var ) {133 VariableExpr::VariableExpr( const VariableExpr & other ) : Expression( other ), var( other.var ) { 127 134 } 128 135 129 136 VariableExpr::~VariableExpr() { 130 137 // don't delete the declaration, since it points somewhere else in the tree 138 } 139 140 bool VariableExpr::get_lvalue() const { 141 // It isn't always an lvalue, but it is never an rvalue. 142 return true; 131 143 } 132 144 … … 137 149 } 138 150 139 void VariableExpr::print( std::ostream & os, Indenter indent ) const {151 void VariableExpr::print( std::ostream & os, Indenter indent ) const { 140 152 os << "Variable Expression: "; 141 153 var->printShort(os, indent); … … 143 155 } 144 156 145 SizeofExpr::SizeofExpr( Expression * expr_ ) :157 SizeofExpr::SizeofExpr( Expression * expr_ ) : 146 158 Expression(), expr(expr_), type(0), isType(false) { 147 159 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 148 160 } 149 161 150 SizeofExpr::SizeofExpr( Type * type_ ) :162 SizeofExpr::SizeofExpr( Type * type_ ) : 151 163 Expression(), expr(0), type(type_), isType(true) { 152 164 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 153 165 } 154 166 155 SizeofExpr::SizeofExpr( const SizeofExpr & other ) :167 SizeofExpr::SizeofExpr( const SizeofExpr & other ) : 156 168 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 157 169 } … … 162 174 } 163 175 164 void SizeofExpr::print( std::ostream & os, Indenter indent) const {176 void SizeofExpr::print( std::ostream & os, Indenter indent) const { 165 177 os << "Sizeof Expression on: "; 166 178 if (isType) type->print(os, indent+1); … … 169 181 } 170 182 171 AlignofExpr::AlignofExpr( Expression * expr_ ) :183 AlignofExpr::AlignofExpr( Expression * expr_ ) : 172 184 Expression(), expr(expr_), type(0), isType(false) { 173 185 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 174 186 } 175 187 176 AlignofExpr::AlignofExpr( Type * type_ ) :188 AlignofExpr::AlignofExpr( Type * type_ ) : 177 189 Expression(), expr(0), type(type_), isType(true) { 178 190 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 179 191 } 180 192 181 AlignofExpr::AlignofExpr( const AlignofExpr & other ) :193 AlignofExpr::AlignofExpr( const AlignofExpr & other ) : 182 194 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 183 195 } … … 188 200 } 189 201 190 void AlignofExpr::print( std::ostream & os, Indenter indent) const {202 void AlignofExpr::print( std::ostream & os, Indenter indent) const { 191 203 os << "Alignof Expression on: "; 192 204 if (isType) type->print(os, indent+1); … … 195 207 } 196 208 197 UntypedOffsetofExpr::UntypedOffsetofExpr( Type * type, const std::string &member ) :209 UntypedOffsetofExpr::UntypedOffsetofExpr( Type * type, const std::string & member ) : 198 210 Expression(), type(type), member(member) { 199 211 assert( type ); … … 201 213 } 202 214 203 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr & other ) :215 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr & other ) : 204 216 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 205 217 … … 208 220 } 209 221 210 void UntypedOffsetofExpr::print( std::ostream & os, Indenter indent) const {222 void UntypedOffsetofExpr::print( std::ostream & os, Indenter indent) const { 211 223 os << "Untyped Offsetof Expression on member " << member << " of "; 212 224 type->print(os, indent+1); … … 214 226 } 215 227 216 OffsetofExpr::OffsetofExpr( Type * type, DeclarationWithType *member ) :228 OffsetofExpr::OffsetofExpr( Type * type, DeclarationWithType * member ) : 217 229 Expression(), type(type), member(member) { 218 230 assert( member ); … … 221 233 } 222 234 223 OffsetofExpr::OffsetofExpr( const OffsetofExpr & other ) :235 OffsetofExpr::OffsetofExpr( const OffsetofExpr & other ) : 224 236 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 225 237 … … 228 240 } 229 241 230 void OffsetofExpr::print( std::ostream & os, Indenter indent) const {242 void OffsetofExpr::print( std::ostream & os, Indenter indent) const { 231 243 os << "Offsetof Expression on member " << member->name << " of "; 232 244 type->print(os, indent+1); … … 234 246 } 235 247 236 OffsetPackExpr::OffsetPackExpr( StructInstType * type ) : Expression(), type( type ) {248 OffsetPackExpr::OffsetPackExpr( StructInstType * type ) : Expression(), type( type ) { 237 249 assert( type ); 238 250 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); 239 251 } 240 252 241 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr & other ) : Expression( other ), type( maybeClone( other.type ) ) {}253 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr & other ) : Expression( other ), type( maybeClone( other.type ) ) {} 242 254 243 255 OffsetPackExpr::~OffsetPackExpr() { delete type; } 244 256 245 void OffsetPackExpr::print( std::ostream & os, Indenter indent ) const {257 void OffsetPackExpr::print( std::ostream & os, Indenter indent ) const { 246 258 os << "Offset pack expression on "; 247 259 type->print(os, indent+1); … … 249 261 } 250 262 251 AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) : 252 Expression(), attr( attr ), expr(expr_), type(0), isType(false) { 253 } 254 255 AttrExpr::AttrExpr( Expression *attr, Type *type_ ) : 256 Expression(), attr( attr ), expr(0), type(type_), isType(true) { 257 } 258 259 AttrExpr::AttrExpr( const AttrExpr &other ) : 260 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 261 } 262 263 AttrExpr::~AttrExpr() { 264 delete attr; 265 delete expr; 266 delete type; 267 } 268 269 void AttrExpr::print( std::ostream &os, Indenter indent) const { 270 os << "Attr "; 271 attr->print( os, indent+1); 272 if ( isType || expr ) { 273 os << "applied to: "; 274 if (isType) type->print(os, indent+1); 275 else expr->print(os, indent+1); 276 } // if 277 Expression::print( os, indent ); 278 } 279 280 CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) { 263 CastExpr::CastExpr( Expression * arg, Type * toType, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) { 281 264 set_result(toType); 282 265 } 283 266 284 CastExpr::CastExpr( Expression * arg, bool isGenerated ) : Expression(),arg(arg), isGenerated( isGenerated ) {267 CastExpr::CastExpr( Expression * arg, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) { 285 268 set_result( new VoidType( Type::Qualifiers() ) ); 286 269 } 287 270 288 CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {271 CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) { 289 272 } 290 273 … … 293 276 } 294 277 295 void CastExpr::print( std::ostream &os, Indenter indent ) const { 296 os << "Cast of:" << std::endl << indent+1; 278 bool CastExpr::get_lvalue() const { 279 // This is actually wrong by C, but it works with our current set-up. 280 return arg->get_lvalue(); 281 } 282 283 void CastExpr::print( std::ostream & os, Indenter indent ) const { 284 os << (isGenerated ? "Generated " : "Explicit ") << "Cast of:" << std::endl << indent+1; 297 285 arg->print(os, indent+1); 298 286 os << std::endl << indent << "... to:"; … … 306 294 } 307 295 308 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) {309 } 310 311 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {296 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) { 297 } 298 299 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) { 312 300 } 313 301 … … 327 315 } 328 316 329 void KeywordCastExpr::print( std::ostream & os, Indenter indent ) const {317 void KeywordCastExpr::print( std::ostream & os, Indenter indent ) const { 330 318 os << "Keyword Cast of:" << std::endl << indent+1; 331 319 arg->print(os, indent+1); … … 335 323 } 336 324 337 VirtualCastExpr::VirtualCastExpr( Expression * arg_, Type *toType ) : Expression(), arg(arg_) {325 VirtualCastExpr::VirtualCastExpr( Expression * arg_, Type * toType ) : Expression(), arg(arg_) { 338 326 set_result(toType); 339 327 } 340 328 341 VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ) {329 VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 342 330 } 343 331 … … 346 334 } 347 335 348 void VirtualCastExpr::print( std::ostream & os, Indenter indent ) const {336 void VirtualCastExpr::print( std::ostream & os, Indenter indent ) const { 349 337 os << "Virtual Cast of:" << std::endl << indent+1; 350 338 arg->print(os, indent+1); … … 359 347 } 360 348 361 UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression * aggregate ) :349 UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression * aggregate ) : 362 350 Expression(), member(member), aggregate(aggregate) { 363 351 assert( aggregate ); 364 352 } 365 353 366 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr & other ) :354 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr & other ) : 367 355 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 368 356 } … … 373 361 } 374 362 375 void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const { 363 bool UntypedMemberExpr::get_lvalue() const { 364 return aggregate->get_lvalue(); 365 } 366 367 void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const { 376 368 os << "Untyped Member Expression, with field: " << std::endl << indent+1; 377 369 member->print(os, indent+1 ); 378 os << indent << "... from aggregate: " << std::endl << indent+1;370 os << indent << "... from aggregate:" << std::endl << indent+1; 379 371 aggregate->print(os, indent+1); 380 372 Expression::print( os, indent ); 381 373 } 382 374 383 MemberExpr::MemberExpr( DeclarationWithType * member, Expression *aggregate ) :375 MemberExpr::MemberExpr( DeclarationWithType * member, Expression * aggregate ) : 384 376 Expression(), member(member), aggregate(aggregate) { 385 377 assert( member ); … … 391 383 sub.apply( res ); 392 384 result = res; 393 result->set_lvalue( true );394 385 result->get_qualifiers() |= aggregate->result->get_qualifiers(); 395 386 } 396 387 397 MemberExpr::MemberExpr( const MemberExpr & other ) :388 MemberExpr::MemberExpr( const MemberExpr & other ) : 398 389 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { 399 390 } … … 404 395 } 405 396 406 void MemberExpr::print( std::ostream &os, Indenter indent ) const { 407 os << "Member Expression, with field: " << std::endl; 397 bool MemberExpr::get_lvalue() const { 398 // This is actually wrong by C, but it works with our current set-up. 399 return true; 400 } 401 402 void MemberExpr::print( std::ostream & os, Indenter indent ) const { 403 os << "Member Expression, with field:" << std::endl; 408 404 os << indent+1; 409 405 member->print( os, indent+1 ); 410 os << std::endl << indent << "... from aggregate: " << std::endl << indent+1;406 os << std::endl << indent << "... from aggregate:" << std::endl << indent+1; 411 407 aggregate->print(os, indent + 1); 412 408 Expression::print( os, indent ); 413 409 } 414 410 415 UntypedExpr::UntypedExpr( Expression * function, const std::list<Expression *> &args ) :411 UntypedExpr::UntypedExpr( Expression * function, const std::list<Expression *> & args ) : 416 412 Expression(), function(function), args(args) {} 417 413 418 UntypedExpr::UntypedExpr( const UntypedExpr & other ) :414 UntypedExpr::UntypedExpr( const UntypedExpr & other ) : 419 415 Expression( other ), function( maybeClone( other.function ) ) { 420 416 cloneAll( other.args, args ); … … 435 431 // if references are still allowed in the AST, dereference returns a reference 436 432 ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) ); 437 } else {438 // references have been removed, in which case dereference returns an lvalue of the base type.439 ret->result->set_lvalue( true );440 433 } 441 434 } … … 454 447 } 455 448 456 457 void UntypedExpr::print( std::ostream &os, Indenter indent ) const { 458 os << "Applying untyped: " << std::endl; 449 bool UntypedExpr::get_lvalue() const { 450 // from src/GenPoly/Lvalue.cc: isIntrinsicReference 451 static std::set<std::string> lvalueFunctions = { "*?", "?[?]" }; 452 std::string fname = InitTweak::getFunctionName( const_cast< UntypedExpr * >( this ) ); 453 return lvalueFunctions.count(fname); 454 } 455 456 void UntypedExpr::print( std::ostream & os, Indenter indent ) const { 457 os << "Applying untyped:" << std::endl; 459 458 os << indent+1; 460 459 function->print(os, indent+1); 461 os << std::endl << indent << "...to: " << std::endl;460 os << std::endl << indent << "...to:" << std::endl; 462 461 printAll(args, os, indent+1); 463 462 Expression::print( os, indent ); … … 469 468 } 470 469 471 NameExpr::NameExpr( const NameExpr & other ) : Expression( other ), name( other.name ) {470 NameExpr::NameExpr( const NameExpr & other ) : Expression( other ), name( other.name ) { 472 471 } 473 472 474 473 NameExpr::~NameExpr() {} 475 474 476 void NameExpr::print( std::ostream & os, Indenter indent ) const {475 void NameExpr::print( std::ostream & os, Indenter indent ) const { 477 476 os << "Name: " << get_name(); 478 477 Expression::print( os, indent ); 479 478 } 480 479 481 LogicalExpr::LogicalExpr( Expression * arg1_, Expression *arg2_, bool andp ) :480 LogicalExpr::LogicalExpr( Expression * arg1_, Expression * arg2_, bool andp ) : 482 481 Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) { 483 482 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 484 483 } 485 484 486 LogicalExpr::LogicalExpr( const LogicalExpr & other ) :485 LogicalExpr::LogicalExpr( const LogicalExpr & other ) : 487 486 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { 488 487 } … … 493 492 } 494 493 495 void LogicalExpr::print( std::ostream & os, Indenter indent )const {494 void LogicalExpr::print( std::ostream & os, Indenter indent )const { 496 495 os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: "; 497 496 arg1->print(os); … … 504 503 Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {} 505 504 506 ConditionalExpr::ConditionalExpr( const ConditionalExpr & other ) :505 ConditionalExpr::ConditionalExpr( const ConditionalExpr & other ) : 507 506 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { 508 507 } … … 514 513 } 515 514 516 void ConditionalExpr::print( std::ostream &os, Indenter indent ) const { 515 bool ConditionalExpr::get_lvalue() const { 516 return false; 517 } 518 519 void ConditionalExpr::print( std::ostream & os, Indenter indent ) const { 517 520 os << "Conditional expression on: " << std::endl << indent+1; 518 521 arg1->print( os, indent+1 ); … … 527 530 528 531 529 void AsmExpr::print( std::ostream & os, Indenter indent ) const {532 void AsmExpr::print( std::ostream & os, Indenter indent ) const { 530 533 os << "Asm Expression: " << std::endl; 531 534 if ( inout ) inout->print( os, indent+1 ); … … 538 541 assert( callExpr ); 539 542 assert( callExpr->result ); 540 set_result( callExpr-> get_result()->clone() );543 set_result( callExpr->result->clone() ); 541 544 } 542 545 543 546 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { 544 cloneAll( other.tempDecls, tempDecls );545 cloneAll( other.returnDecls, returnDecls );546 cloneAll( other.dtors, dtors );547 547 } 548 548 … … 550 550 set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment 551 551 delete callExpr; 552 deleteAll( tempDecls ); 553 deleteAll( returnDecls ); 554 deleteAll( dtors ); 555 } 556 557 void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const { 552 } 553 554 void ImplicitCopyCtorExpr::print( std::ostream & os, Indenter indent ) const { 558 555 os << "Implicit Copy Constructor Expression: " << std::endl << indent+1; 559 556 callExpr->print( os, indent+1 ); 560 os << std::endl << indent << "... with temporaries:" << std::endl;561 printAll( tempDecls, os, indent+1 );562 os << std::endl << indent << "... with return temporaries:" << std::endl;563 printAll( returnDecls, os, indent+1 );564 Expression::print( os, indent );565 557 } 566 558 … … 581 573 } 582 574 583 void ConstructorExpr::print( std::ostream &os, Indenter indent ) const { 575 bool ConstructorExpr::get_lvalue() const { 576 return false; 577 } 578 579 void ConstructorExpr::print( std::ostream & os, Indenter indent ) const { 584 580 os << "Constructor Expression: " << std::endl << indent+1; 585 581 callExpr->print( os, indent + 2 ); … … 590 586 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) { 591 587 assert( type && initializer ); 592 type->set_lvalue( true );593 588 set_result( type ); 594 589 } 595 590 596 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {}591 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {} 597 592 598 593 CompoundLiteralExpr::~CompoundLiteralExpr() { … … 600 595 } 601 596 602 void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const { 597 bool CompoundLiteralExpr::get_lvalue() const { 598 return true; 599 } 600 601 void CompoundLiteralExpr::print( std::ostream & os, Indenter indent ) const { 603 602 os << "Compound Literal Expression: " << std::endl << indent+1; 604 603 result->print( os, indent+1 ); … … 608 607 } 609 608 610 RangeExpr::RangeExpr( Expression * low, Expression *high ) : low( low ), high( high ) {}611 RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}612 void RangeExpr::print( std::ostream & os, Indenter indent ) const {609 RangeExpr::RangeExpr( Expression * low, Expression * high ) : low( low ), high( high ) {} 610 RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 611 void RangeExpr::print( std::ostream & os, Indenter indent ) const { 613 612 os << "Range Expression: "; 614 613 low->print( os, indent ); … … 618 617 } 619 618 620 StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) {619 StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) { 621 620 computeResult(); 622 621 } 623 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone()) {622 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ), resultExpr( other.resultExpr ) { 624 623 cloneAll( other.returnDecls, returnDecls ); 625 624 cloneAll( other.dtors, dtors ); … … 650 649 } 651 650 } 652 void StmtExpr::print( std::ostream &os, Indenter indent ) const { 651 bool StmtExpr::get_lvalue() const { 652 return false; 653 } 654 void StmtExpr::print( std::ostream & os, Indenter indent ) const { 653 655 os << "Statement Expression: " << std::endl << indent+1; 654 656 statements->print( os, indent+1 ); … … 666 668 667 669 long long UniqueExpr::count = 0; 668 UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {670 UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) { 669 671 assert( expr ); 670 672 assert( count != -1 ); … … 674 676 } 675 677 } 676 UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {678 UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { 677 679 } 678 680 UniqueExpr::~UniqueExpr() { … … 681 683 delete var; 682 684 } 683 void UniqueExpr::print( std::ostream & os, Indenter indent ) const {685 void UniqueExpr::print( std::ostream & os, Indenter indent ) const { 684 686 os << "Unique Expression with id:" << id << std::endl << indent+1; 685 687 expr->print( os, indent+1 ); … … 732 734 } 733 735 734 DeletedExpr::DeletedExpr( Expression * expr, BaseSyntaxNode* deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {736 DeletedExpr::DeletedExpr( Expression * expr, Declaration * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) { 735 737 assert( expr->result ); 736 738 result = expr->result->clone(); … … 746 748 os << std::endl << indent+1 << "... deleted by: "; 747 749 deleteStmt->print( os, indent+1 ); 750 } 751 752 753 DefaultArgExpr::DefaultArgExpr( Expression * expr ) : expr( expr ) { 754 assert( expr->result ); 755 result = expr->result->clone(); 756 } 757 DefaultArgExpr::DefaultArgExpr( const DefaultArgExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ) {} 758 DefaultArgExpr::~DefaultArgExpr() { 759 delete expr; 760 } 761 762 void DefaultArgExpr::print( std::ostream & os, Indenter indent ) const { 763 os << "Default Argument Expression" << std::endl << indent+1; 764 expr->print( os, indent+1 ); 748 765 } 749 766 -
src/SynTree/Expression.h
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Sep 3 19:23:46 201713 // Update Count : 4811 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 15 13:46:00 2019 13 // Update Count : 54 14 14 // 15 15 … … 21 21 #include <memory> // for allocator, unique_ptr 22 22 #include <string> // for string 23 #include <vector> // for vector 23 24 24 25 #include "BaseSyntaxNode.h" // for BaseSyntaxNode … … 38 39 /// but subject to decay-to-pointer and type parameter renaming 39 40 struct ParamEntry { 40 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams) {}41 ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}41 ParamEntry(): decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {} 42 ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr ); 42 43 ParamEntry( const ParamEntry & other ); 43 44 ParamEntry( ParamEntry && other ); 44 45 ~ParamEntry(); 45 ParamEntry & operator=( const ParamEntry & other );46 46 ParamEntry & operator=( ParamEntry && other ); 47 47 48 UniqueId decl; 49 Type * actualType; 50 Type * formalType; 48 UniqueId const decl; 49 Declaration * const declptr; 50 Type * const actualType; 51 Type * const formalType; 51 52 Expression * expr; 52 std::unique_ptr< InferredParams > inferParams;53 53 }; 54 54 … … 59 59 TypeSubstitution * env; 60 60 bool extension = false; 61 InferredParams inferParams; 61 InferredParams inferParams; ///< Post-resolution inferred parameter slots 62 std::vector<UniqueId> resnSlots; ///< Pre-resolution inferred parameter slots 63 64 // xxx - should turn inferParams+resnSlots into a union to save some memory 62 65 63 66 Expression(); … … 68 71 const Type * get_result() const { return result; } 69 72 void set_result( Type * newValue ) { result = newValue; } 73 virtual bool get_lvalue() const; 70 74 71 75 TypeSubstitution * get_env() const { return env; } … … 74 78 Expression * set_extension( bool exten ) { extension = exten; return this; } 75 79 76 InferredParams & get_inferParams() { return inferParams; }77 78 80 // move other's inferParams to this 79 81 void spliceInferParams( Expression * other ); … … 81 83 virtual Expression * clone() const override = 0; 82 84 virtual void accept( Visitor & v ) override = 0; 85 virtual void accept( Visitor & v ) const override = 0; 83 86 virtual Expression * acceptMutator( Mutator & m ) override = 0; 84 87 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 96 99 virtual ~ApplicationExpr(); 97 100 101 bool get_lvalue() const final; 102 98 103 Expression * get_function() const { return function; } 99 104 void set_function( Expression * newValue ) { function = newValue; } 100 105 std::list<Expression *>& get_args() { return args; } 101 106 102 virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); } 103 virtual void accept( Visitor & v ) { v.visit( this ); } 104 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 105 virtual void print( std::ostream & os, Indenter indent = {} ) const; 107 virtual ApplicationExpr * clone() const override { return new ApplicationExpr( * this ); } 108 virtual void accept( Visitor & v ) override { v.visit( this ); } 109 virtual void accept( Visitor & v ) const override { v.visit( this ); } 110 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 111 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 106 112 }; 107 113 … … 118 124 virtual ~UntypedExpr(); 119 125 126 bool get_lvalue() const final; 127 120 128 Expression * get_function() const { return function; } 121 129 void set_function( Expression * newValue ) { function = newValue; } … … 128 136 static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 ); 129 137 130 virtual UntypedExpr * clone() const { return new UntypedExpr( * 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, Indenter indent = {} ) const; 138 virtual UntypedExpr * clone() const override { return new UntypedExpr( * this ); } 139 virtual void accept( Visitor & v ) override { v.visit( this ); } 140 virtual void accept( Visitor & v ) const override { v.visit( this ); } 141 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 142 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 134 143 }; 135 144 … … 146 155 void set_name( std::string newValue ) { name = newValue; } 147 156 148 virtual NameExpr * clone() const { return new NameExpr( * this ); } 149 virtual void accept( Visitor & v ) { v.visit( this ); } 150 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 151 virtual void print( std::ostream & os, Indenter indent = {} ) const; 157 virtual NameExpr * clone() const override { return new NameExpr( * this ); } 158 virtual void accept( Visitor & v ) override { v.visit( this ); } 159 virtual void accept( Visitor & v ) const override { v.visit( this ); } 160 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 161 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 152 162 }; 153 163 … … 167 177 void set_arg(Expression * newValue ) { arg = newValue; } 168 178 169 virtual AddressExpr * clone() const { return new AddressExpr( * this ); } 170 virtual void accept( Visitor & v ) { v.visit( this ); } 171 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 172 virtual void print( std::ostream & os, Indenter indent = {} ) const; 179 virtual AddressExpr * clone() const override { return new AddressExpr( * this ); } 180 virtual void accept( Visitor & v ) override { v.visit( this ); } 181 virtual void accept( Visitor & v ) const override { v.visit( this ); } 182 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 183 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 173 184 }; 174 185 … … 183 194 virtual ~LabelAddressExpr(); 184 195 185 virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); } 186 virtual void accept( Visitor & v ) { v.visit( this ); } 187 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 188 virtual void print( std::ostream & os, Indenter indent = {} ) const; 196 virtual LabelAddressExpr * clone() const override { return new LabelAddressExpr( * this ); } 197 virtual void accept( Visitor & v ) override { v.visit( this ); } 198 virtual void accept( Visitor & v ) const override { v.visit( this ); } 199 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 200 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 189 201 }; 190 202 … … 193 205 public: 194 206 Expression * arg; 195 bool isGenerated = true; // whether this cast appeared in the sourceprogram207 bool isGenerated = true; // cast generated implicitly by code generation or explicit in program 196 208 197 209 CastExpr( Expression * arg, bool isGenerated = true ); … … 201 213 virtual ~CastExpr(); 202 214 215 bool get_lvalue() const final; 216 203 217 Expression * get_arg() const { return arg; } 204 218 void set_arg( Expression * newValue ) { arg = newValue; } 205 219 206 virtual CastExpr * clone() const { return new CastExpr( * this ); } 207 virtual void accept( Visitor & v ) { v.visit( this ); } 208 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 209 virtual void print( std::ostream & os, Indenter indent = {} ) const; 220 virtual CastExpr * clone() const override { return new CastExpr( * this ); } 221 virtual void accept( Visitor & v ) override { v.visit( this ); } 222 virtual void accept( Visitor & v ) const override { v.visit( this ); } 223 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 224 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 210 225 }; 211 226 … … 224 239 const std::string & targetString() const; 225 240 226 virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); } 227 virtual void accept( Visitor & v ) { v.visit( this ); } 228 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 229 virtual void print( std::ostream & os, Indenter indent = {} ) const; 241 virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); } 242 virtual void accept( Visitor & v ) override { v.visit( this ); } 243 virtual void accept( Visitor & v ) const override { v.visit( this ); } 244 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 245 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 230 246 }; 231 247 … … 242 258 void set_arg( Expression * newValue ) { arg = newValue; } 243 259 244 virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); } 245 virtual void accept( Visitor & v ) { v.visit( this ); } 246 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 247 virtual void print( std::ostream & os, Indenter indent = {} ) const; 260 virtual VirtualCastExpr * clone() const override { return new VirtualCastExpr( * this ); } 261 virtual void accept( Visitor & v ) override { v.visit( this ); } 262 virtual void accept( Visitor & v ) const override { v.visit( this ); } 263 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 264 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 248 265 }; 249 266 … … 257 274 UntypedMemberExpr( const UntypedMemberExpr & other ); 258 275 virtual ~UntypedMemberExpr(); 276 277 bool get_lvalue() const final; 259 278 260 279 Expression * get_member() const { return member; } … … 263 282 void set_aggregate( Expression * newValue ) { aggregate = newValue; } 264 283 265 virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * 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, Indenter indent = {} ) const; 284 virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); } 285 virtual void accept( Visitor & v ) override { v.visit( this ); } 286 virtual void accept( Visitor & v ) const override { v.visit( this ); } 287 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 288 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 269 289 }; 270 290 … … 279 299 MemberExpr( const MemberExpr & other ); 280 300 virtual ~MemberExpr(); 301 302 bool get_lvalue() const final; 281 303 282 304 DeclarationWithType * get_member() const { return member; } … … 285 307 void set_aggregate( Expression * newValue ) { aggregate = newValue; } 286 308 287 virtual MemberExpr * clone() const { return new MemberExpr( * this ); } 288 virtual void accept( Visitor & v ) { v.visit( this ); } 289 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 290 virtual void print( std::ostream & os, Indenter indent = {} ) const; 309 virtual MemberExpr * clone() const override { return new MemberExpr( * this ); } 310 virtual void accept( Visitor & v ) override { v.visit( this ); } 311 virtual void accept( Visitor & v ) const override { v.visit( this ); } 312 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 313 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 291 314 }; 292 315 … … 297 320 DeclarationWithType * var; 298 321 322 VariableExpr(); 299 323 VariableExpr( DeclarationWithType * var ); 300 324 VariableExpr( const VariableExpr & other ); 301 325 virtual ~VariableExpr(); 302 326 327 bool get_lvalue() const final; 328 303 329 DeclarationWithType * get_var() const { return var; } 304 330 void set_var( DeclarationWithType * newValue ) { var = newValue; } … … 306 332 static VariableExpr * functionPointer( FunctionDecl * decl ); 307 333 308 virtual VariableExpr * clone() const { return new VariableExpr( * this ); } 309 virtual void accept( Visitor & v ) { v.visit( this ); } 310 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 311 virtual void print( std::ostream & os, Indenter indent = {} ) const; 334 virtual VariableExpr * clone() const override { return new VariableExpr( * this ); } 335 virtual void accept( Visitor & v ) override { v.visit( this ); } 336 virtual void accept( Visitor & v ) const override { v.visit( this ); } 337 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 338 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 312 339 }; 313 340 … … 327 354 long long int intValue() const; 328 355 329 virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); } 330 virtual void accept( Visitor & v ) { v.visit( this ); } 331 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 332 virtual void print( std::ostream & os, Indenter indent = {} ) const; 356 virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); } 357 virtual void accept( Visitor & v ) override { v.visit( this ); } 358 virtual void accept( Visitor & v ) const override { v.visit( this ); } 359 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 360 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 333 361 }; 334 362 … … 352 380 void set_isType( bool newValue ) { isType = newValue; } 353 381 354 virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); } 355 virtual void accept( Visitor & v ) { v.visit( this ); } 356 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 357 virtual void print( std::ostream & os, Indenter indent = {} ) const; 382 virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); } 383 virtual void accept( Visitor & v ) override { v.visit( this ); } 384 virtual void accept( Visitor & v ) const override { v.visit( this ); } 385 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 386 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 358 387 }; 359 388 … … 377 406 void set_isType( bool newValue ) { isType = newValue; } 378 407 379 virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); } 380 virtual void accept( Visitor & v ) { v.visit( this ); } 381 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 382 virtual void print( std::ostream & os, Indenter indent = {} ) const; 408 virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); } 409 virtual void accept( Visitor & v ) override { v.visit( this ); } 410 virtual void accept( Visitor & v ) const override { v.visit( this ); } 411 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 412 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 383 413 }; 384 414 … … 398 428 void set_type( Type * newValue ) { type = newValue; } 399 429 400 virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); } 401 virtual void accept( Visitor & v ) { v.visit( this ); } 402 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 403 virtual void print( std::ostream & os, Indenter indent = {} ) const; 430 virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); } 431 virtual void accept( Visitor & v ) override { v.visit( this ); } 432 virtual void accept( Visitor & v ) const override { v.visit( this ); } 433 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 434 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 404 435 }; 405 436 … … 419 450 void set_member( DeclarationWithType * newValue ) { member = newValue; } 420 451 421 virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); } 422 virtual void accept( Visitor & v ) { v.visit( this ); } 423 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 424 virtual void print( std::ostream & os, Indenter indent = {} ) const; 452 virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); } 453 virtual void accept( Visitor & v ) override { v.visit( this ); } 454 virtual void accept( Visitor & v ) const override { v.visit( this ); } 455 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 456 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 425 457 }; 426 458 … … 437 469 void set_type( StructInstType * newValue ) { type = newValue; } 438 470 439 virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); } 440 virtual void accept( Visitor & v ) { v.visit( this ); } 441 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 442 virtual void print( std::ostream & os, Indenter indent = {} ) const; 443 }; 444 445 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined) 446 class AttrExpr : public Expression { 447 public: 448 Expression * attr; 449 Expression * expr; 450 Type * type; 451 bool isType; 452 453 AttrExpr(Expression * attr, Expression * expr ); 454 AttrExpr( const AttrExpr & other ); 455 AttrExpr( Expression * attr, Type * type ); 456 virtual ~AttrExpr(); 457 458 Expression * get_attr() const { return attr; } 459 void set_attr( Expression * newValue ) { attr = newValue; } 460 Expression * get_expr() const { return expr; } 461 void set_expr( Expression * newValue ) { expr = newValue; } 462 Type * get_type() const { return type; } 463 void set_type( Type * newValue ) { type = newValue; } 464 bool get_isType() const { return isType; } 465 void set_isType( bool newValue ) { isType = newValue; } 466 467 virtual AttrExpr * clone() const { return new AttrExpr( * this ); } 468 virtual void accept( Visitor & v ) { v.visit( this ); } 469 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 470 virtual void print( std::ostream & os, Indenter indent = {} ) const; 471 virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); } 472 virtual void accept( Visitor & v ) override { v.visit( this ); } 473 virtual void accept( Visitor & v ) const override { v.visit( this ); } 474 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 475 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 471 476 }; 472 477 … … 487 492 void set_arg2( Expression * newValue ) { arg2 = newValue; } 488 493 489 virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); } 490 virtual void accept( Visitor & v ) { v.visit( this ); } 491 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 492 virtual void print( std::ostream & os, Indenter indent = {} ) const; 494 virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); } 495 virtual void accept( Visitor & v ) override { v.visit( this ); } 496 virtual void accept( Visitor & v ) const override { v.visit( this ); } 497 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 498 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 493 499 494 500 private: … … 506 512 ConditionalExpr( const ConditionalExpr & other ); 507 513 virtual ~ConditionalExpr(); 514 515 bool get_lvalue() const final; 508 516 509 517 Expression * get_arg1() const { return arg1; } … … 514 522 void set_arg3( Expression * newValue ) { arg3 = newValue; } 515 523 516 virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); } 517 virtual void accept( Visitor & v ) { v.visit( this ); } 518 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 519 virtual void print( std::ostream & os, Indenter indent = {} ) const; 524 virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); } 525 virtual void accept( Visitor & v ) override { v.visit( this ); } 526 virtual void accept( Visitor & v ) const override { v.visit( this ); } 527 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 528 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 520 529 }; 521 530 … … 529 538 CommaExpr( const CommaExpr & other ); 530 539 virtual ~CommaExpr(); 540 541 bool get_lvalue() const final; 531 542 532 543 Expression * get_arg1() const { return arg1; } … … 535 546 void set_arg2( Expression * newValue ) { arg2 = newValue; } 536 547 537 virtual CommaExpr * clone() const { return new CommaExpr( * this ); } 538 virtual void accept( Visitor & v ) { v.visit( this ); } 539 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 540 virtual void print( std::ostream & os, Indenter indent = {} ) const; 548 virtual CommaExpr * clone() const override { return new CommaExpr( * this ); } 549 virtual void accept( Visitor & v ) override { v.visit( this ); } 550 virtual void accept( Visitor & v ) const override { v.visit( this ); } 551 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 552 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 541 553 }; 542 554 … … 553 565 void set_type( Type * newValue ) { type = newValue; } 554 566 555 virtual TypeExpr * clone() const { return new TypeExpr( * this ); } 556 virtual void accept( Visitor & v ) { v.visit( this ); } 557 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 558 virtual void print( std::ostream & os, Indenter indent = {} ) const; 567 virtual TypeExpr * clone() const override { return new TypeExpr( * this ); } 568 virtual void accept( Visitor & v ) override { v.visit( this ); } 569 virtual void accept( Visitor & v ) const override { v.visit( this ); } 570 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 571 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 559 572 }; 560 573 … … 579 592 void set_operand( Expression * newValue ) { operand = newValue; } 580 593 581 virtual AsmExpr * clone() const { return new AsmExpr( * this ); } 582 virtual void accept( Visitor & v ) { v.visit( this ); } 583 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 584 virtual void print( std::ostream & os, Indenter indent = {} ) const; 594 virtual AsmExpr * clone() const override { return new AsmExpr( * this ); } 595 virtual void accept( Visitor & v ) override { v.visit( this ); } 596 virtual void accept( Visitor & v ) const override { v.visit( this ); } 597 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 598 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 585 599 586 600 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints … … 591 605 class ImplicitCopyCtorExpr : public Expression { 592 606 public: 593 ApplicationExpr * callExpr; 594 std::list< ObjectDecl * > tempDecls; 595 std::list< ObjectDecl * > returnDecls; 596 std::list< Expression * > dtors; 607 ApplicationExpr * callExpr = nullptr; 597 608 598 609 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); … … 600 611 virtual ~ImplicitCopyCtorExpr(); 601 612 602 ApplicationExpr * get_callExpr() const { return callExpr; } 603 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; } 604 605 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 606 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 607 std::list< Expression * > & get_dtors() { return dtors; } 608 609 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); } 610 virtual void accept( Visitor & v ) { v.visit( this ); } 611 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 612 virtual void print( std::ostream & os, Indenter indent = {} ) const; 613 virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); } 614 virtual void accept( Visitor & v ) override { v.visit( this ); } 615 virtual void accept( Visitor & v ) const override { v.visit( this ); } 616 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 617 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 613 618 }; 614 619 … … 622 627 ~ConstructorExpr(); 623 628 629 bool get_lvalue() const final; 630 624 631 Expression * get_callExpr() const { return callExpr; } 625 632 void set_callExpr( Expression * newValue ) { callExpr = newValue; } 626 633 627 virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); } 628 virtual void accept( Visitor & v ) { v.visit( this ); } 629 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 630 virtual void print( std::ostream & os, Indenter indent = {} ) const; 634 virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); } 635 virtual void accept( Visitor & v ) override { v.visit( this ); } 636 virtual void accept( Visitor & v ) const override { v.visit( this ); } 637 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 638 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 631 639 }; 632 640 … … 640 648 virtual ~CompoundLiteralExpr(); 641 649 650 bool get_lvalue() const final; 651 642 652 Initializer * get_initializer() const { return initializer; } 643 653 void set_initializer( Initializer * i ) { initializer = i; } 644 654 645 virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); } 646 virtual void accept( Visitor & v ) { v.visit( this ); } 647 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 648 virtual void print( std::ostream & os, Indenter indent = {} ) const; 655 virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); } 656 virtual void accept( Visitor & v ) override { v.visit( this ); } 657 virtual void accept( Visitor & v ) const override { v.visit( this ); } 658 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 659 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 649 660 }; 650 661 … … 662 673 RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; } 663 674 664 virtual RangeExpr * clone() const { return new RangeExpr( * this ); } 665 virtual void accept( Visitor & v ) { v.visit( this ); } 666 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 667 virtual void print( std::ostream & os, Indenter indent = {} ) const; 675 virtual RangeExpr * clone() const override { return new RangeExpr( * this ); } 676 virtual void accept( Visitor & v ) override { v.visit( this ); } 677 virtual void accept( Visitor & v ) const override { v.visit( this ); } 678 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 679 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 668 680 }; 669 681 … … 679 691 std::list<Expression*>& get_exprs() { return exprs; } 680 692 681 virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); } 682 virtual void accept( Visitor & v ) { v.visit( this ); } 683 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 684 virtual void print( std::ostream & os, Indenter indent = {} ) const; 693 virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); } 694 virtual void accept( Visitor & v ) override { v.visit( this ); } 695 virtual void accept( Visitor & v ) const override { v.visit( this ); } 696 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 697 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 685 698 }; 686 699 … … 694 707 virtual ~TupleExpr(); 695 708 709 bool get_lvalue() const final; 710 696 711 std::list<Expression*>& get_exprs() { return exprs; } 697 712 698 virtual TupleExpr * clone() const { return new TupleExpr( * this ); } 699 virtual void accept( Visitor & v ) { v.visit( this ); } 700 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 701 virtual void print( std::ostream & os, Indenter indent = {} ) const; 713 virtual TupleExpr * clone() const override { return new TupleExpr( * this ); } 714 virtual void accept( Visitor & v ) override { v.visit( this ); } 715 virtual void accept( Visitor & v ) const override { v.visit( this ); } 716 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 717 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 702 718 }; 703 719 … … 711 727 TupleIndexExpr( const TupleIndexExpr & other ); 712 728 virtual ~TupleIndexExpr(); 729 730 bool get_lvalue() const final; 713 731 714 732 Expression * get_tuple() const { return tuple; } … … 717 735 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; } 718 736 719 virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); } 720 virtual void accept( Visitor & v ) { v.visit( this ); } 721 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 722 virtual void print( std::ostream & os, Indenter indent = {} ) const; 737 virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); } 738 virtual void accept( Visitor & v ) override { v.visit( this ); } 739 virtual void accept( Visitor & v ) const override { v.visit( this ); } 740 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 741 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 723 742 }; 724 743 … … 735 754 StmtExpr * get_stmtExpr() const { return stmtExpr; } 736 755 737 virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); } 738 virtual void accept( Visitor & v ) { v.visit( this ); } 739 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 740 virtual void print( std::ostream & os, Indenter indent = {} ) const; 756 virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); } 757 virtual void accept( Visitor & v ) override { v.visit( this ); } 758 virtual void accept( Visitor & v ) const override { v.visit( this ); } 759 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 760 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 761 762 friend class ConverterNewToOld; 763 private: 764 TupleAssignExpr( StmtExpr * stmts ); 741 765 }; 742 766 … … 748 772 std::list< Expression * > dtors; // destructor(s) for return variable(s) 749 773 774 // readonly 775 ExprStmt * resultExpr = nullptr; 776 750 777 StmtExpr( CompoundStmt * statements ); 751 778 StmtExpr( const StmtExpr & other ); 752 779 virtual ~StmtExpr(); 753 780 781 bool get_lvalue() const final; 782 754 783 CompoundStmt * get_statements() const { return statements; } 755 784 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } … … 761 790 std::list< Expression * > & get_dtors() { return dtors; } 762 791 763 virtual StmtExpr * clone() const { return new StmtExpr( * this ); } 764 virtual void accept( Visitor & v ) { v.visit( this ); } 765 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 766 virtual void print( std::ostream & os, Indenter indent = {} ) const; 792 virtual StmtExpr * clone() const override { return new StmtExpr( * this ); } 793 virtual void accept( Visitor & v ) override { v.visit( this ); } 794 virtual void accept( Visitor & v ) const override { v.visit( this ); } 795 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 796 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 767 797 }; 768 798 … … 788 818 int get_id() const { return id; } 789 819 790 virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); } 791 virtual void accept( Visitor & v ) { v.visit( this ); } 792 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 793 virtual void print( std::ostream & os, Indenter indent = {} ) const; 820 virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); } 821 virtual void accept( Visitor & v ) override { v.visit( this ); } 822 virtual void accept( Visitor & v ) const override { v.visit( this ); } 823 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 824 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 794 825 795 826 private: … … 822 853 std::list<InitAlternative> & get_initAlts() { return initAlts; } 823 854 824 virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); } 825 virtual void accept( Visitor & v ) { v.visit( this ); } 826 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 827 virtual void print( std::ostream & os, Indenter indent = {} ) const; 855 virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); } 856 virtual void accept( Visitor & v ) override { v.visit( this ); } 857 virtual void accept( Visitor & v ) const override { v.visit( this ); } 858 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 859 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 828 860 }; 829 861 … … 843 875 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; } 844 876 845 virtual InitExpr * clone() const { return new InitExpr( * this ); } 846 virtual void accept( Visitor & v ) { v.visit( this ); } 847 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 848 virtual void print( std::ostream & os, Indenter indent = {} ) const; 877 virtual InitExpr * clone() const override { return new InitExpr( * this ); } 878 virtual void accept( Visitor & v ) override { v.visit( this ); } 879 virtual void accept( Visitor & v ) const override { v.visit( this ); } 880 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 881 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 849 882 }; 850 883 … … 853 886 public: 854 887 Expression * expr; 855 BaseSyntaxNode* deleteStmt;856 857 DeletedExpr( Expression * expr, BaseSyntaxNode* deleteStmt );888 Declaration * deleteStmt; 889 890 DeletedExpr( Expression * expr, Declaration * deleteStmt ); 858 891 DeletedExpr( const DeletedExpr & other ); 859 892 ~DeletedExpr(); 860 893 861 virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); } 862 virtual void accept( Visitor & v ) { v.visit( this ); } 863 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 864 virtual void print( std::ostream & os, Indenter indent = {} ) const; 894 virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); } 895 virtual void accept( Visitor & v ) override { v.visit( this ); } 896 virtual void accept( Visitor & v ) const override { v.visit( this ); } 897 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 898 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 899 }; 900 901 /// expression wrapping the use of a default argument - should never make it past the resolver. 902 class DefaultArgExpr : public Expression { 903 public: 904 Expression * expr; 905 906 DefaultArgExpr( Expression * expr ); 907 DefaultArgExpr( const DefaultArgExpr & other ); 908 ~DefaultArgExpr(); 909 910 virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); } 911 virtual void accept( Visitor & v ) override { v.visit( this ); } 912 virtual void accept( Visitor & v ) const override { v.visit( this ); } 913 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 914 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 865 915 }; 866 916 … … 887 937 virtual ~GenericExpr(); 888 938 889 virtual GenericExpr * clone() const { return new GenericExpr( * this ); } 890 virtual void accept( Visitor & v ) { v.visit( this ); } 891 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 892 virtual void print( std::ostream & os, Indenter indent = {} ) const; 939 virtual GenericExpr * clone() const override { return new GenericExpr( * this ); } 940 virtual void accept( Visitor & v ) override { v.visit( this ); } 941 virtual void accept( Visitor & v ) const override { v.visit( this ); } 942 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 943 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 893 944 }; 894 945 -
src/SynTree/FunctionDecl.cc
r7951100 rb067d9b 87 87 88 88 if ( statements ) { 89 os << indent << "... with body " << endl << indent+1;89 os << indent << "... with body" << endl << indent+1; 90 90 statements->print( os, indent+1 ); 91 91 } // if -
src/SynTree/FunctionType.cc
r7951100 rb067d9b 66 66 os << indent+1 << "accepting unspecified arguments" << endl; 67 67 } // if 68 os << indent << "... returning ";68 os << indent << "... returning"; 69 69 if ( returnVals.empty() ) { 70 os << " nothing" << endl;70 os << " nothing" << endl; 71 71 } else { 72 72 os << endl; -
src/SynTree/Initializer.h
r7951100 rb067d9b 38 38 39 39 virtual Designation * clone() const override { return new Designation( *this ); }; 40 virtual void accept( Visitor &v ) override { v.visit( this ); } 40 virtual void accept( Visitor & v ) override { v.visit( this ); } 41 virtual void accept( Visitor & v ) const override { v.visit( this ); } 41 42 virtual Designation * acceptMutator( Mutator &m ) override { return m.mutate( this ); } 42 43 virtual void print( std::ostream &os, Indenter indent = {} ) const override; … … 52 53 virtual ~Initializer(); 53 54 54 bool get_maybeConstructed() { return maybeConstructed; }55 bool get_maybeConstructed() const { return maybeConstructed; } 55 56 56 57 virtual Initializer *clone() const override = 0; 57 virtual void accept( Visitor &v ) override = 0; 58 virtual void accept( Visitor & v ) override = 0; 59 virtual void accept( Visitor & v ) const override = 0; 58 60 virtual Initializer *acceptMutator( Mutator &m ) override = 0; 59 61 virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0; … … 76 78 77 79 virtual SingleInit *clone() const override { return new SingleInit( *this); } 78 virtual void accept( Visitor &v ) override { v.visit( this ); } 80 virtual void accept( Visitor & v ) override { v.visit( this ); } 81 virtual void accept( Visitor & v ) const override { v.visit( this ); } 79 82 virtual Initializer *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 80 83 virtual void print( std::ostream &os, Indenter indent = {} ) const override; … … 104 107 105 108 virtual ListInit *clone() const override { return new ListInit( *this ); } 106 virtual void accept( Visitor &v ) override { v.visit( this ); } 109 virtual void accept( Visitor & v ) override { v.visit( this ); } 110 virtual void accept( Visitor & v ) const override { v.visit( this ); } 107 111 virtual Initializer *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 108 112 virtual void print( std::ostream &os, Indenter indent = {} ) const override; … … 133 137 134 138 ConstructorInit *clone() const override { return new ConstructorInit( *this ); } 135 virtual void accept( Visitor &v ) override { v.visit( this ); } 139 virtual void accept( Visitor & v ) override { v.visit( this ); } 140 virtual void accept( Visitor & v ) const override { v.visit( this ); } 136 141 virtual Initializer *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 137 142 virtual void print( std::ostream &os, Indenter indent = {} ) const override; -
src/SynTree/Label.h
r7951100 rb067d9b 35 35 operator std::string() const { return name; } 36 36 bool empty() { return name.empty(); } 37 private: 37 38 38 std::string name; 39 39 Statement * labelled; -
src/SynTree/Mutator.h
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jul 24 16:31:00 201713 // Update Count : 1 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:37:46 2019 13 // Update Count : 17 14 14 // 15 15 #pragma once … … 52 52 virtual Statement * mutate( FinallyStmt * catchStmt ) = 0; 53 53 virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0; 54 virtual Statement* mutate( WithStmt * withStmt ) = 0;54 virtual Declaration * mutate( WithStmt * withStmt ) = 0; 55 55 virtual NullStmt * mutate( NullStmt * nullStmt ) = 0; 56 56 virtual Statement * mutate( DeclStmt * declStmt ) = 0; … … 74 74 virtual Expression * mutate( OffsetofExpr * offsetofExpr ) = 0; 75 75 virtual Expression * mutate( OffsetPackExpr * offsetPackExpr ) = 0; 76 virtual Expression * mutate( AttrExpr * attrExpr ) = 0;77 76 virtual Expression * mutate( LogicalExpr * logicalExpr ) = 0; 78 77 virtual Expression * mutate( ConditionalExpr * conditionalExpr ) = 0; … … 93 92 virtual Expression * mutate( InitExpr * initExpr ) = 0; 94 93 virtual Expression * mutate( DeletedExpr * delExpr ) = 0; 94 virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0; 95 95 virtual Expression * mutate( GenericExpr * genExpr ) = 0; 96 96 … … 100 100 virtual Type * mutate( ArrayType * arrayType ) = 0; 101 101 virtual Type * mutate( ReferenceType * refType ) = 0; 102 virtual Type * mutate( QualifiedType * qualType ) = 0; 102 103 virtual Type * mutate( FunctionType * functionType ) = 0; 103 104 virtual Type * mutate( StructInstType * aggregateUseType ) = 0; … … 112 113 virtual Type * mutate( ZeroType * zeroType ) = 0; 113 114 virtual Type * mutate( OneType * oneType ) = 0; 115 virtual Type * mutate( GlobalScopeType * globalType ) = 0; 114 116 115 117 virtual Designation * mutate( Designation * designation ) = 0 ; … … 117 119 virtual Initializer * mutate( ListInit * listInit ) = 0 ; 118 120 virtual Initializer * mutate( ConstructorInit * ctorInit ) = 0 ; 119 120 virtual Subrange * mutate( Subrange * subrange ) = 0;121 121 122 122 virtual Constant * mutate( Constant * constant ) = 0; -
src/SynTree/ObjectDecl.cc
r7951100 rb067d9b 66 66 67 67 if ( ! attributes.empty() ) { 68 os << std::endl << indent << "... with attributes: " << std::endl;68 os << std::endl << indent << "... with attributes:" << std::endl; 69 69 printAll( attributes, os, indent+1 ); 70 70 } -
src/SynTree/ReferenceToType.cc
r7951100 rb067d9b 76 76 bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; } 77 77 78 AggregateDecl * StructInstType::getAggr() { return baseStruct; }78 AggregateDecl * StructInstType::getAggr() const { return baseStruct; } 79 79 80 80 TypeSubstitution StructInstType::genericSubstitution() const { … … 93 93 else { 94 94 Type::print( os, indent ); 95 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";95 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body(); 96 96 if ( ! parameters.empty() ) { 97 97 os << endl << indent << "... with parameters" << endl; … … 119 119 bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; } 120 120 121 AggregateDecl * UnionInstType::getAggr() { return baseUnion; }121 AggregateDecl * UnionInstType::getAggr() const { return baseUnion; } 122 122 123 123 TypeSubstitution UnionInstType::genericSubstitution() const { … … 136 136 else { 137 137 Type::print( os, indent ); 138 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";138 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body(); 139 139 if ( ! parameters.empty() ) { 140 140 os << endl << indent << "... with parameters" << endl; … … 152 152 bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; } 153 153 154 AggregateDecl * EnumInstType::getAggr() const { return baseEnum; } 155 154 156 void EnumInstType::print( std::ostream &os, Indenter indent ) const { 155 157 using std::endl; … … 158 160 else { 159 161 Type::print( os, indent ); 160 os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body() << " ";162 os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body(); 161 163 } // if 162 164 } … … 203 205 204 206 Type::print( os, indent ); 205 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";207 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type)"; 206 208 if ( ! parameters.empty() ) { 207 209 os << endl << indent << "... with parameters" << endl; -
src/SynTree/Statement.cc
r7951100 rb067d9b 493 493 494 494 495 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {}496 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {495 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {} 496 WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { 497 497 cloneAll( other.exprs, exprs ); 498 498 } -
src/SynTree/Statement.h
r7951100 rb067d9b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Mar 8 14:53:02 201813 // Update Count : 7812 // Last Modified On : Tue Mar 12 09:01:53 2019 13 // Update Count : 83 14 14 // 15 15 … … 19 19 #include <list> // for list 20 20 #include <memory> // for allocator 21 #include <vector> // for vector21 #include <vector> // for vector 22 22 23 23 #include "BaseSyntaxNode.h" // for BaseSyntaxNode … … 43 43 const std::list<Label> & get_labels() const { return labels; } 44 44 45 virtual Statement *clone() const override = 0; 46 virtual void accept( Visitor &v ) override = 0; 47 virtual Statement *acceptMutator( Mutator &m ) override = 0; 48 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 45 virtual Statement * clone() const override = 0; 46 virtual void accept( Visitor & v ) override = 0; 47 virtual void accept( Visitor & v ) const override = 0; 48 virtual Statement * acceptMutator( Mutator & m ) override = 0; 49 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 49 50 }; 50 51 … … 55 56 CompoundStmt(); 56 57 CompoundStmt( std::list<Statement *> stmts ); 57 CompoundStmt( const CompoundStmt & other );58 CompoundStmt( const CompoundStmt & other ); 58 59 virtual ~CompoundStmt(); 59 60 … … 62 63 void push_front( Statement * stmt ) { kids.push_front( stmt ); } 63 64 64 virtual CompoundStmt *clone() const override { return new CompoundStmt( *this ); } 65 virtual void accept( Visitor &v ) override { v.visit( this ); } 66 virtual CompoundStmt *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 67 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 65 virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); } 66 virtual void accept( Visitor & v ) override { v.visit( this ); } 67 virtual void accept( Visitor & v ) const override { v.visit( this ); } 68 virtual CompoundStmt * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 69 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 68 70 }; 69 71 … … 72 74 NullStmt( const std::list<Label> & labels = {} ); 73 75 74 virtual NullStmt *clone() const override { return new NullStmt( *this ); } 75 virtual void accept( Visitor &v ) override { v.visit( this ); } 76 virtual NullStmt *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 77 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 76 virtual NullStmt * clone() const override { return new NullStmt( *this ); } 77 virtual void accept( Visitor & v ) override { v.visit( this ); } 78 virtual void accept( Visitor & v ) const override { v.visit( this ); } 79 virtual NullStmt * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 80 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 78 81 }; 79 82 80 83 class ExprStmt : public Statement { 81 84 public: 82 Expression * expr;83 84 ExprStmt( Expression * expr );85 ExprStmt( const ExprStmt & other );85 Expression * expr; 86 87 ExprStmt( Expression * expr ); 88 ExprStmt( const ExprStmt & other ); 86 89 virtual ~ExprStmt(); 87 90 88 Expression *get_expr() { return expr; } 89 void set_expr( Expression *newValue ) { expr = newValue; } 90 91 virtual ExprStmt *clone() const override { return new ExprStmt( *this ); } 92 virtual void accept( Visitor &v ) override { v.visit( this ); } 93 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 94 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 91 Expression * get_expr() { return expr; } 92 void set_expr( Expression * newValue ) { expr = newValue; } 93 94 virtual ExprStmt * clone() const override { return new ExprStmt( *this ); } 95 virtual void accept( Visitor & v ) override { v.visit( this ); } 96 virtual void accept( Visitor & v ) const override { v.visit( this ); } 97 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 98 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 95 99 }; 96 100 … … 98 102 public: 99 103 bool voltile; 100 Expression * instruction;104 Expression * instruction; 101 105 std::list<Expression *> output, input; 102 106 std::list<ConstantExpr *> clobber; 103 107 std::list<Label> gotolabels; 104 108 105 AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );106 AsmStmt( const AsmStmt & other );109 AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); 110 AsmStmt( const AsmStmt & other ); 107 111 virtual ~AsmStmt(); 108 112 … … 114 118 void set_output( const std::list<Expression *> & newValue ) { output = newValue; } 115 119 std::list<Expression *> & get_input() { return input; } 116 void set_input( const std::list<Expression *> & newValue ) { input = newValue; }120 void set_input( const std::list<Expression *> & newValue ) { input = newValue; } 117 121 std::list<ConstantExpr *> & get_clobber() { return clobber; } 118 void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; }122 void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; } 119 123 std::list<Label> & get_gotolabels() { return gotolabels; } 120 void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; } 121 122 virtual AsmStmt * clone() const { return new AsmStmt( *this ); } 123 virtual void accept( Visitor & v ) { v.visit( this ); } 124 virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); } 125 virtual void print( std::ostream & os, Indenter indent = {} ) const; 124 void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; } 125 126 virtual AsmStmt * clone() const override { return new AsmStmt( *this ); } 127 virtual void accept( Visitor & v ) override { v.visit( this ); } 128 virtual void accept( Visitor & v ) const override { v.visit( this ); } 129 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 130 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 126 131 }; 127 132 … … 133 138 virtual ~DirectiveStmt(){} 134 139 135 virtual DirectiveStmt * clone() const { return new DirectiveStmt( *this ); } 136 virtual void accept( Visitor & v ) { v.visit( this ); } 137 virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); } 138 virtual void print( std::ostream & os, Indenter indent = {} ) const; 140 virtual DirectiveStmt * clone() const override { return new DirectiveStmt( *this ); } 141 virtual void accept( Visitor & v ) override { v.visit( this ); } 142 virtual void accept( Visitor & v ) const override { v.visit( this ); } 143 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 144 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 139 145 }; 140 146 141 147 class IfStmt : public Statement { 142 148 public: 143 Expression * condition;144 Statement * thenPart;145 Statement * elsePart;149 Expression * condition; 150 Statement * thenPart; 151 Statement * elsePart; 146 152 std::list<Statement *> initialization; 147 153 148 IfStmt( Expression * condition, Statement *thenPart, Statement *elsePart,154 IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, 149 155 std::list<Statement *> initialization = std::list<Statement *>() ); 150 IfStmt( const IfStmt & other );156 IfStmt( const IfStmt & other ); 151 157 virtual ~IfStmt(); 152 158 153 std::list<Statement *> &get_initialization() { return initialization; } 154 Expression *get_condition() { return condition; } 155 void set_condition( Expression *newValue ) { condition = newValue; } 156 Statement *get_thenPart() { return thenPart; } 157 void set_thenPart( Statement *newValue ) { thenPart = newValue; } 158 Statement *get_elsePart() { return elsePart; } 159 void set_elsePart( Statement *newValue ) { elsePart = newValue; } 160 161 virtual IfStmt *clone() const override { return new IfStmt( *this ); } 162 virtual void accept( Visitor &v ) override { v.visit( this ); } 163 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 164 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 159 std::list<Statement *> & get_initialization() { return initialization; } 160 Expression * get_condition() { return condition; } 161 void set_condition( Expression * newValue ) { condition = newValue; } 162 Statement * get_thenPart() { return thenPart; } 163 void set_thenPart( Statement * newValue ) { thenPart = newValue; } 164 Statement * get_elsePart() { return elsePart; } 165 void set_elsePart( Statement * newValue ) { elsePart = newValue; } 166 167 virtual IfStmt * clone() const override { return new IfStmt( *this ); } 168 virtual void accept( Visitor & v ) override { v.visit( this ); } 169 virtual void accept( Visitor & v ) const override { v.visit( this ); } 170 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 171 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 165 172 }; 166 173 … … 170 177 std::list<Statement *> statements; 171 178 172 SwitchStmt( Expression * condition, const std::list<Statement *> &statements );173 SwitchStmt( const SwitchStmt & other );179 SwitchStmt( Expression * condition, const std::list<Statement *> & statements ); 180 SwitchStmt( const SwitchStmt & other ); 174 181 virtual ~SwitchStmt(); 175 182 176 Expression * get_condition() { return condition; }177 void set_condition( Expression * newValue ) { condition = newValue; }183 Expression * get_condition() { return condition; } 184 void set_condition( Expression * newValue ) { condition = newValue; } 178 185 179 186 std::list<Statement *> & get_statements() { return statements; } 180 187 181 virtual void accept( Visitor &v ) override { v.visit( this ); } 182 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 183 184 virtual SwitchStmt *clone() const override { return new SwitchStmt( *this ); } 185 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 188 virtual void accept( Visitor & v ) override { v.visit( this ); } 189 virtual void accept( Visitor & v ) const override { v.visit( this ); } 190 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 191 192 virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); } 193 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 186 194 187 195 }; … … 192 200 std::list<Statement *> stmts; 193 201 194 CaseStmt( Expression * conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);195 CaseStmt( const CaseStmt & other );202 CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException); 203 CaseStmt( const CaseStmt & other ); 196 204 virtual ~CaseStmt(); 197 205 … … 201 209 void set_default(bool b) { _isDefault = b; } 202 210 203 Expression * &get_condition() { return condition; } 204 void set_condition( Expression *newValue ) { condition = newValue; } 205 206 std::list<Statement *> &get_statements() { return stmts; } 207 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } 208 209 virtual void accept( Visitor &v ) override { v.visit( this ); } 210 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 211 212 virtual CaseStmt *clone() const override { return new CaseStmt( *this ); } 213 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 211 Expression * & get_condition() { return condition; } 212 void set_condition( Expression * newValue ) { condition = newValue; } 213 214 std::list<Statement *> & get_statements() { return stmts; } 215 void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; } 216 217 virtual void accept( Visitor & v ) override { v.visit( this ); } 218 virtual void accept( Visitor & v ) const override { v.visit( this ); } 219 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 220 221 virtual CaseStmt * clone() const override { return new CaseStmt( *this ); } 222 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 214 223 private: 215 224 bool _isDefault; … … 218 227 class WhileStmt : public Statement { 219 228 public: 220 Expression * condition;221 Statement * body;229 Expression * condition; 230 Statement * body; 222 231 std::list<Statement *> initialization; 223 232 bool isDoWhile; 224 233 225 WhileStmt( Expression *condition, 226 Statement *body, std::list<Statement *> & initialization, bool isDoWhile = false ); 227 WhileStmt( const WhileStmt &other ); 234 WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false ); 235 WhileStmt( const WhileStmt & other ); 228 236 virtual ~WhileStmt(); 229 237 230 Expression * get_condition() { return condition; }231 void set_condition( Expression * newValue ) { condition = newValue; }232 Statement * get_body() { return body; }233 void set_body( Statement * newValue ) { body = newValue; }238 Expression * get_condition() { return condition; } 239 void set_condition( Expression * newValue ) { condition = newValue; } 240 Statement * get_body() { return body; } 241 void set_body( Statement * newValue ) { body = newValue; } 234 242 bool get_isDoWhile() { return isDoWhile; } 235 243 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 236 244 237 virtual WhileStmt *clone() const override { return new WhileStmt( *this ); } 238 virtual void accept( Visitor &v ) override { v.visit( this ); } 239 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 240 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 245 virtual WhileStmt * clone() const override { return new WhileStmt( *this ); } 246 virtual void accept( Visitor & v ) override { v.visit( this ); } 247 virtual void accept( Visitor & v ) const override { v.visit( this ); } 248 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 249 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 241 250 }; 242 251 … … 244 253 public: 245 254 std::list<Statement *> initialization; 246 Expression *condition; 247 Expression *increment; 248 Statement *body; 249 250 ForStmt( std::list<Statement *> initialization, 251 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 252 ForStmt( const ForStmt &other ); 255 Expression * condition; 256 Expression * increment; 257 Statement * body; 258 259 ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0 ); 260 ForStmt( const ForStmt & other ); 253 261 virtual ~ForStmt(); 254 262 255 std::list<Statement *> &get_initialization() { return initialization; } 256 Expression *get_condition() { return condition; } 257 void set_condition( Expression *newValue ) { condition = newValue; } 258 Expression *get_increment() { return increment; } 259 void set_increment( Expression *newValue ) { increment = newValue; } 260 Statement *get_body() { return body; } 261 void set_body( Statement *newValue ) { body = newValue; } 262 263 virtual ForStmt *clone() const override { return new ForStmt( *this ); } 264 virtual void accept( Visitor &v ) override { v.visit( this ); } 265 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 266 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 263 std::list<Statement *> & get_initialization() { return initialization; } 264 Expression * get_condition() { return condition; } 265 void set_condition( Expression * newValue ) { condition = newValue; } 266 Expression * get_increment() { return increment; } 267 void set_increment( Expression * newValue ) { increment = newValue; } 268 Statement * get_body() { return body; } 269 void set_body( Statement * newValue ) { body = newValue; } 270 271 virtual ForStmt * clone() const override { return new ForStmt( *this ); } 272 virtual void accept( Visitor & v ) override { v.visit( this ); } 273 virtual void accept( Visitor & v ) const override { v.visit( this ); } 274 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 275 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 267 276 }; 268 277 … … 274 283 const Label originalTarget; 275 284 Label target; 276 Expression * computedTarget;285 Expression * computedTarget; 277 286 Type type; 278 287 279 288 BranchStmt( Label target, Type ) throw (SemanticErrorException); 280 BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);289 BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException); 281 290 282 291 Label get_originalTarget() { return originalTarget; } … … 284 293 void set_target( Label newValue ) { target = newValue; } 285 294 286 Expression * get_computedTarget() { return computedTarget; }295 Expression * get_computedTarget() { return computedTarget; } 287 296 void set_target( Expression * newValue ) { computedTarget = newValue; } 288 297 289 298 Type get_type() { return type; } 290 const char *get_typename() { return brType[ type ]; } 291 292 virtual BranchStmt *clone() const override { return new BranchStmt( *this ); } 293 virtual void accept( Visitor &v ) override { v.visit( this ); } 294 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 295 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 299 const char * get_typename() { return brType[ type ]; } 300 301 virtual BranchStmt * clone() const override { return new BranchStmt( *this ); } 302 virtual void accept( Visitor & v ) override { v.visit( this ); } 303 virtual void accept( Visitor & v ) const override { v.visit( this ); } 304 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 305 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 296 306 private: 297 static const char * brType[];307 static const char * brType[]; 298 308 }; 299 309 300 310 class ReturnStmt : public Statement { 301 311 public: 302 Expression * expr;303 304 ReturnStmt( Expression * expr );305 ReturnStmt( const ReturnStmt & other );312 Expression * expr; 313 314 ReturnStmt( Expression * expr ); 315 ReturnStmt( const ReturnStmt & other ); 306 316 virtual ~ReturnStmt(); 307 317 308 Expression *get_expr() { return expr; } 309 void set_expr( Expression *newValue ) { expr = newValue; } 310 311 virtual ReturnStmt *clone() const override { return new ReturnStmt( *this ); } 312 virtual void accept( Visitor &v ) override { v.visit( this ); } 313 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 314 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 318 Expression * get_expr() { return expr; } 319 void set_expr( Expression * newValue ) { expr = newValue; } 320 321 virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); } 322 virtual void accept( Visitor & v ) override { v.visit( this ); } 323 virtual void accept( Visitor & v ) const override { v.visit( this ); } 324 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 325 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 315 326 }; 316 327 … … 324 335 325 336 ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr ); 326 ThrowStmt( const ThrowStmt & other );337 ThrowStmt( const ThrowStmt & other ); 327 338 virtual ~ThrowStmt(); 328 339 … … 333 344 void set_target( Expression * newTarget ) { target = newTarget; } 334 345 335 virtual ThrowStmt *clone() const override { return new ThrowStmt( *this ); } 336 virtual void accept( Visitor &v ) override { v.visit( this ); } 337 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 338 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 346 virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); } 347 virtual void accept( Visitor & v ) override { v.visit( this ); } 348 virtual void accept( Visitor & v ) const override { v.visit( this ); } 349 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 350 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 339 351 }; 340 352 … … 345 357 FinallyStmt * finallyBlock; 346 358 347 TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );348 TryStmt( const TryStmt & other );359 TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0 ); 360 TryStmt( const TryStmt & other ); 349 361 virtual ~TryStmt(); 350 362 351 CompoundStmt * get_block() const { return block; }352 void set_block( CompoundStmt * newValue ) { block = newValue; }363 CompoundStmt * get_block() const { return block; } 364 void set_block( CompoundStmt * newValue ) { block = newValue; } 353 365 std::list<CatchStmt *>& get_catchers() { return handlers; } 354 366 355 FinallyStmt *get_finally() const { return finallyBlock; } 356 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } 357 358 virtual TryStmt *clone() const override { return new TryStmt( *this ); } 359 virtual void accept( Visitor &v ) override { v.visit( this ); } 360 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 361 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 367 FinallyStmt * get_finally() const { return finallyBlock; } 368 void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; } 369 370 virtual TryStmt * clone() const override { return new TryStmt( *this ); } 371 virtual void accept( Visitor & v ) override { v.visit( this ); } 372 virtual void accept( Visitor & v ) const override { v.visit( this ); } 373 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 374 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 362 375 }; 363 376 … … 367 380 368 381 const Kind kind; 369 Declaration * decl;370 Expression * cond;371 Statement * body;372 373 CatchStmt( Kind kind, Declaration * decl,374 Expression * cond, Statement *body );375 CatchStmt( const CatchStmt & other );382 Declaration * decl; 383 Expression * cond; 384 Statement * body; 385 386 CatchStmt( Kind kind, Declaration * decl, 387 Expression * cond, Statement * body ); 388 CatchStmt( const CatchStmt & other ); 376 389 virtual ~CatchStmt(); 377 390 378 391 Kind get_kind() { return kind; } 379 Declaration *get_decl() { return decl; } 380 void set_decl( Declaration *newValue ) { decl = newValue; } 381 Expression *get_cond() { return cond; } 382 void set_cond( Expression *newCond ) { cond = newCond; } 383 Statement *get_body() { return body; } 384 void set_body( Statement *newValue ) { body = newValue; } 385 386 virtual CatchStmt *clone() const override { return new CatchStmt( *this ); } 387 virtual void accept( Visitor &v ) override { v.visit( this ); } 388 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 389 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 392 Declaration * get_decl() { return decl; } 393 void set_decl( Declaration * newValue ) { decl = newValue; } 394 Expression * get_cond() { return cond; } 395 void set_cond( Expression * newCond ) { cond = newCond; } 396 Statement * get_body() { return body; } 397 void set_body( Statement * newValue ) { body = newValue; } 398 399 virtual CatchStmt * clone() const override { return new CatchStmt( *this ); } 400 virtual void accept( Visitor & v ) override { v.visit( this ); } 401 virtual void accept( Visitor & v ) const override { v.visit( this ); } 402 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 403 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 390 404 }; 391 405 392 406 class FinallyStmt : public Statement { 393 407 public: 394 CompoundStmt * block;395 396 FinallyStmt( CompoundStmt * block );397 FinallyStmt( const FinallyStmt & other );408 CompoundStmt * block; 409 410 FinallyStmt( CompoundStmt * block ); 411 FinallyStmt( const FinallyStmt & other ); 398 412 virtual ~FinallyStmt(); 399 413 400 CompoundStmt *get_block() const { return block; } 401 void set_block( CompoundStmt *newValue ) { block = newValue; } 402 403 virtual FinallyStmt *clone() const override { return new FinallyStmt( *this ); } 404 virtual void accept( Visitor &v ) override { v.visit( this ); } 405 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 406 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 414 CompoundStmt * get_block() const { return block; } 415 void set_block( CompoundStmt * newValue ) { block = newValue; } 416 417 virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); } 418 virtual void accept( Visitor & v ) override { v.visit( this ); } 419 virtual void accept( Visitor & v ) const override { v.visit( this ); } 420 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 421 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 407 422 }; 408 423 … … 438 453 } orelse; 439 454 440 virtual WaitForStmt *clone() const override { return new WaitForStmt( *this ); } 441 virtual void accept( Visitor &v ) override { v.visit( this ); } 442 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 443 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 444 445 }; 446 447 class WithStmt : public Statement { 448 public: 449 std::list< Expression * > exprs; 450 Statement * stmt; 451 452 WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 453 WithStmt( const WithStmt & other ); 454 virtual ~WithStmt(); 455 456 virtual WithStmt * clone() const override { return new WithStmt( *this ); } 457 virtual void accept( Visitor & v ) override { v.visit( this ); } 458 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 459 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 460 }; 455 virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); } 456 virtual void accept( Visitor & v ) override { v.visit( this ); } 457 virtual void accept( Visitor & v ) const override { v.visit( this ); } 458 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 459 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 460 461 }; 462 463 // class WithStmt : public Statement { 464 // public: 465 // std::list< Expression * > exprs; 466 // Statement * stmt; 467 468 // WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 469 // WithStmt( const WithStmt & other ); 470 // virtual ~WithStmt(); 471 472 // virtual WithStmt * clone() const override { return new WithStmt( *this ); } 473 // virtual void accept( Visitor & v ) override { v.visit( this ); } 474 // virtual void accept( Visitor & v ) const override { v.visit( this ); } 475 // virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 476 // virtual void print( std::ostream & os, Indenter indent = {} ) const override; 477 // }; 461 478 462 479 … … 464 481 class DeclStmt : public Statement { 465 482 public: 466 Declaration * decl;467 468 DeclStmt( Declaration * decl );469 DeclStmt( const DeclStmt & other );483 Declaration * decl; 484 485 DeclStmt( Declaration * decl ); 486 DeclStmt( const DeclStmt & other ); 470 487 virtual ~DeclStmt(); 471 488 472 Declaration * get_decl() const { return decl; }473 void set_decl( Declaration * newValue ) { decl = newValue; }474 475 virtual DeclStmt * clone() const override { return new DeclStmt( *this ); }476 virtual void accept( Visitor & v ) override { v.visit( this ); }477 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }478 virtual void print( std::ostream &os, Indenter indent = {} ) const override;479 };480 481 482 /// represents an implicit application of a constructor or destructor. Qualifiers are replaced 483 /// immediately before and after the call so that qualified objects can be constructed484 /// with the same functions as unqualified objects.489 Declaration * get_decl() const { return decl; } 490 void set_decl( Declaration * newValue ) { decl = newValue; } 491 492 virtual DeclStmt * clone() const override { return new DeclStmt( *this ); } 493 virtual void accept( Visitor & v ) override { v.visit( this ); } 494 virtual void accept( Visitor & v ) const override { v.visit( this ); } 495 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 496 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 497 }; 498 499 500 /// represents an implicit application of a constructor or destructor. Qualifiers are replaced immediately before and 501 /// after the call so that qualified objects can be constructed with the same functions as unqualified objects. 485 502 class ImplicitCtorDtorStmt : public Statement { 486 503 public: … … 492 509 virtual ~ImplicitCtorDtorStmt(); 493 510 494 Statement * get_callStmt() const { return callStmt; }511 Statement * get_callStmt() const { return callStmt; } 495 512 void set_callStmt( Statement * newValue ) { callStmt = newValue; } 496 513 497 virtual ImplicitCtorDtorStmt *clone() const override { return new ImplicitCtorDtorStmt( *this ); } 498 virtual void accept( Visitor &v ) override { v.visit( this ); } 499 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 500 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 514 virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); } 515 virtual void accept( Visitor & v ) override { v.visit( this ); } 516 virtual void accept( Visitor & v ) const override { v.visit( this ); } 517 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 518 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 501 519 }; 502 520 -
src/SynTree/SynTree.h
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jul 24 16:54:00 201713 // Update Count : 1 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:37:45 2019 13 // Update Count : 12 14 14 // 15 15 … … 34 34 class NamedTypeDecl; 35 35 class TypeDecl; 36 class FtypeDecl;37 class DtypeDecl;38 36 class TypedefDecl; 39 37 class AsmDecl; … … 81 79 class OffsetofExpr; 82 80 class OffsetPackExpr; 83 class AttrExpr;84 81 class LogicalExpr; 85 82 class ConditionalExpr; … … 90 87 class ConstructorExpr; 91 88 class CompoundLiteralExpr; 92 class UntypedValofExpr;93 89 class RangeExpr; 94 90 class UntypedTupleExpr; … … 101 97 class InitExpr; 102 98 class DeletedExpr; 99 class DefaultArgExpr; 103 100 class GenericExpr; 104 101 … … 109 106 class ArrayType; 110 107 class ReferenceType; 108 class QualifiedType; 111 109 class FunctionType; 112 110 class ReferenceToType; … … 122 120 class ZeroType; 123 121 class OneType; 122 class GlobalScopeType; 124 123 125 124 class Designation; … … 128 127 class ListInit; 129 128 class ConstructorInit; 130 131 class Subrange;132 129 133 130 //template <class T> // emulate a union with templates? -
src/SynTree/TupleExpr.cc
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Mar 17 09:42:29 201713 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 14 14:34:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 57 57 } 58 58 59 bool TupleExpr::get_lvalue() const { 60 return false; 61 } 62 59 63 void TupleExpr::print( std::ostream &os, Indenter indent ) const { 60 64 os << "Tuple:" << std::endl; … … 67 71 assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); 68 72 set_result( (*std::next( type->get_types().begin(), index ))->clone() ); 69 // like MemberExpr, TupleIndexExpr is always an lvalue70 get_result()->set_lvalue( true );71 73 } 72 74 … … 76 78 TupleIndexExpr::~TupleIndexExpr() { 77 79 delete tuple; 80 } 81 82 bool TupleIndexExpr::get_lvalue() const { 83 return tuple->get_lvalue(); 78 84 } 79 85 … … 105 111 } 106 112 113 TupleAssignExpr::TupleAssignExpr( 114 StmtExpr * s ) 115 : Expression(), stmtExpr(s) { 116 } 117 118 107 119 TupleAssignExpr::~TupleAssignExpr() { 108 120 delete stmtExpr; -
src/SynTree/Type.cc
r7951100 rb067d9b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 25 15:16:32 201713 // Update Count : 3812 // Last Modified On : Sun Aug 4 21:05:07 2019 13 // Update Count : 45 14 14 // 15 15 #include "Type.h" … … 24 24 using namespace std; 25 25 26 const char * BasicType::typeNames[] = {26 const char * BasicType::typeNames[] = { 27 27 "_Bool", 28 28 "char", … … 37 37 "signed long long int", 38 38 "unsigned long long int", 39 "float",40 "double",41 "long double",42 "float _Complex",43 "double _Complex",44 "long double _Complex",45 "float _Imaginary",46 "double _Imaginary",47 "long double _Imaginary",48 39 "__int128", 49 40 "unsigned __int128", 41 "_Float16", 42 "_Float16 _Complex", 43 "_Float32", 44 "_Float32 _Complex", 45 "float", 46 "float _Complex", 47 //"float _Imaginary", 48 "_Float32x", 49 "_Float32x _Complex", 50 "_Float64", 51 "_Float64 _Complex", 52 "double", 53 "double _Complex", 54 //"double _Imaginary", 55 "_Float64x", 56 "_Float64x _Complex", 50 57 "__float80", 51 "__float128" 58 "_Float128", 59 "_Float128 _Complex", 60 "__float128", 61 "long double", 62 "long double _Complex", 63 //"long double _Imaginary", 64 "_Float128x", 65 "_Float128x _Complex", 52 66 }; 53 67 static_assert( 54 sizeof(BasicType::typeNames) /sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,68 sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES, 55 69 "Each basic type name should have a corresponding kind enum value" 56 70 ); … … 69 83 70 84 // These must remain in the same order as the corresponding bit fields. 71 const char * Type::FuncSpecifiersNames[] = { "inline", " fortran", "_Noreturn" };85 const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" }; 72 86 const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; 73 const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", " lvalue", "mutex", "_Atomic" };87 const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" }; 74 88 75 89 Type * Type::stripDeclarator() { … … 86 100 } 87 101 102 const Type * Type::stripReferences() const { 103 const Type * type; 104 const ReferenceType * ref; 105 for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base ); 106 return type; 107 } 108 88 109 int Type::referenceDepth() const { return 0; } 89 110 90 111 TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } 91 112 92 void Type::print( std::ostream & os, Indenter indent ) const {113 void Type::print( std::ostream & os, Indenter indent ) const { 93 114 if ( ! forall.empty() ) { 94 115 os << "forall" << std::endl; … … 105 126 } 106 127 128 129 QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) { 130 } 131 132 QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) { 133 } 134 135 QualifiedType::~QualifiedType() { 136 delete parent; 137 delete child; 138 } 139 140 void QualifiedType::print( std::ostream & os, Indenter indent ) const { 141 os << "Qualified Type:" << endl; 142 os << indent+1; 143 parent->print( os, indent+1 ); 144 os << endl << indent+1; 145 child->print( os, indent+1 ); 146 os << endl; 147 Type::print( os, indent+1 ); 148 } 149 150 GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {} 151 152 void GlobalScopeType::print( std::ostream & os, Indenter ) const { 153 os << "Global Scope Type" << endl; 154 } 155 156 107 157 // Empty Variable declarations: 108 158 const Type::FuncSpecifiers noFuncSpecifiers; -
src/SynTree/Type.h
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Sep 25 14:14:01 201713 // Update Count : 1 5411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Sep 4 09:58:00 2019 13 // Update Count : 170 14 14 // 15 15 … … 102 102 }; // StorageClasses 103 103 104 enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6};104 enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Mutex = 1 << 3, Atomic = 1 << 4, NumTypeQualifier = 5 }; 105 105 static const char * QualifiersNames[]; 106 106 union Qualifiers { 107 enum { Mask = ~ (Restrict | Lvalue)};107 enum { Mask = ~Restrict }; 108 108 unsigned int val; 109 109 struct { … … 111 111 bool is_restrict : 1; 112 112 bool is_volatile : 1; 113 bool is_lvalue : 1;114 113 bool is_mutex : 1; 115 114 bool is_atomic : 1; … … 131 130 bool operator>( Qualifiers other ) const { return *this != other && *this >= other; } 132 131 BFCommon( Qualifiers, NumTypeQualifier ) 132 133 Qualifiers unify( Qualifiers const & other ) const { 134 int or_flags = Mask & (val | other.val); 135 int and_flags = val & other.val; 136 return Qualifiers( or_flags | and_flags ); 137 } 133 138 }; // Qualifiers 134 139 … … 144 149 145 150 Qualifiers & get_qualifiers() { return tq; } 146 bool get_const() { return tq.is_const; } 147 bool get_volatile() { return tq.is_volatile; } 148 bool get_restrict() { return tq.is_restrict; } 149 bool get_lvalue() { return tq.is_lvalue; } 150 bool get_mutex() { return tq.is_mutex; } 151 bool get_atomic() { return tq.is_atomic; } 151 bool get_const() const { return tq.is_const; } 152 bool get_volatile() const { return tq.is_volatile; } 153 bool get_restrict() const { return tq.is_restrict; } 154 bool get_mutex() const { return tq.is_mutex; } 155 bool get_atomic() const { return tq.is_atomic; } 152 156 void set_const( bool newValue ) { tq.is_const = newValue; } 153 157 void set_volatile( bool newValue ) { tq.is_volatile = newValue; } 154 158 void set_restrict( bool newValue ) { tq.is_restrict = newValue; } 155 void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; }156 159 void set_mutex( bool newValue ) { tq.is_mutex = newValue; } 157 160 void set_atomic( bool newValue ) { tq.is_atomic = newValue; } … … 172 175 /// return type without outer references 173 176 Type * stripReferences(); 177 const Type * stripReferences() const; 174 178 175 179 /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types) … … 178 182 virtual bool isComplete() const { return true; } 179 183 180 virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }184 virtual AggregateDecl * getAggr() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } 181 185 182 186 virtual TypeSubstitution genericSubstitution() const; … … 184 188 virtual Type *clone() const = 0; 185 189 virtual void accept( Visitor & v ) = 0; 190 virtual void accept( Visitor & v ) const = 0; 186 191 virtual Type *acceptMutator( Mutator & m ) = 0; 187 192 virtual void print( std::ostream & os, Indenter indent = {} ) const; … … 201 206 virtual VoidType *clone() const override { return new VoidType( *this ); } 202 207 virtual void accept( Visitor & v ) override { v.visit( this ); } 208 virtual void accept( Visitor & v ) const override { v.visit( this ); } 203 209 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 204 210 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 207 213 class BasicType : public Type { 208 214 public: 215 // GENERATED START, DO NOT EDIT 216 // GENERATED BY BasicTypes-gen.cc 209 217 enum Kind { 210 218 Bool, … … 220 228 LongLongSignedInt, 221 229 LongLongUnsignedInt, 222 Float,223 Double,224 LongDouble,225 FloatComplex,226 DoubleComplex,227 LongDoubleComplex,228 FloatImaginary,229 DoubleImaginary,230 LongDoubleImaginary,231 230 SignedInt128, 232 231 UnsignedInt128, 233 Float80, 234 Float128, 232 uFloat16, 233 uFloat16Complex, 234 uFloat32, 235 uFloat32Complex, 236 Float, 237 FloatComplex, 238 uFloat32x, 239 uFloat32xComplex, 240 uFloat64, 241 uFloat64Complex, 242 Double, 243 DoubleComplex, 244 uFloat64x, 245 uFloat64xComplex, 246 uuFloat80, 247 uFloat128, 248 uFloat128Complex, 249 uuFloat128, 250 LongDouble, 251 LongDoubleComplex, 252 uFloat128x, 253 uFloat128xComplex, 235 254 NUMBER_OF_BASIC_TYPES 236 255 } kind; 256 // GENERATED END 237 257 238 258 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind … … 240 260 BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 241 261 242 Kind get_kind() { return kind; }262 Kind get_kind() const { return kind; } 243 263 void set_kind( Kind newValue ) { kind = newValue; } 244 264 245 265 virtual BasicType *clone() const override { return new BasicType( *this ); } 246 266 virtual void accept( Visitor & v ) override { v.visit( this ); } 267 virtual void accept( Visitor & v ) const override { v.visit( this ); } 247 268 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 248 269 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 280 301 virtual PointerType *clone() const override { return new PointerType( *this ); } 281 302 virtual void accept( Visitor & v ) override { v.visit( this ); } 303 virtual void accept( Visitor & v ) const override { v.visit( this ); } 282 304 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 283 305 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 311 333 virtual ArrayType *clone() const override { return new ArrayType( *this ); } 312 334 virtual void accept( Visitor & v ) override { v.visit( this ); } 335 virtual void accept( Visitor & v ) const override { v.visit( this ); } 336 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 337 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 338 }; 339 340 class QualifiedType : public Type { 341 public: 342 Type * parent; 343 Type * child; 344 345 QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ); 346 QualifiedType( const QualifiedType & tq ); 347 virtual ~QualifiedType(); 348 349 virtual QualifiedType *clone() const override { return new QualifiedType( *this ); } 350 virtual void accept( Visitor & v ) override { v.visit( this ); } 351 virtual void accept( Visitor & v ) const override { v.visit( this ); } 313 352 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 314 353 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 337 376 virtual ReferenceType *clone() const override { return new ReferenceType( *this ); } 338 377 virtual void accept( Visitor & v ) override { v.visit( this ); } 378 virtual void accept( Visitor & v ) const override { v.visit( this ); } 339 379 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 340 380 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 366 406 virtual FunctionType *clone() const override { return new FunctionType( *this ); } 367 407 virtual void accept( Visitor & v ) override { v.visit( this ); } 408 virtual void accept( Visitor & v ) const override { v.visit( this ); } 368 409 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 369 410 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 416 457 virtual bool isComplete() const override; 417 458 418 virtual AggregateDecl * getAggr() override;459 virtual AggregateDecl * getAggr() const override; 419 460 420 461 virtual TypeSubstitution genericSubstitution() const override; … … 426 467 virtual StructInstType *clone() const override { return new StructInstType( *this ); } 427 468 virtual void accept( Visitor & v ) override { v.visit( this ); } 469 virtual void accept( Visitor & v ) const override { v.visit( this ); } 428 470 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 429 471 … … 453 495 virtual bool isComplete() const override; 454 496 455 virtual AggregateDecl * getAggr() override;497 virtual AggregateDecl * getAggr() const override; 456 498 457 499 virtual TypeSubstitution genericSubstitution() const override; … … 463 505 virtual UnionInstType *clone() const override { return new UnionInstType( *this ); } 464 506 virtual void accept( Visitor & v ) override { v.visit( this ); } 507 virtual void accept( Visitor & v ) const override { v.visit( this ); } 465 508 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 466 509 … … 486 529 virtual bool isComplete() const override; 487 530 531 virtual AggregateDecl * getAggr() const override; 532 488 533 virtual EnumInstType *clone() const override { return new EnumInstType( *this ); } 489 534 virtual void accept( Visitor & v ) override { v.visit( this ); } 535 virtual void accept( Visitor & v ) const override { v.visit( this ); } 490 536 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 491 537 … … 511 557 virtual TraitInstType *clone() const override { return new TraitInstType( *this ); } 512 558 virtual void accept( Visitor & v ) override { v.visit( this ); } 559 virtual void accept( Visitor & v ) const override { v.visit( this ); } 513 560 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 514 561 private: … … 538 585 virtual TypeInstType *clone() const override { return new TypeInstType( *this ); } 539 586 virtual void accept( Visitor & v ) override { v.visit( this ); } 587 virtual void accept( Visitor & v ) const override { v.visit( this ); } 540 588 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 541 589 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 575 623 virtual TupleType *clone() const override { return new TupleType( *this ); } 576 624 virtual void accept( Visitor & v ) override { v.visit( this ); } 625 virtual void accept( Visitor & v ) const override { v.visit( this ); } 577 626 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 578 627 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 581 630 class TypeofType : public Type { 582 631 public: 583 Expression *expr; 584 585 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 632 Expression *expr; ///< expression to take the type of 633 bool is_basetypeof; ///< true iff is basetypeof type 634 635 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 636 TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof, 637 const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 586 638 TypeofType( const TypeofType& ); 587 639 virtual ~TypeofType(); … … 594 646 virtual TypeofType *clone() const override { return new TypeofType( *this ); } 595 647 virtual void accept( Visitor & v ) override { v.visit( this ); } 648 virtual void accept( Visitor & v ) const override { v.visit( this ); } 596 649 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 597 650 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 623 676 virtual AttrType *clone() const override { return new AttrType( *this ); } 624 677 virtual void accept( Visitor & v ) override { v.visit( this ); } 678 virtual void accept( Visitor & v ) const override { v.visit( this ); } 625 679 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 626 680 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 637 691 virtual VarArgsType *clone() const override { return new VarArgsType( *this ); } 638 692 virtual void accept( Visitor & v ) override { v.visit( this ); } 693 virtual void accept( Visitor & v ) const override { v.visit( this ); } 639 694 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 640 695 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 649 704 virtual ZeroType *clone() const override { return new ZeroType( *this ); } 650 705 virtual void accept( Visitor & v ) override { v.visit( this ); } 706 virtual void accept( Visitor & v ) const override { v.visit( this ); } 651 707 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 652 708 virtual void print( std::ostream & os, Indenter indent = {} ) const override; … … 661 717 virtual OneType *clone() const override { return new OneType( *this ); } 662 718 virtual void accept( Visitor & v ) override { v.visit( this ); } 719 virtual void accept( Visitor & v ) const override { v.visit( this ); } 720 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 721 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 722 }; 723 724 class GlobalScopeType : public Type { 725 public: 726 GlobalScopeType(); 727 728 virtual GlobalScopeType *clone() const override { return new GlobalScopeType( *this ); } 729 virtual void accept( Visitor & v ) override { v.visit( this ); } 730 virtual void accept( Visitor & v ) const override { v.visit( this ); } 663 731 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 664 732 virtual void print( std::ostream & os, Indenter indent = {} ) const override; -
src/SynTree/TypeSubstitution.cc
r7951100 rb067d9b 64 64 } 65 65 66 void TypeSubstitution::addVar( std::string formalExpr, Expression *actualExpr ) { 67 varEnv[ formalExpr ] = actualExpr; 68 } 69 66 70 void TypeSubstitution::remove( std::string formalType ) { 67 71 TypeEnvType::iterator i = typeEnv.find( formalType ); … … 108 112 namespace { 109 113 struct EnvTrimmer { 110 TypeSubstitution * env, * newEnv; 111 EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){} 114 const TypeSubstitution * env; 115 TypeSubstitution * newEnv; 116 EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){} 112 117 void previsit( TypeDecl * tyDecl ) { 113 118 // transfer known bindings for seen type variables … … 120 125 121 126 /// reduce environment to just the parts that are referenced in a given expression 122 TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, TypeSubstitution * env ) {127 TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, const TypeSubstitution * env ) { 123 128 if ( env ) { 124 129 TypeSubstitution * newEnv = new TypeSubstitution(); -
src/SynTree/TypeSubstitution.h
r7951100 rb067d9b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:52:24 201713 // Update Count : 312 // Last Modified On : Tue Apr 30 22:52:47 2019 13 // Update Count : 9 14 14 // 15 15 … … 19 19 #include <iosfwd> // for ostream 20 20 #include <list> // for list<>::iterator, _List_iterator 21 #include < map> // for _Rb_tree_iterator, map, map<>::val...22 #include < set> // for set21 #include <unordered_map> 22 #include <unordered_set> 23 23 #include <string> // for string, operator!= 24 24 #include <utility> // for pair … … 39 39 TypeSubstitution &operator=( const TypeSubstitution &other ); 40 40 41 template< typename SynTreeClass > int apply( SynTreeClass *&input ) ;42 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) ;41 template< typename SynTreeClass > int apply( SynTreeClass *&input ) const; 42 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const; 43 43 44 44 void add( std::string formalType, Type *actualType ); … … 48 48 bool empty() const; 49 49 50 void addVar( std::string formalExpr, Expression *actualExpr ); 51 50 52 template< typename FormalIterator, typename ActualIterator > 51 53 void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); … … 56 58 57 59 /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr 58 static TypeSubstitution * newFromExpr( Expression * expr, TypeSubstitution * env );60 static TypeSubstitution * newFromExpr( Expression * expr, const TypeSubstitution * env ); 59 61 60 62 void normalize(); … … 78 80 friend class PassVisitor; 79 81 80 typedef std:: map< std::string, Type* > TypeEnvType;81 typedef std:: map< std::string, Expression* > VarEnvType;82 typedef std::unordered_map< std::string, Type * > TypeEnvType; 83 typedef std::unordered_map< std::string, Expression * > VarEnvType; 82 84 TypeEnvType typeEnv; 83 85 VarEnvType varEnv; … … 89 91 auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); } 90 92 auto end() const -> decltype( typeEnv. end() ) { return typeEnv. end(); } 93 94 auto beginVar() -> decltype( varEnv.begin() ) { return varEnv.begin(); } 95 auto endVar() -> decltype( varEnv. end() ) { return varEnv. end(); } 96 auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); } 97 auto endVar() const -> decltype( varEnv. end() ) { return varEnv. end(); } 91 98 }; 92 99 … … 98 105 ActualIterator actualIt = actualBegin; 99 106 for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) { 100 if ( TypeDecl *formal = dynamic_cast< TypeDecl * >( *formalIt ) ) {101 if ( TypeExpr *actual = dynamic_cast< TypeExpr * >( *actualIt ) ) {107 if ( TypeDecl *formal = dynamic_cast< TypeDecl * >( *formalIt ) ) { 108 if ( TypeExpr *actual = dynamic_cast< TypeExpr * >( *actualIt ) ) { 102 109 if ( formal->get_name() != "" ) { 103 110 TypeEnvType::iterator i = typeEnv.find( formal->get_name() ); … … 130 137 // definitition must happen after PassVisitor is included so that WithGuards can be used 131 138 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> { 132 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}139 Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {} 133 140 134 141 Type * postmutate( TypeInstType * aggregateUseType ); … … 143 150 void premutate( UnionInstType * aggregateUseType ); 144 151 145 TypeSubstitution & sub;152 const TypeSubstitution & sub; 146 153 int subCount = 0; 147 154 bool freeOnly; 148 typedef std:: set< std::string > BoundVarsType;155 typedef std::unordered_set< std::string > BoundVarsType; 149 156 BoundVarsType boundVars; 150 157 }; 151 158 152 159 template< typename SynTreeClass > 153 int TypeSubstitution::apply( SynTreeClass *&input ) {160 int TypeSubstitution::apply( SynTreeClass *&input ) const { 154 161 assert( input ); 155 162 PassVisitor<Substituter> sub( *this, false ); … … 163 170 164 171 template< typename SynTreeClass > 165 int TypeSubstitution::applyFree( SynTreeClass *&input ) {172 int TypeSubstitution::applyFree( SynTreeClass *&input ) const { 166 173 assert( input ); 167 174 PassVisitor<Substituter> sub( *this, true ); -
src/SynTree/TypeofType.cc
r7951100 rb067d9b 23 23 class Attribute; 24 24 25 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), expr( expr ) { 26 } 25 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, 26 const std::list< Attribute * > & attributes ) 27 : Type( tq, attributes ), expr( expr ), is_basetypeof(false) {} 27 28 28 TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) { 29 } 29 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, bool is_basetypeof, 30 const std::list< Attribute * > & attributes ) 31 : Type( tq, attributes ), expr( expr ), is_basetypeof( is_basetypeof ) {} 32 33 TypeofType::TypeofType( const TypeofType &other ) 34 : Type( other ), expr( maybeClone( other.expr ) ), is_basetypeof( other.is_basetypeof ) {} 30 35 31 36 TypeofType::~TypeofType() { … … 35 40 void TypeofType::print( std::ostream &os, Indenter indent ) const { 36 41 Type::print( os, indent ); 42 if ( is_basetypeof ) { os << "base-"; } 37 43 os << "type-of expression "; 38 44 if ( expr ) { -
src/SynTree/Visitor.h
r7951100 rb067d9b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jul 24 16:28:00 201713 // Update Count : 1 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:21:49 2019 13 // Update Count : 14 14 14 // 15 15 … … 27 27 // of the given syntax node, but performs no other action. 28 28 29 virtual void visit( ObjectDecl * objectDecl ) = 0; 30 virtual void visit( FunctionDecl * functionDecl ) = 0; 31 virtual void visit( StructDecl * aggregateDecl ) = 0; 32 virtual void visit( UnionDecl * aggregateDecl ) = 0; 33 virtual void visit( EnumDecl * aggregateDecl ) = 0; 34 virtual void visit( TraitDecl * aggregateDecl ) = 0; 35 virtual void visit( TypeDecl * typeDecl ) = 0; 36 virtual void visit( TypedefDecl * typeDecl ) = 0; 37 virtual void visit( AsmDecl * asmDecl ) = 0; 38 virtual void visit( StaticAssertDecl * assertDecl ) = 0; 39 40 virtual void visit( CompoundStmt * compoundStmt ) = 0; 41 virtual void visit( ExprStmt * exprStmt ) = 0; 42 virtual void visit( AsmStmt * asmStmt ) = 0; 43 virtual void visit( DirectiveStmt * directiveStmt ) = 0; 44 virtual void visit( IfStmt * ifStmt ) = 0; 45 virtual void visit( WhileStmt * whileStmt ) = 0; 46 virtual void visit( ForStmt * forStmt ) = 0; 47 virtual void visit( SwitchStmt * switchStmt ) = 0; 48 virtual void visit( CaseStmt * caseStmt ) = 0; 49 virtual void visit( BranchStmt * branchStmt ) = 0; 50 virtual void visit( ReturnStmt * returnStmt ) = 0; 51 virtual void visit( ThrowStmt * throwStmt ) = 0; 52 virtual void visit( TryStmt * tryStmt ) = 0; 53 virtual void visit( CatchStmt * catchStmt ) = 0; 54 virtual void visit( FinallyStmt * finallyStmt ) = 0; 55 virtual void visit( WaitForStmt * waitforStmt ) = 0; 56 virtual void visit( WithStmt * withStmt ) = 0; 57 virtual void visit( NullStmt * nullStmt ) = 0; 58 virtual void visit( DeclStmt * declStmt ) = 0; 59 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) = 0; 60 61 virtual void visit( ApplicationExpr * applicationExpr ) = 0; 62 virtual void visit( UntypedExpr * untypedExpr ) = 0; 63 virtual void visit( NameExpr * nameExpr ) = 0; 64 virtual void visit( CastExpr * castExpr ) = 0; 65 virtual void visit( KeywordCastExpr * castExpr ) = 0; 66 virtual void visit( VirtualCastExpr * castExpr ) = 0; 67 virtual void visit( AddressExpr * addressExpr ) = 0; 68 virtual void visit( LabelAddressExpr * labAddressExpr ) = 0; 69 virtual void visit( UntypedMemberExpr * memberExpr ) = 0; 70 virtual void visit( MemberExpr * memberExpr ) = 0; 71 virtual void visit( VariableExpr * variableExpr ) = 0; 72 virtual void visit( ConstantExpr * constantExpr ) = 0; 73 virtual void visit( SizeofExpr * sizeofExpr ) = 0; 74 virtual void visit( AlignofExpr * alignofExpr ) = 0; 75 virtual void visit( UntypedOffsetofExpr * offsetofExpr ) = 0; 76 virtual void visit( OffsetofExpr * offsetofExpr ) = 0; 77 virtual void visit( OffsetPackExpr * offsetPackExpr ) = 0; 78 virtual void visit( AttrExpr * attrExpr ) = 0; 79 virtual void visit( LogicalExpr * logicalExpr ) = 0; 80 virtual void visit( ConditionalExpr * conditionalExpr ) = 0; 81 virtual void visit( CommaExpr * commaExpr ) = 0; 82 virtual void visit( TypeExpr * typeExpr ) = 0; 83 virtual void visit( AsmExpr * asmExpr ) = 0; 84 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) = 0; 85 virtual void visit( ConstructorExpr * ctorExpr ) = 0; 86 virtual void visit( CompoundLiteralExpr * compLitExpr ) = 0; 87 virtual void visit( RangeExpr * rangeExpr ) = 0; 88 virtual void visit( UntypedTupleExpr * tupleExpr ) = 0; 89 virtual void visit( TupleExpr * tupleExpr ) = 0; 90 virtual void visit( TupleIndexExpr * tupleExpr ) = 0; 91 virtual void visit( TupleAssignExpr * assignExpr ) = 0; 92 virtual void visit( StmtExpr * stmtExpr ) = 0; 93 virtual void visit( UniqueExpr * uniqueExpr ) = 0; 94 virtual void visit( UntypedInitExpr * initExpr ) = 0; 95 virtual void visit( InitExpr * initExpr ) = 0; 96 virtual void visit( DeletedExpr * delExpr ) = 0; 97 virtual void visit( GenericExpr * genExpr ) = 0; 98 99 virtual void visit( VoidType * basicType ) = 0; 100 virtual void visit( BasicType * basicType ) = 0; 101 virtual void visit( PointerType * pointerType ) = 0; 102 virtual void visit( ArrayType * arrayType ) = 0; 103 virtual void visit( ReferenceType * refType ) = 0; 104 virtual void visit( FunctionType * functionType ) = 0; 105 virtual void visit( StructInstType * aggregateUseType ) = 0; 106 virtual void visit( UnionInstType * aggregateUseType ) = 0; 107 virtual void visit( EnumInstType * aggregateUseType ) = 0; 108 virtual void visit( TraitInstType * aggregateUseType ) = 0; 109 virtual void visit( TypeInstType * aggregateUseType ) = 0; 110 virtual void visit( TupleType * tupleType ) = 0; 111 virtual void visit( TypeofType * typeofType ) = 0; 112 virtual void visit( AttrType * attrType ) = 0; 113 virtual void visit( VarArgsType * varArgsType ) = 0; 114 virtual void visit( ZeroType * zeroType ) = 0; 115 virtual void visit( OneType * oneType ) = 0; 116 117 virtual void visit( Designation * designation ) = 0; 118 virtual void visit( SingleInit * singleInit ) = 0; 119 virtual void visit( ListInit * listInit ) = 0; 120 virtual void visit( ConstructorInit * ctorInit ) = 0; 121 122 virtual void visit( Subrange * subrange ) = 0; 123 124 virtual void visit( Constant * constant ) = 0; 125 126 virtual void visit( Attribute * attribute ) = 0; 29 virtual void visit( ObjectDecl * node ) { visit( const_cast<const ObjectDecl *>(node) ); } 30 virtual void visit( const ObjectDecl * objectDecl ) = 0; 31 virtual void visit( FunctionDecl * node ) { visit( const_cast<const FunctionDecl *>(node) ); } 32 virtual void visit( const FunctionDecl * functionDecl ) = 0; 33 virtual void visit( StructDecl * node ) { visit( const_cast<const StructDecl *>(node) ); } 34 virtual void visit( const StructDecl * aggregateDecl ) = 0; 35 virtual void visit( UnionDecl * node ) { visit( const_cast<const UnionDecl *>(node) ); } 36 virtual void visit( const UnionDecl * aggregateDecl ) = 0; 37 virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); } 38 virtual void visit( const EnumDecl * aggregateDecl ) = 0; 39 virtual void visit( TraitDecl * node ) { visit( const_cast<const TraitDecl *>(node) ); } 40 virtual void visit( const TraitDecl * aggregateDecl ) = 0; 41 virtual void visit( TypeDecl * node ) { visit( const_cast<const TypeDecl *>(node) ); } 42 virtual void visit( const TypeDecl * typeDecl ) = 0; 43 virtual void visit( TypedefDecl * node ) { visit( const_cast<const TypedefDecl *>(node) ); } 44 virtual void visit( const TypedefDecl * typeDecl ) = 0; 45 virtual void visit( AsmDecl * node ) { visit( const_cast<const AsmDecl *>(node) ); } 46 virtual void visit( const AsmDecl * asmDecl ) = 0; 47 virtual void visit( StaticAssertDecl * node ) { visit( const_cast<const StaticAssertDecl *>(node) ); } 48 virtual void visit( const StaticAssertDecl * assertDecl ) = 0; 49 50 virtual void visit( CompoundStmt * node ) { visit( const_cast<const CompoundStmt *>(node) ); } 51 virtual void visit( const CompoundStmt * compoundStmt ) = 0; 52 virtual void visit( ExprStmt * node ) { visit( const_cast<const ExprStmt *>(node) ); } 53 virtual void visit( const ExprStmt * exprStmt ) = 0; 54 virtual void visit( AsmStmt * node ) { visit( const_cast<const AsmStmt *>(node) ); } 55 virtual void visit( const AsmStmt * asmStmt ) = 0; 56 virtual void visit( DirectiveStmt * node ) { visit( const_cast<const DirectiveStmt *>(node) ); } 57 virtual void visit( const DirectiveStmt * directiveStmt ) = 0; 58 virtual void visit( IfStmt * node ) { visit( const_cast<const IfStmt *>(node) ); } 59 virtual void visit( const IfStmt * ifStmt ) = 0; 60 virtual void visit( WhileStmt * node ) { visit( const_cast<const WhileStmt *>(node) ); } 61 virtual void visit( const WhileStmt * whileStmt ) = 0; 62 virtual void visit( ForStmt * node ) { visit( const_cast<const ForStmt *>(node) ); } 63 virtual void visit( const ForStmt * forStmt ) = 0; 64 virtual void visit( SwitchStmt * node ) { visit( const_cast<const SwitchStmt *>(node) ); } 65 virtual void visit( const SwitchStmt * switchStmt ) = 0; 66 virtual void visit( CaseStmt * node ) { visit( const_cast<const CaseStmt *>(node) ); } 67 virtual void visit( const CaseStmt * caseStmt ) = 0; 68 virtual void visit( BranchStmt * node ) { visit( const_cast<const BranchStmt *>(node) ); } 69 virtual void visit( const BranchStmt * branchStmt ) = 0; 70 virtual void visit( ReturnStmt * node ) { visit( const_cast<const ReturnStmt *>(node) ); } 71 virtual void visit( const ReturnStmt * returnStmt ) = 0; 72 virtual void visit( ThrowStmt * node ) { visit( const_cast<const ThrowStmt *>(node) ); } 73 virtual void visit( const ThrowStmt * throwStmt ) = 0; 74 virtual void visit( TryStmt * node ) { visit( const_cast<const TryStmt *>(node) ); } 75 virtual void visit( const TryStmt * tryStmt ) = 0; 76 virtual void visit( CatchStmt * node ) { visit( const_cast<const CatchStmt *>(node) ); } 77 virtual void visit( const CatchStmt * catchStmt ) = 0; 78 virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); } 79 virtual void visit( const FinallyStmt * finallyStmt ) = 0; 80 virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); } 81 virtual void visit( const WaitForStmt * waitforStmt ) = 0; 82 virtual void visit( WithStmt * node ) { visit( const_cast<const WithStmt *>(node) ); } 83 virtual void visit( const WithStmt * withStmt ) = 0; 84 virtual void visit( NullStmt * node ) { visit( const_cast<const NullStmt *>(node) ); } 85 virtual void visit( const NullStmt * nullStmt ) = 0; 86 virtual void visit( DeclStmt * node ) { visit( const_cast<const DeclStmt *>(node) ); } 87 virtual void visit( const DeclStmt * declStmt ) = 0; 88 virtual void visit( ImplicitCtorDtorStmt * node ) { visit( const_cast<const ImplicitCtorDtorStmt *>(node) ); } 89 virtual void visit( const ImplicitCtorDtorStmt * impCtorDtorStmt ) = 0; 90 91 virtual void visit( ApplicationExpr * node ) { visit( const_cast<const ApplicationExpr *>(node) ); } 92 virtual void visit( const ApplicationExpr * applicationExpr ) = 0; 93 virtual void visit( UntypedExpr * node ) { visit( const_cast<const UntypedExpr *>(node) ); } 94 virtual void visit( const UntypedExpr * untypedExpr ) = 0; 95 virtual void visit( NameExpr * node ) { visit( const_cast<const NameExpr *>(node) ); } 96 virtual void visit( const NameExpr * nameExpr ) = 0; 97 virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); } 98 virtual void visit( const CastExpr * castExpr ) = 0; 99 virtual void visit( KeywordCastExpr * node ) { visit( const_cast<const KeywordCastExpr *>(node) ); } 100 virtual void visit( const KeywordCastExpr * castExpr ) = 0; 101 virtual void visit( VirtualCastExpr * node ) { visit( const_cast<const VirtualCastExpr *>(node) ); } 102 virtual void visit( const VirtualCastExpr * castExpr ) = 0; 103 virtual void visit( AddressExpr * node ) { visit( const_cast<const AddressExpr *>(node) ); } 104 virtual void visit( const AddressExpr * addressExpr ) = 0; 105 virtual void visit( LabelAddressExpr * node ) { visit( const_cast<const LabelAddressExpr *>(node) ); } 106 virtual void visit( const LabelAddressExpr * labAddressExpr ) = 0; 107 virtual void visit( UntypedMemberExpr * node ) { visit( const_cast<const UntypedMemberExpr *>(node) ); } 108 virtual void visit( const UntypedMemberExpr * memberExpr ) = 0; 109 virtual void visit( MemberExpr * node ) { visit( const_cast<const MemberExpr *>(node) ); } 110 virtual void visit( const MemberExpr * memberExpr ) = 0; 111 virtual void visit( VariableExpr * node ) { visit( const_cast<const VariableExpr *>(node) ); } 112 virtual void visit( const VariableExpr * variableExpr ) = 0; 113 virtual void visit( ConstantExpr * node ) { visit( const_cast<const ConstantExpr *>(node) ); } 114 virtual void visit( const ConstantExpr * constantExpr ) = 0; 115 virtual void visit( SizeofExpr * node ) { visit( const_cast<const SizeofExpr *>(node) ); } 116 virtual void visit( const SizeofExpr * sizeofExpr ) = 0; 117 virtual void visit( AlignofExpr * node ) { visit( const_cast<const AlignofExpr *>(node) ); } 118 virtual void visit( const AlignofExpr * alignofExpr ) = 0; 119 virtual void visit( UntypedOffsetofExpr * node ) { visit( const_cast<const UntypedOffsetofExpr *>(node) ); } 120 virtual void visit( const UntypedOffsetofExpr * offsetofExpr ) = 0; 121 virtual void visit( OffsetofExpr * node ) { visit( const_cast<const OffsetofExpr *>(node) ); } 122 virtual void visit( const OffsetofExpr * offsetofExpr ) = 0; 123 virtual void visit( OffsetPackExpr * node ) { visit( const_cast<const OffsetPackExpr *>(node) ); } 124 virtual void visit( const OffsetPackExpr * offsetPackExpr ) = 0; 125 virtual void visit( LogicalExpr * node ) { visit( const_cast<const LogicalExpr *>(node) ); } 126 virtual void visit( const LogicalExpr * logicalExpr ) = 0; 127 virtual void visit( ConditionalExpr * node ) { visit( const_cast<const ConditionalExpr *>(node) ); } 128 virtual void visit( const ConditionalExpr * conditionalExpr ) = 0; 129 virtual void visit( CommaExpr * node ) { visit( const_cast<const CommaExpr *>(node) ); } 130 virtual void visit( const CommaExpr * commaExpr ) = 0; 131 virtual void visit( TypeExpr * node ) { visit( const_cast<const TypeExpr *>(node) ); } 132 virtual void visit( const TypeExpr * typeExpr ) = 0; 133 virtual void visit( AsmExpr * node ) { visit( const_cast<const AsmExpr *>(node) ); } 134 virtual void visit( const AsmExpr * asmExpr ) = 0; 135 virtual void visit( ImplicitCopyCtorExpr * node ) { visit( const_cast<const ImplicitCopyCtorExpr *>(node) ); } 136 virtual void visit( const ImplicitCopyCtorExpr * impCpCtorExpr ) = 0; 137 virtual void visit( ConstructorExpr * node ) { visit( const_cast<const ConstructorExpr *>(node) ); } 138 virtual void visit( const ConstructorExpr * ctorExpr ) = 0; 139 virtual void visit( CompoundLiteralExpr * node ) { visit( const_cast<const CompoundLiteralExpr *>(node) ); } 140 virtual void visit( const CompoundLiteralExpr * compLitExpr ) = 0; 141 virtual void visit( RangeExpr * node ) { visit( const_cast<const RangeExpr *>(node) ); } 142 virtual void visit( const RangeExpr * rangeExpr ) = 0; 143 virtual void visit( UntypedTupleExpr * node ) { visit( const_cast<const UntypedTupleExpr *>(node) ); } 144 virtual void visit( const UntypedTupleExpr * tupleExpr ) = 0; 145 virtual void visit( TupleExpr * node ) { visit( const_cast<const TupleExpr *>(node) ); } 146 virtual void visit( const TupleExpr * tupleExpr ) = 0; 147 virtual void visit( TupleIndexExpr * node ) { visit( const_cast<const TupleIndexExpr *>(node) ); } 148 virtual void visit( const TupleIndexExpr * tupleExpr ) = 0; 149 virtual void visit( TupleAssignExpr * node ) { visit( const_cast<const TupleAssignExpr *>(node) ); } 150 virtual void visit( const TupleAssignExpr * assignExpr ) = 0; 151 virtual void visit( StmtExpr * node ) { visit( const_cast<const StmtExpr *>(node) ); } 152 virtual void visit( const StmtExpr * stmtExpr ) = 0; 153 virtual void visit( UniqueExpr * node ) { visit( const_cast<const UniqueExpr *>(node) ); } 154 virtual void visit( const UniqueExpr * uniqueExpr ) = 0; 155 virtual void visit( UntypedInitExpr * node ) { visit( const_cast<const UntypedInitExpr *>(node) ); } 156 virtual void visit( const UntypedInitExpr * initExpr ) = 0; 157 virtual void visit( InitExpr * node ) { visit( const_cast<const InitExpr *>(node) ); } 158 virtual void visit( const InitExpr * initExpr ) = 0; 159 virtual void visit( DeletedExpr * node ) { visit( const_cast<const DeletedExpr *>(node) ); } 160 virtual void visit( const DeletedExpr * delExpr ) = 0; 161 virtual void visit( DefaultArgExpr * node ) { visit( const_cast<const DefaultArgExpr *>(node) ); } 162 virtual void visit( const DefaultArgExpr * argExpr ) = 0; 163 virtual void visit( GenericExpr * node ) { visit( const_cast<const GenericExpr *>(node) ); } 164 virtual void visit( const GenericExpr * genExpr ) = 0; 165 166 virtual void visit( VoidType * node ) { visit( const_cast<const VoidType *>(node) ); } 167 virtual void visit( const VoidType * basicType ) = 0; 168 virtual void visit( BasicType * node ) { visit( const_cast<const BasicType *>(node) ); } 169 virtual void visit( const BasicType * basicType ) = 0; 170 virtual void visit( PointerType * node ) { visit( const_cast<const PointerType *>(node) ); } 171 virtual void visit( const PointerType * pointerType ) = 0; 172 virtual void visit( ArrayType * node ) { visit( const_cast<const ArrayType *>(node) ); } 173 virtual void visit( const ArrayType * arrayType ) = 0; 174 virtual void visit( ReferenceType * node ) { visit( const_cast<const ReferenceType *>(node) ); } 175 virtual void visit( const ReferenceType * refType ) = 0; 176 virtual void visit( QualifiedType * node ) { visit( const_cast<const QualifiedType *>(node) ); } 177 virtual void visit( const QualifiedType * qualType ) = 0; 178 virtual void visit( FunctionType * node ) { visit( const_cast<const FunctionType *>(node) ); } 179 virtual void visit( const FunctionType * functionType ) = 0; 180 virtual void visit( StructInstType * node ) { visit( const_cast<const StructInstType *>(node) ); } 181 virtual void visit( const StructInstType * aggregateUseType ) = 0; 182 virtual void visit( UnionInstType * node ) { visit( const_cast<const UnionInstType *>(node) ); } 183 virtual void visit( const UnionInstType * aggregateUseType ) = 0; 184 virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); } 185 virtual void visit( const EnumInstType * aggregateUseType ) = 0; 186 virtual void visit( TraitInstType * node ) { visit( const_cast<const TraitInstType *>(node) ); } 187 virtual void visit( const TraitInstType * aggregateUseType ) = 0; 188 virtual void visit( TypeInstType * node ) { visit( const_cast<const TypeInstType *>(node) ); } 189 virtual void visit( const TypeInstType * aggregateUseType ) = 0; 190 virtual void visit( TupleType * node ) { visit( const_cast<const TupleType *>(node) ); } 191 virtual void visit( const TupleType * tupleType ) = 0; 192 virtual void visit( TypeofType * node ) { visit( const_cast<const TypeofType *>(node) ); } 193 virtual void visit( const TypeofType * typeofType ) = 0; 194 virtual void visit( AttrType * node ) { visit( const_cast<const AttrType *>(node) ); } 195 virtual void visit( const AttrType * attrType ) = 0; 196 virtual void visit( VarArgsType * node ) { visit( const_cast<const VarArgsType *>(node) ); } 197 virtual void visit( const VarArgsType * varArgsType ) = 0; 198 virtual void visit( ZeroType * node ) { visit( const_cast<const ZeroType *>(node) ); } 199 virtual void visit( const ZeroType * zeroType ) = 0; 200 virtual void visit( OneType * node ) { visit( const_cast<const OneType *>(node) ); } 201 virtual void visit( const OneType * oneType ) = 0; 202 virtual void visit( GlobalScopeType * node ) { visit( const_cast<const GlobalScopeType *>(node) ); } 203 virtual void visit( const GlobalScopeType * globalType ) = 0; 204 205 virtual void visit( Designation * node ) { visit( const_cast<const Designation *>(node) ); } 206 virtual void visit( const Designation * designation ) = 0; 207 virtual void visit( SingleInit * node ) { visit( const_cast<const SingleInit *>(node) ); } 208 virtual void visit( const SingleInit * singleInit ) = 0; 209 virtual void visit( ListInit * node ) { visit( const_cast<const ListInit *>(node) ); } 210 virtual void visit( const ListInit * listInit ) = 0; 211 virtual void visit( ConstructorInit * node ) { visit( const_cast<const ConstructorInit *>(node) ); } 212 virtual void visit( const ConstructorInit * ctorInit ) = 0; 213 214 virtual void visit( Constant * node ) { visit( const_cast<const Constant *>(node) ); } 215 virtual void visit( const Constant * constant ) = 0; 216 217 virtual void visit( Attribute * node ) { visit( const_cast<const Attribute *>(node) ); } 218 virtual void visit( const Attribute * attribute ) = 0; 127 219 }; 128 220 129 221 template< typename TreeType, typename VisitorType > 130 inline void maybeAccept( TreeType * tree, VisitorType &visitor ) {222 inline void maybeAccept( TreeType * tree, VisitorType & visitor ) { 131 223 if ( tree ) { 132 224 tree->accept( visitor ); … … 134 226 } 135 227 228 template< typename TreeType, typename VisitorType > 229 inline void maybeAccept( const TreeType * tree, VisitorType & visitor ) { 230 if ( tree ) { 231 tree->accept( visitor ); 232 } 233 } 234 136 235 template< typename Container, typename VisitorType > 137 inline void acceptAll( Container & container, VisitorType &visitor ) {236 inline void acceptAll( Container & container, VisitorType & visitor ) { 138 237 SemanticErrorException errors; 139 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i) {238 for ( auto * i : container ) { 140 239 try { 141 if ( *i ) { 142 (*i)->accept( visitor ); 240 if ( i ) { 241 i->accept( visitor ); 242 } 243 } catch( SemanticErrorException & e ) { 244 errors.append( e ); 245 } 246 } 247 if ( ! errors.isEmpty() ) { 248 throw errors; 249 } 250 } 251 252 template< typename Container, typename VisitorType > 253 inline void acceptAll( const Container & container, VisitorType & visitor ) { 254 SemanticErrorException errors; 255 for ( const auto * i : container ) { 256 try { 257 if ( i ) { 258 i->accept( visitor ); 143 259 } 144 260 } catch( SemanticErrorException &e ) { -
src/SynTree/module.mk
r7951100 rb067d9b 15 15 ############################################################################### 16 16 17 SRC += SynTree/Type.cc \ 18 SynTree/VoidType.cc \ 19 SynTree/BasicType.cc \ 20 SynTree/PointerType.cc \ 21 SynTree/ArrayType.cc \ 22 SynTree/ReferenceType.cc \ 23 SynTree/FunctionType.cc \ 24 SynTree/ReferenceToType.cc \ 25 SynTree/TupleType.cc \ 26 SynTree/TypeofType.cc \ 27 SynTree/AttrType.cc \ 28 SynTree/VarArgsType.cc \ 29 SynTree/ZeroOneType.cc \ 30 SynTree/Constant.cc \ 31 SynTree/Expression.cc \ 32 SynTree/TupleExpr.cc \ 33 SynTree/CommaExpr.cc \ 34 SynTree/TypeExpr.cc \ 35 SynTree/ApplicationExpr.cc \ 36 SynTree/AddressExpr.cc \ 37 SynTree/Statement.cc \ 38 SynTree/CompoundStmt.cc \ 39 SynTree/DeclStmt.cc \ 40 SynTree/Declaration.cc \ 41 SynTree/DeclarationWithType.cc \ 42 SynTree/ObjectDecl.cc \ 43 SynTree/FunctionDecl.cc \ 44 SynTree/AggregateDecl.cc \ 45 SynTree/NamedTypeDecl.cc \ 46 SynTree/TypeDecl.cc \ 47 SynTree/Initializer.cc \ 48 SynTree/TypeSubstitution.cc \ 49 SynTree/Attribute.cc \ 50 SynTree/DeclReplacer.cc 17 SRC_SYNTREE = \ 18 SynTree/Type.cc \ 19 SynTree/VoidType.cc \ 20 SynTree/BasicType.cc \ 21 SynTree/PointerType.cc \ 22 SynTree/ArrayType.cc \ 23 SynTree/ReferenceType.cc \ 24 SynTree/FunctionType.cc \ 25 SynTree/ReferenceToType.cc \ 26 SynTree/TupleType.cc \ 27 SynTree/TypeofType.cc \ 28 SynTree/AttrType.cc \ 29 SynTree/VarArgsType.cc \ 30 SynTree/ZeroOneType.cc \ 31 SynTree/Constant.cc \ 32 SynTree/Expression.cc \ 33 SynTree/TupleExpr.cc \ 34 SynTree/CommaExpr.cc \ 35 SynTree/TypeExpr.cc \ 36 SynTree/ApplicationExpr.cc \ 37 SynTree/AddressExpr.cc \ 38 SynTree/Statement.cc \ 39 SynTree/CompoundStmt.cc \ 40 SynTree/DeclStmt.cc \ 41 SynTree/Declaration.cc \ 42 SynTree/DeclarationWithType.cc \ 43 SynTree/ObjectDecl.cc \ 44 SynTree/FunctionDecl.cc \ 45 SynTree/AggregateDecl.cc \ 46 SynTree/NamedTypeDecl.cc \ 47 SynTree/TypeDecl.cc \ 48 SynTree/Initializer.cc \ 49 SynTree/TypeSubstitution.cc \ 50 SynTree/Attribute.cc \ 51 SynTree/DeclReplacer.cc 51 52 53 SRC += $(SRC_SYNTREE) 54 SRCDEMANGLE += $(SRC_SYNTREE)
Note:
See TracChangeset
for help on using the changeset viewer.