Changeset 32cab5b for src/SynTree
- Timestamp:
- Apr 17, 2018, 12:01:09 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 3265399
- Parents:
- b2fe1c9 (diff), 81bb114 (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
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/CompoundStmt.cc
rb2fe1c9 r32cab5b 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
rb2fe1c9 r32cab5b 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
rb2fe1c9 r32cab5b 81 81 82 82 83 StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message ) { 84 } 85 86 StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) ) { 87 } 88 89 StaticAssertDecl::~StaticAssertDecl() { 90 delete condition; 91 delete message; 92 } 93 94 void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const { 95 os << "Static Assert with condition: "; 96 condition->print( os, indent+1 ); 97 os << std::endl << indent << "and message: "; 98 message->print( os, indent+1 ); 99 os << std::endl; 100 } 101 102 void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const { 103 print( os, indent ); 104 } 105 83 106 // Local Variables: // 84 107 // tab-width: 4 // -
src/SynTree/Declaration.h
rb2fe1c9 r32cab5b 365 365 }; 366 366 367 class StaticAssertDecl : public Declaration { 368 public: 369 Expression * condition; 370 ConstantExpr * message; // string literal 371 372 StaticAssertDecl( Expression * condition, ConstantExpr * message ); 373 StaticAssertDecl( const StaticAssertDecl & other ); 374 virtual ~StaticAssertDecl(); 375 376 virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 377 virtual void accept( Visitor &v ) override { v.visit( this ); } 378 virtual StaticAssertDecl * acceptMutator( Mutator &m ) override { return m.mutate( this ); } 379 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 380 virtual void printShort( std::ostream &os, Indenter indent = {} ) const override; 381 }; 382 367 383 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ); 368 384 -
src/SynTree/FunctionDecl.cc
rb2fe1c9 r32cab5b 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
rb2fe1c9 r32cab5b 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; -
src/SynTree/Statement.cc
rb2fe1c9 r32cab5b 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 << ","; … … 223 223 224 224 void CaseStmt::print( std::ostream &os, Indenter indent ) const { 225 if ( isDefault() ) os << "Default ";225 if ( isDefault() ) os << indent << "Default "; 226 226 else { 227 os << "Case ";227 os << indent << "Case "; 228 228 condition->print( os, indent ); 229 229 } // if … … 231 231 232 232 for ( Statement * stmt : stmts ) { 233 os << indent+1; 233 234 stmt->print( os, indent+1 ); 234 235 } … … 478 479 } 479 480 480 void NullStmt::print( std::ostream &os, Indenter ) const {481 void NullStmt::print( std::ostream &os, Indenter indent ) const { 481 482 os << "Null Statement" << endl; 483 Statement::print( os, indent ); 482 484 } 483 485 -
src/SynTree/Statement.h
rb2fe1c9 r32cab5b 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 … … 255 255 class BranchStmt : public Statement { 256 256 public: 257 enum Type { Goto = 0, Break, Continue };257 enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault }; 258 258 259 259 // originalTarget kept for error messages. -
src/SynTree/SynTree.h
rb2fe1c9 r32cab5b 38 38 class TypedefDecl; 39 39 class AsmDecl; 40 class StaticAssertDecl; 40 41 41 42 class Statement; -
src/SynTree/TypeSubstitution.cc
rb2fe1c9 r32cab5b 149 149 return inst; 150 150 } else { 151 /// std::cerr << "found " << inst->get_name() << ", replacing with "; 152 /// i->second->print( std::cerr ); 153 /// std::cerr << std::endl; 151 // cut off infinite loop for the case where a type is bound to itself. 152 // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here. 153 // TODO: investigate preventing type variables from being bound to themselves in the first place. 154 if ( TypeInstType * replacement = dynamic_cast< TypeInstType * >( i->second ) ) { 155 if ( inst->name == replacement->name ) { 156 return inst; 157 } 158 } 159 // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl; 154 160 subCount++; 155 161 Type * newtype = i->second->clone(); 156 162 newtype->get_qualifiers() |= inst->get_qualifiers(); 157 163 delete inst; 158 return newtype; 164 // 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. 165 return newtype->acceptMutator( *visitor ); 159 166 } // if 160 167 } -
src/SynTree/TypeSubstitution.h
rb2fe1c9 r32cab5b 129 129 130 130 // definitition must happen after PassVisitor is included so that WithGuards can be used 131 struct TypeSubstitution::Substituter : public WithGuards {131 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> { 132 132 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {} 133 133 -
src/SynTree/Visitor.h
rb2fe1c9 r32cab5b 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; -
src/SynTree/module.mk
rb2fe1c9 r32cab5b 48 48 SynTree/TypeSubstitution.cc \ 49 49 SynTree/Attribute.cc \ 50 SynTree/ VarExprReplacer.cc50 SynTree/DeclReplacer.cc 51 51
Note:
See TracChangeset
for help on using the changeset viewer.