Changeset 312029a for src/SynTree
- Timestamp:
- Dec 11, 2019, 8:52:38 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
- Children:
- 737c98a
- Parents:
- 98d6965d
- Location:
- src/SynTree
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AggregateDecl.cc
r98d6965d r312029a 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 23:56:39 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 4 14:22:00 201713 // Update Count : 2 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:31:55 2019 13 // Update Count : 29 14 14 // 15 15 … … 21 21 #include "Common/utility.h" // for printAll, cloneAll, deleteAll 22 22 #include "Declaration.h" // for AggregateDecl, TypeDecl, Declaration 23 #include "Initializer.h" 23 24 #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall 24 25 #include "Type.h" // for Type, Type::StorageClasses 25 26 27 28 // These must harmonize with the corresponding AggregateDecl::Aggregate enumerations. 29 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" }; 30 31 const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) { 32 return aggregateNames[aggr]; 33 } 26 34 27 35 AggregateDecl::AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, Type::StorageClasses(), linkage ), body( false ), attributes( attributes ) { … … 78 86 } 79 87 80 std::string StructDecl::typeString() const { return "struct"; }88 const char * StructDecl::typeString() const { return aggrString( kind ); } 81 89 82 std::string UnionDecl::typeString() const { return "union"; }90 const char * UnionDecl::typeString() const { return aggrString( Union ); } 83 91 84 std::string EnumDecl::typeString() const { return "enum"; }92 const char * EnumDecl::typeString() const { return aggrString( Enum ); } 85 93 86 std::string TraitDecl::typeString() const { return "trait"; }94 const char * TraitDecl::typeString() const { return aggrString( Trait ); } 87 95 88 96 bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) { -
src/SynTree/Declaration.cc
r98d6965d r312029a 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 : Wed Aug 9 14:38:00 201713 // Update Count : 2511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:39:56 2019 13 // Update Count : 36 14 14 // 15 15 … … 24 24 #include "SynTree/Statement.h" // for AsmStmt 25 25 #include "SynTree/SynTree.h" // for UniqueId 26 #include "SynTree/Expression.h" 26 27 #include "Type.h" // for Type, Type::StorageClasses 27 28 29 // To canonicalize declarations 28 30 static UniqueId lastUniqueId = 0; 29 31 -
src/SynTree/Declaration.h
r98d6965d r312029a 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 : Thr May 2 10:47:00 201913 // Update Count : 1 3511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:48:20 2019 13 // Update Count : 149 14 14 // 15 15 … … 25 25 #include "Mutator.h" // for Mutator 26 26 #include "Parser/LinkageSpec.h" // for Spec, Cforall 27 #include "Parser/ParseNode.h" // for DeclarationNode, DeclarationNode::Ag...28 27 #include "SynTree.h" // for UniqueId 29 28 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Type::Fu... … … 194 193 std::list< DeclarationWithType* >& get_assertions() { return assertions; } 195 194 196 virtual std::stringtypeString() const = 0;195 virtual const char * typeString() const = 0; 197 196 198 197 virtual NamedTypeDecl *clone() const override = 0; … … 237 236 TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; } 238 237 239 virtual std::stringtypeString() const override;240 virtual std::stringgenTypeString() const;238 virtual const char * typeString() const override; 239 virtual const char * genTypeString() const; 241 240 242 241 virtual TypeDecl *clone() const override { return new TypeDecl( *this ); } … … 257 256 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} 258 257 259 virtual std::stringtypeString() const override;258 virtual const char * typeString() const override; 260 259 261 260 virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); } … … 269 268 typedef Declaration Parent; 270 269 public: 270 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate }; 271 static const char * aggrString( Aggregate aggr ); 272 271 273 std::list<Declaration*> members; 272 274 std::list<TypeDecl*> parameters; … … 291 293 virtual void printShort( std::ostream &os, Indenter indent = {} ) const override; 292 294 protected: 293 virtual std::stringtypeString() const = 0;295 virtual const char * typeString() const = 0; 294 296 }; 295 297 … … 297 299 typedef AggregateDecl Parent; 298 300 public: 299 StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {}301 StructDecl( const std::string &name, Aggregate kind = Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {} 300 302 StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {} 301 303 302 bool is_coroutine() { return kind == DeclarationNode::Coroutine; }303 bool is_monitor() { return kind == DeclarationNode::Monitor; }304 bool is_thread() { return kind == DeclarationNode::Thread; }304 bool is_coroutine() { return kind == Coroutine; } 305 bool is_monitor() { return kind == Monitor; } 306 bool is_thread() { return kind == Thread; } 305 307 306 308 virtual StructDecl *clone() const override { return new StructDecl( *this ); } … … 308 310 virtual void accept( Visitor & v ) const override { v.visit( this ); } 309 311 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 310 DeclarationNode::Aggregate kind;311 private: 312 virtual std::stringtypeString() const override;312 Aggregate kind; 313 private: 314 virtual const char * typeString() const override; 313 315 }; 314 316 … … 324 326 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 325 327 private: 326 virtual std::stringtypeString() const override;328 virtual const char * typeString() const override; 327 329 }; 328 330 … … 341 343 private: 342 344 std::unordered_map< std::string, long long int > enumValues; 343 virtual std::stringtypeString() const override;345 virtual const char * typeString() const override; 344 346 }; 345 347 … … 357 359 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 358 360 private: 359 virtual std::stringtypeString() const override;361 virtual const char * typeString() const override; 360 362 }; 361 363 -
src/SynTree/Expression.cc
r98d6965d r312029a 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 : Thr Aug 15 13:43:00201913 // Update Count : 6411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 07:55:15 2019 13 // Update Count : 70 14 14 // 15 15 … … 22 22 23 23 #include "Common/utility.h" // for maybeClone, cloneAll, deleteAll 24 #include "Declaration.h" // for ObjectDecl, DeclarationWithType25 24 #include "Expression.h" // for Expression, ImplicitCopyCtorExpr 26 25 #include "InitTweak/InitTweak.h" // for getCallArg, getPointerBase … … 294 293 } 295 294 296 KeywordCastExpr::KeywordCastExpr( Expression * arg, Targettarget ) : Expression(), arg(arg), target( target ) {295 KeywordCastExpr::KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ) : Expression(), arg(arg), target( target ) { 297 296 } 298 297 … … 304 303 } 305 304 306 const std::string & KeywordCastExpr::targetString() const { 307 static const std::string targetStrs[] = { 308 "coroutine", "thread", "monitor" 309 }; 310 static_assert( 311 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 312 "Each KeywordCastExpr::Target should have a corresponding string representation" 313 ); 314 return targetStrs[(unsigned long)target]; 305 const char * KeywordCastExpr::targetString() const { 306 return AggregateDecl::aggrString( target ); 315 307 } 316 308 -
src/SynTree/Expression.h
r98d6965d r312029a 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 : Thr Aug 15 13:46:00201913 // Update Count : 5411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:50:19 2019 13 // Update Count : 60 14 14 // 15 15 … … 28 28 #include "Label.h" // for Label 29 29 #include "Mutator.h" // for Mutator 30 #include "Declaration.h" // for Aggregate 30 31 #include "SynTree.h" // for UniqueId 31 32 #include "Visitor.h" // for Visitor … … 229 230 public: 230 231 Expression * arg; 231 enum Target {232 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS233 };234 232 struct Concrete { 235 233 std::string field; 236 234 std::string getter; 237 235 }; 238 Targettarget;236 AggregateDecl::Aggregate target; 239 237 Concrete concrete_target; 240 238 241 KeywordCastExpr( Expression * arg, Targettarget );239 KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ); 242 240 KeywordCastExpr( const KeywordCastExpr & other ); 243 241 virtual ~KeywordCastExpr(); 244 242 245 const std::string &targetString() const;243 const char * targetString() const; 246 244 247 245 virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); } -
src/SynTree/FunctionDecl.cc
r98d6965d r312029a 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 08:33:41 201713 // Update Count : 7 412 // Last Modified On : Sat Dec 7 17:40:09 2019 13 // Update Count : 75 14 14 // 15 15 … … 23 23 #include "Common/utility.h" // for maybeClone, printAll 24 24 #include "Declaration.h" // for FunctionDecl, FunctionDecl::Parent 25 #include "Expression.h" 25 26 #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall 26 27 #include "Statement.h" // for CompoundStmt -
src/SynTree/NamedTypeDecl.cc
r98d6965d r312029a 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 : Wed Aug 9 13:28:00 201713 // Update Count : 1 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 08:26:17 2019 13 // Update Count : 15 14 14 // 15 15 … … 78 78 } 79 79 80 std::stringTypedefDecl::typeString() const { return "typedef"; }80 const char * TypedefDecl::typeString() const { return "typedef"; } 81 81 82 82 // Local Variables: // -
src/SynTree/TypeDecl.cc
r98d6965d r312029a 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 : Wed Aug 9 14:35:00 201713 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 17:56:30 2019 13 // Update Count : 10 14 14 // 15 15 … … 18 18 19 19 #include "Common/utility.h" // for maybeClone 20 #include "Parser/ParseNode.h" 20 21 #include "Declaration.h" // for TypeDecl, TypeDecl::Data, TypeDecl::Kind... 21 22 #include "Type.h" // for Type, Type::StorageClasses … … 31 32 } 32 33 33 std::stringTypeDecl::typeString() const {34 static const std::string kindNames[] = { "object type", "function type", "tuple type" };34 const char * TypeDecl::typeString() const { 35 static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" }; 35 36 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "typeString: kindNames is out of sync." ); 36 37 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); 37 return (isComplete() ? "sized " : "") + kindNames[ kind ];38 return isComplete() ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0' 38 39 } 39 40 40 std::stringTypeDecl::genTypeString() const {41 static const std::stringkindNames[] = { "dtype", "ftype", "ttype" };41 const char * TypeDecl::genTypeString() const { 42 static const char * kindNames[] = { "dtype", "ftype", "ttype" }; 42 43 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." ); 43 44 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
Note:
See TracChangeset
for help on using the changeset viewer.