Changeset 1cdfa82 for src/SynTree
- Timestamp:
- Apr 25, 2018, 4:55:53 PM (7 years ago)
- Branches:
- new-env, with_gc
- Children:
- 42107b4
- Parents:
- 2efe4b8 (diff), 9d5fb67 (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:
-
- 1 added
- 1 deleted
- 14 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/CompoundStmt.cc
r2efe4b8 r1cdfa82 23 23 #include "Statement.h" // for CompoundStmt, Statement, DeclStmt 24 24 #include "SynTree/Label.h" // for Label 25 #include "SynTree/ VarExprReplacer.h" // for VarExprReplacer, VarExprReplace...25 #include "SynTree/DeclReplacer.h" // for DeclReplacer 26 26 27 27 using std::string; … … 49 49 // recursively execute this routine. There may be more efficient ways of doing 50 50 // this. 51 VarExprReplacer::DeclMap declMap;51 DeclReplacer::DeclMap declMap; 52 52 std::list< Statement * >::const_iterator origit = other.kids.begin(); 53 53 for ( Statement * s : kids ) { … … 64 64 } 65 65 if ( ! declMap.empty() ) { 66 VarExprReplacer::replace( this, declMap );66 DeclReplacer::replace( this, declMap ); 67 67 } 68 68 } -
src/SynTree/DeclReplacer.h
r2efe4b8 r1cdfa82 23 23 class VariableExpr; 24 24 25 namespace VarExprReplacer {25 namespace DeclReplacer { 26 26 typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap; 27 typedef std::map< TypeDecl *, TypeDecl * > TypeMap; 27 28 28 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 ); 29 32 } 30 33 -
src/SynTree/Declaration.cc
r2efe4b8 r1cdfa82 74 74 75 75 76 StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message ) { 77 } 78 79 StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) ) { 80 } 81 82 StaticAssertDecl::~StaticAssertDecl() { 83 delete condition; 84 delete message; 85 } 86 87 void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const { 88 os << "Static Assert with condition: "; 89 condition->print( os, indent+1 ); 90 os << std::endl << indent << "and message: "; 91 message->print( os, indent+1 ); 92 os << std::endl; 93 } 94 95 void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const { 96 print( os, indent ); 97 } 98 76 99 // Local Variables: // 77 100 // tab-width: 4 // -
src/SynTree/Declaration.h
r2efe4b8 r1cdfa82 357 357 }; 358 358 359 class StaticAssertDecl : public Declaration { 360 public: 361 Expression * condition; 362 ConstantExpr * message; // string literal 363 364 StaticAssertDecl( Expression * condition, ConstantExpr * message ); 365 StaticAssertDecl( const StaticAssertDecl & other ); 366 virtual ~StaticAssertDecl(); 367 368 virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 369 virtual void accept( Visitor &v ) override { v.visit( this ); } 370 virtual StaticAssertDecl * acceptMutator( Mutator &m ) override { return m.mutate( this ); } 371 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 372 virtual void printShort( std::ostream &os, Indenter indent = {} ) const override; 373 }; 374 359 375 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ); 360 376 -
src/SynTree/Expression.cc
r2efe4b8 r1cdfa82 238 238 } 239 239 240 CastExpr::CastExpr( Expression *arg _, Type *toType ) : Expression(), arg(arg_) {240 CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) { 241 241 set_result(toType); 242 242 } 243 243 244 CastExpr::CastExpr( Expression *arg _ ) : Expression(), arg(arg_) {244 CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) { 245 245 set_result( new VoidType( Type::Qualifiers() ) ); 246 246 } 247 247 248 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {248 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) { 249 249 } 250 250 … … 259 259 result->print( os, indent+1 ); 260 260 } // if 261 Expression::print( os, indent ); 262 } 263 264 KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) { 265 } 266 267 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) { 268 } 269 270 KeywordCastExpr::~KeywordCastExpr() { 271 delete arg; 272 } 273 274 const std::string & KeywordCastExpr::targetString() const { 275 static const std::string targetStrs[] = { 276 "coroutine", "thread", "monitor" 277 }; 278 static_assert( 279 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 280 "Each KeywordCastExpr::Target should have a corresponding string representation" 281 ); 282 return targetStrs[(unsigned long)target]; 283 } 284 285 void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const { 286 os << "Keyword Cast of:" << std::endl << indent+1; 287 arg->print(os, indent+1); 288 os << std::endl << indent << "... to: "; 289 os << targetString(); 261 290 Expression::print( os, indent ); 262 291 } -
src/SynTree/Expression.h
r2efe4b8 r1cdfa82 184 184 public: 185 185 Expression * arg; 186 187 CastExpr( Expression * arg ); 188 CastExpr( Expression * arg, Type * toType ); 186 bool isGenerated = true; // whether this cast appeared in the source program 187 188 CastExpr( Expression * arg, bool isGenerated = true ); 189 CastExpr( Expression * arg, Type * toType, bool isGenerated = true ); 190 CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor 189 191 CastExpr( const CastExpr & other ); 190 192 … … 193 195 194 196 virtual CastExpr * clone() const { return new CastExpr( * this ); } 197 virtual void accept( Visitor & v ) { v.visit( this ); } 198 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 199 virtual void print( std::ostream & os, Indenter indent = {} ) const; 200 }; 201 202 /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t 203 class KeywordCastExpr : public Expression { 204 public: 205 Expression * arg; 206 enum Target { 207 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS 208 } target; 209 210 KeywordCastExpr( Expression * arg, Target target ); 211 KeywordCastExpr( const KeywordCastExpr & other ); 212 virtual ~KeywordCastExpr(); 213 214 const std::string & targetString() const; 215 216 virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); } 195 217 virtual void accept( Visitor & v ) { v.visit( this ); } 196 218 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } -
src/SynTree/FunctionDecl.cc
r2efe4b8 r1cdfa82 26 26 #include "Statement.h" // for CompoundStmt 27 27 #include "Type.h" // for Type, FunctionType, Type::FuncSpecif... 28 #include " VarExprReplacer.h"28 #include "DeclReplacer.h" 29 29 30 30 extern bool translation_unit_nomain; … … 41 41 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) { 42 42 43 VarExprReplacer::DeclMap declMap;43 DeclReplacer::DeclMap declMap; 44 44 for ( auto p : group_iterate( other.type->parameters, type->parameters ) ) { 45 45 declMap[ std::get<0>(p) ] = std::get<1>(p); … … 49 49 } 50 50 if ( ! declMap.empty() ) { 51 VarExprReplacer::replace( this, declMap );51 DeclReplacer::replace( this, declMap ); 52 52 } 53 53 cloneAll( other.withExprs, withExprs ); -
src/SynTree/Mutator.h
r2efe4b8 r1cdfa82 34 34 virtual Declaration * mutate( TypedefDecl * typeDecl ) = 0; 35 35 virtual AsmDecl * mutate( AsmDecl * asmDecl ) = 0; 36 virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0; 36 37 37 38 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) = 0; … … 58 59 virtual Expression * mutate( UntypedExpr * untypedExpr ) = 0; 59 60 virtual Expression * mutate( NameExpr * nameExpr ) = 0; 60 virtual Expression * mutate( AddressExpr * castExpr ) = 0;61 virtual Expression * mutate( AddressExpr * addrExpr ) = 0; 61 62 virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) = 0; 62 63 virtual Expression * mutate( CastExpr * castExpr ) = 0; 64 virtual Expression * mutate( KeywordCastExpr * castExpr ) = 0; 63 65 virtual Expression * mutate( VirtualCastExpr * castExpr ) = 0; 64 66 virtual Expression * mutate( UntypedMemberExpr * memberExpr ) = 0; -
src/SynTree/Statement.cc
r2efe4b8 r1cdfa82 34 34 Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {} 35 35 36 void Statement::print( std::ostream & os, Indenter ) const {36 void Statement::print( std::ostream & os, Indenter indent ) const { 37 37 if ( ! labels.empty() ) { 38 os << "Labels: {";38 os << indent << "... Labels: {"; 39 39 for ( const Label & l : labels ) { 40 40 os << l << ","; … … 188 188 189 189 void CaseStmt::print( std::ostream &os, Indenter indent ) const { 190 if ( isDefault() ) os << "Default ";190 if ( isDefault() ) os << indent << "Default "; 191 191 else { 192 os << "Case ";192 os << indent << "Case "; 193 193 condition->print( os, indent ); 194 194 } // if … … 196 196 197 197 for ( Statement * stmt : stmts ) { 198 os << indent+1; 198 199 stmt->print( os, indent+1 ); 199 200 } … … 391 392 } 392 393 393 void NullStmt::print( std::ostream &os, Indenter ) const {394 void NullStmt::print( std::ostream &os, Indenter indent ) const { 394 395 os << "Null Statement" << endl; 396 Statement::print( os, indent ); 395 397 } 396 398 -
src/SynTree/Statement.h
r2efe4b8 r1cdfa82 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 20:46:46 201713 // Update Count : 7 712 // Last Modified On : Thu Mar 8 14:53:02 2018 13 // Update Count : 78 14 14 // 15 15 … … 246 246 class BranchStmt : public Statement { 247 247 public: 248 enum Type { Goto = 0, Break, Continue };248 enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault }; 249 249 250 250 // originalTarget kept for error messages. -
src/SynTree/SynTree.h
r2efe4b8 r1cdfa82 38 38 class TypedefDecl; 39 39 class AsmDecl; 40 class StaticAssertDecl; 40 41 41 42 class Statement; … … 68 69 class LabelAddressExpr; 69 70 class CastExpr; 71 class KeywordCastExpr; 70 72 class VirtualCastExpr; 71 73 class MemberExpr; -
src/SynTree/TypeSubstitution.cc
r2efe4b8 r1cdfa82 132 132 return inst; 133 133 } else { 134 /// std::cerr << "found " << inst->get_name() << ", replacing with "; 135 /// i->second->print( std::cerr ); 136 /// std::cerr << std::endl; 134 // cut off infinite loop for the case where a type is bound to itself. 135 // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here. 136 // TODO: investigate preventing type variables from being bound to themselves in the first place. 137 if ( TypeInstType * replacement = dynamic_cast< TypeInstType * >( i->second ) ) { 138 if ( inst->name == replacement->name ) { 139 return inst; 140 } 141 } 142 // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl; 137 143 subCount++; 138 144 Type * newtype = i->second->clone(); 139 145 newtype->get_qualifiers() |= inst->get_qualifiers(); 140 return newtype; 146 // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode. 147 return newtype->acceptMutator( *visitor ); 141 148 } // if 142 149 } -
src/SynTree/TypeSubstitution.h
r2efe4b8 r1cdfa82 125 125 126 126 // definitition must happen after PassVisitor is included so that WithGuards can be used 127 struct TypeSubstitution::Substituter : public WithGuards {127 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> { 128 128 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {} 129 129 -
src/SynTree/Visitor.h
r2efe4b8 r1cdfa82 36 36 virtual void visit( TypedefDecl * typeDecl ) = 0; 37 37 virtual void visit( AsmDecl * asmDecl ) = 0; 38 virtual void visit( StaticAssertDecl * assertDecl ) = 0; 38 39 39 40 virtual void visit( CompoundStmt * compoundStmt ) = 0; … … 61 62 virtual void visit( NameExpr * nameExpr ) = 0; 62 63 virtual void visit( CastExpr * castExpr ) = 0; 64 virtual void visit( KeywordCastExpr * castExpr ) = 0; 63 65 virtual void visit( VirtualCastExpr * castExpr ) = 0; 64 66 virtual void visit( AddressExpr * addressExpr ) = 0; -
src/SynTree/module.mk
r2efe4b8 r1cdfa82 49 49 SynTree/Attribute.cc \ 50 50 SynTree/BaseSyntaxNode.cc \ 51 SynTree/ VarExprReplacer.cc51 SynTree/DeclReplacer.cc 52 52
Note:
See TracChangeset
for help on using the changeset viewer.