Changeset 62423350 for src/SynTree
- Timestamp:
- Jun 29, 2017, 5:06:24 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, resolv-new, with_gc
- Children:
- a12d5aa
- Parents:
- bb1cd95
- Location:
- src/SynTree
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Constant.cc
rbb1cd95 r62423350 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Constant.cc -- 7 // Constant.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 46 46 } 47 47 48 unsigned long long Constant::get_ival() const { 49 assertf( safe_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve ival from non-integer constant." ); 50 return val.ival; 51 } 52 53 double Constant::get_dval() const { 54 assertf( ! safe_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve dval from integer constant." ); 55 return val.dval; 56 } 57 48 58 void Constant::print( std::ostream &os ) const { 49 59 os << "(" << rep << " " << val.ival; -
src/SynTree/Constant.h
rbb1cd95 r62423350 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Constant.h -- 7 // Constant.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 32 32 std::string & get_value() { return rep; } 33 33 void set_value( std::string newValue ) { rep = newValue; } 34 unsigned long long get_ival() const; 35 double get_dval() const; 34 36 35 37 /// generates a boolean constant of the given bool -
src/SynTree/Expression.cc
rbb1cd95 r62423350 21 21 #include <iterator> 22 22 23 #include "Declaration.h" 24 #include "Expression.h" 25 #include "Initializer.h" 26 #include "Statement.h" 23 27 #include "Type.h" 24 #include "Initializer.h"25 #include "Expression.h"26 #include "Declaration.h"27 #include "Statement.h"28 28 #include "TypeSubstitution.h" 29 #include "VarExprReplacer.h" 30 29 31 #include "Common/utility.h" 32 #include "Common/PassVisitor.h" 33 30 34 #include "InitTweak/InitTweak.h" 31 35 … … 681 685 } 682 686 683 InitExpr::InitExpr( Expression * expr, Type * type,Designation * designation ) : expr( expr ), designation( designation ) {684 set_result( type);687 InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) { 688 set_result( expr->get_result()->clone() ); 685 689 } 686 690 InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {} -
src/SynTree/Expression.h
rbb1cd95 r62423350 776 776 class InitExpr : public Expression { 777 777 public: 778 InitExpr( Expression * expr, Type * type,Designation * designation );778 InitExpr( Expression * expr, Designation * designation ); 779 779 InitExpr( const InitExpr & other ); 780 780 ~InitExpr(); -
src/SynTree/Initializer.cc
rbb1cd95 r62423350 65 65 66 66 67 ListInit::ListInit( const std::list<Initializer*> &initializers, const std::list<Designation *> &designations, bool maybeConstructed ) 68 : Initializer( maybeConstructed ), initializers( initializers ), designations( designations ) { 67 ListInit::ListInit( const std::list<Initializer*> &inits, const std::list<Designation *> &des, bool maybeConstructed ) 68 : Initializer( maybeConstructed ), initializers( inits ), designations( des ) { 69 // handle the common case where a ListInit is created without designations by making a list of empty designations with the same length as the initializer 70 if ( designations.empty() ) { 71 for ( auto & i : initializers ) { 72 (void)i; 73 designations.push_back( new Designation( {} ) ); 74 } 75 } 76 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%d) and designations (%d)", initializers.size(), designations.size() ); 69 77 } 70 78 -
src/SynTree/Mutator.cc
rbb1cd95 r62423350 515 515 mutateAll( tupleType->get_forall(), *this ); 516 516 mutateAll( tupleType->get_types(), *this ); 517 mutateAll( tupleType->get_members(), *this ); 517 518 return tupleType; 518 519 } -
src/SynTree/TupleType.cc
rbb1cd95 r62423350 14 14 // 15 15 16 #include "Declaration.h" 17 #include "Initializer.h" 16 18 #include "Type.h" 17 19 #include "Common/utility.h" 20 #include "Parser/LinkageSpec.h" 18 21 19 22 TupleType::TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), types( types ) { 23 for ( Type * t : *this ) { 24 // xxx - this is very awkward. TupleTypes should contain objects so that members can be named, but if they don't have an initializer node then 25 // they end up getting constructors, which end up being inserted causing problems. This happens because the object decls have to be visited so that 26 // their types are kept in sync with the types list here. Ultimately, the types list here should be eliminated and perhaps replaced with a list-view 27 // of the object types list, but I digress. The temporary solution here is to make a ListInit with maybeConstructed = false, that way even when the 28 // object is visited, it is never constructed. Ultimately, a better solution might be either: 29 // a) to separate TupleType from its declarations, into TupleDecl and Tuple{Inst?}Type, ala StructDecl and StructInstType 30 // b) separate initializer nodes better, e.g. add a MaybeConstructed node that is replaced by genInit, rather than what currently exists in a bool 31 members.push_back( new ObjectDecl( "" , Type::StorageClasses(), LinkageSpec::Cforall, nullptr, t->clone(), new ListInit( {}, {}, false ) ) ); 32 } 20 33 } 21 34 22 35 TupleType::TupleType( const TupleType& other ) : Type( other ) { 23 36 cloneAll( other.types, types ); 37 cloneAll( other.members, members ); 24 38 } 25 39 26 40 TupleType::~TupleType() { 27 41 deleteAll( types ); 42 deleteAll( members ); 28 43 } 29 44 -
src/SynTree/Type.h
rbb1cd95 r62423350 481 481 class TupleType : public Type { 482 482 public: 483 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types = std::list< Type * >(), const std::list< Attribute * > & attributes = std::list< Attribute * >() );483 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 484 484 TupleType( const TupleType& ); 485 485 virtual ~TupleType(); … … 488 488 typedef value_type::iterator iterator; 489 489 490 std::list<Type *>& get_types() { return types; }490 std::list<Type *> & get_types() { return types; } 491 491 virtual unsigned size() const { return types.size(); }; 492 493 // For now, this is entirely synthetic -- tuple types always have unnamed members. 494 // Eventually, we may allow named tuples, in which case members should subsume types 495 std::list<Declaration *> & get_members() { return members; } 492 496 493 497 iterator begin() { return types.begin(); } … … 506 510 virtual void print( std::ostream & os, int indent = 0 ) const; 507 511 private: 508 std::list<Type*> types; 512 std::list<Type *> types; 513 std::list<Declaration *> members; 509 514 }; 510 515 -
src/SynTree/VarExprReplacer.cc
rbb1cd95 r62423350 14 14 // 15 15 16 #include "Declaration.h" 16 17 #include "Expression.h" 17 18 #include "VarExprReplacer.h" 18 19 19 VarExprReplacer::VarExprReplacer( const DeclMap & declMap ) : declMap( declMap) {}20 VarExprReplacer::VarExprReplacer( const DeclMap & declMap, bool debug ) : declMap( declMap ), debug( debug ) {} 20 21 21 22 // replace variable with new node from decl map 22 23 void VarExprReplacer::visit( VariableExpr * varExpr ) { 23 // 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) 24 if ( declMap.count( varExpr->get_var() ) ) { 25 varExpr->set_var( declMap.at( varExpr->get_var() ) ); 26 } 24 // 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) 25 if ( declMap.count( varExpr->get_var() ) ) { 26 if ( debug ) { 27 std::cerr << "replacing variable reference: " << (void*)varExpr->get_var() << " " << varExpr->get_var() << " with " << (void*)declMap.at( varExpr->get_var() ) << " " << declMap.at( varExpr->get_var() ) << std::endl; 28 } 29 varExpr->set_var( declMap.at( varExpr->get_var() ) ); 30 } 27 31 } -
src/SynTree/VarExprReplacer.h
rbb1cd95 r62423350 27 27 private: 28 28 const DeclMap & declMap; 29 bool debug; 29 30 public: 30 VarExprReplacer( const DeclMap & declMap );31 VarExprReplacer( const DeclMap & declMap, bool debug = false ); 31 32 32 33 // replace variable with new node from decl map -
src/SynTree/Visitor.cc
rbb1cd95 r62423350 407 407 acceptAll( tupleType->get_forall(), *this ); 408 408 acceptAll( tupleType->get_types(), *this ); 409 acceptAll( tupleType->get_members(), *this ); 409 410 } 410 411
Note: See TracChangeset
for help on using the changeset viewer.