- Timestamp:
- Dec 11, 2019, 8:52:38 PM (4 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/AST
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r98d6965d r312029a 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jul 25 22:21:46201913 // Update Count : 1312 // Last Modified On : Tue Dec 10 22:20:10 2019 13 // Update Count : 32 14 14 // 15 15 … … 245 245 auto decl = new StructDecl( 246 246 node->name, 247 node->kind,247 (AggregateDecl::Aggregate)node->kind, 248 248 get<Attribute>().acceptL( node->attributes ), 249 249 LinkageSpec::Spec( node->linkage.val ) … … 675 675 676 676 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 677 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS; 678 switch (node->target) { 679 case ast::KeywordCastExpr::Coroutine: 680 castTarget = KeywordCastExpr::Coroutine; 681 break; 682 case ast::KeywordCastExpr::Thread: 683 castTarget = KeywordCastExpr::Thread; 684 break; 685 case ast::KeywordCastExpr::Monitor: 686 castTarget = KeywordCastExpr::Monitor; 687 break; 688 default: 689 break; 690 } 691 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS ); 677 AggregateDecl::Aggregate castTarget = (AggregateDecl::Aggregate)node->target; 678 assert( AggregateDecl::Generator <= castTarget && castTarget <= AggregateDecl::Thread ); 692 679 auto expr = visitBaseExpr( node, 693 680 new KeywordCastExpr( … … 1504 1491 old->location, 1505 1492 old->name, 1506 old->kind,1493 (ast::AggregateDecl::Aggregate)old->kind, 1507 1494 GET_ACCEPT_V(attributes, Attribute), 1508 1495 { old->linkage.val } … … 2045 2032 } 2046 2033 2047 virtual void visit( const KeywordCastExpr * old) override final { 2048 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS; 2049 switch (old->target) { 2050 case KeywordCastExpr::Coroutine: 2051 castTarget = ast::KeywordCastExpr::Coroutine; 2052 break; 2053 case KeywordCastExpr::Thread: 2054 castTarget = ast::KeywordCastExpr::Thread; 2055 break; 2056 case KeywordCastExpr::Monitor: 2057 castTarget = ast::KeywordCastExpr::Monitor; 2058 break; 2059 default: 2060 break; 2061 } 2062 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS ); 2034 virtual void visit( const KeywordCastExpr * old ) override final { 2035 ast::AggregateDecl::Aggregate castTarget = (ast::AggregateDecl::Aggregate)old->target; 2036 assert( ast::AggregateDecl::Generator <= castTarget && castTarget <= ast::AggregateDecl::Thread ); 2063 2037 this->node = visitBaseExpr( old, 2064 2038 new ast::KeywordCastExpr( -
src/AST/Decl.cpp
r98d6965d r312029a 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu May 9 10:00:00201913 // Update Count : 1 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:41:39 2019 13 // Update Count : 18 14 14 // 15 15 … … 18 18 #include <cassert> // for assert, strict_dynamic_cast 19 19 #include <iostream> 20 #include <string>21 20 #include <unordered_map> 22 21 … … 56 55 // --- TypeDecl 57 56 58 std::stringTypeDecl::typeString() const {59 static const std::string kindNames[] = { "object type", "function type", "tuple type" };57 const char * TypeDecl::typeString() const { 58 static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" }; 60 59 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, 61 60 "typeString: kindNames is out of sync." ); 62 61 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); 63 return (sized ? "sized " : "") + kindNames[ kind ];62 return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0' 64 63 } 65 64 66 std::stringTypeDecl::genTypeString() const {67 static const std::stringkindNames[] = { "dtype", "ftype", "ttype" };65 const char * TypeDecl::genTypeString() const { 66 static const char * kindNames[] = { "dtype", "ftype", "ttype" }; 68 67 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." ); 69 68 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); … … 73 72 std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) { 74 73 return out << data.kind << ", " << data.isComplete; 74 } 75 76 // --- AggregateDecl 77 78 // These must harmonize with the corresponding AggregateDecl::Aggregate enumerations. 79 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" }; 80 81 const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) { 82 return aggregateNames[aggr]; 75 83 } 76 84 -
src/AST/Decl.hpp
r98d6965d r312029a 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu May 9 10:00:00 201913 // Update Count : 1 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 08:20:20 2019 13 // Update Count : 16 14 14 // 15 15 … … 154 154 155 155 /// Produces a name for the kind of alias 156 virtual std::stringtypeString() const = 0;156 virtual const char * typeString() const = 0; 157 157 158 158 private: … … 190 190 init( i ) {} 191 191 192 std::stringtypeString() const override;192 const char * typeString() const override; 193 193 /// Produces a name for generated code 194 std::stringgenTypeString() const;194 const char * genTypeString() const; 195 195 196 196 /// convenience accessor to match Type::isComplete() … … 212 212 : NamedTypeDecl( loc, name, storage, b, spec ) {} 213 213 214 std::stringtypeString() const override { return "typedef"; }214 const char * typeString() const override { return "typedef"; } 215 215 216 216 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } … … 223 223 class AggregateDecl : public Decl { 224 224 public: 225 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate }; 226 static const char * aggrString( Aggregate aggr ); 227 225 228 std::vector<ptr<Decl>> members; 226 229 std::vector<ptr<TypeDecl>> params; … … 237 240 238 241 /// Produces a name for the kind of aggregate 239 virtual std::stringtypeString() const = 0;242 virtual const char * typeString() const = 0; 240 243 241 244 private: … … 247 250 class StructDecl final : public AggregateDecl { 248 251 public: 249 DeclarationNode::Aggregate kind;252 Aggregate kind; 250 253 251 254 StructDecl( const CodeLocation& loc, const std::string& name, 252 DeclarationNode::Aggregate kind = DeclarationNode::Struct,255 Aggregate kind = Struct, 253 256 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall ) 254 257 : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {} 255 258 256 bool is_coroutine() { return kind == DeclarationNode::Coroutine; }257 bool is_monitor() { return kind == DeclarationNode::Monitor; }258 bool is_thread() { return kind == DeclarationNode::Thread; }259 260 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 261 262 std::string typeString() const override { return "struct"; }259 bool is_coroutine() { return kind == Coroutine; } 260 bool is_monitor() { return kind == Monitor; } 261 bool is_thread() { return kind == Thread; } 262 263 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 264 265 const char * typeString() const override { return aggrString( kind ); } 263 266 264 267 private: … … 276 279 const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 277 280 278 std::string typeString() const override { return "union"; }281 const char * typeString() const override { return aggrString( Union ); } 279 282 280 283 private: … … 295 298 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 296 299 297 std::string typeString() const override { return "enum"; }300 const char * typeString() const override { return aggrString( Enum ); } 298 301 299 302 private: … … 314 317 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 315 318 316 std::stringtypeString() const override { return "trait"; }319 const char * typeString() const override { return "trait"; } 317 320 318 321 private: -
src/AST/Expr.cpp
r98d6965d r312029a 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 15 17:00:00 2019 11 // Last Modified By : Andrew Beach11 // Last Modified By : Peter A. Buhr 12 12 // Created On : Thr Jun 13 13:38:00 2019 13 // Update Count : 213 // Update Count : 6 14 14 // 15 15 … … 141 141 // --- KeywordCastExpr 142 142 143 const std::string & KeywordCastExpr::targetString() const { 144 static const std::string targetStrs[] = { 145 "coroutine", "thread", "monitor" 146 }; 147 static_assert( 148 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 149 "Each KeywordCastExpr::Target should have a corresponding string representation" 150 ); 151 return targetStrs[(unsigned long)target]; 143 const char * KeywordCastExpr::targetString() const { 144 return AggregateDecl::aggrString( target ); 152 145 } 153 146 -
src/AST/Expr.hpp
r98d6965d r312029a 9 9 // Author : Aaron B. Moss 10 10 // Created On : Fri May 10 10:30:00 2019 11 // Last Modified By : Aaron B. Moss11 // Last Modified By : Peter A. Buhr 12 12 // Created On : Fri May 10 10:30:00 2019 13 // Update Count : 113 // Update Count : 7 14 14 // 15 15 … … 26 26 #include "Fwd.hpp" // for UniqueId 27 27 #include "Label.hpp" 28 #include "Decl.hpp" 28 29 #include "ParseNode.hpp" 29 30 #include "Visitor.hpp" … … 300 301 public: 301 302 ptr<Expr> arg; 302 enum Target { Coroutine, Thread, Monitor, NUMBER_OF_TARGETS }target;303 304 KeywordCastExpr( const CodeLocation & loc, const Expr * a, Targett )303 ast::AggregateDecl::Aggregate target; 304 305 KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t ) 305 306 : Expr( loc ), arg( a ), target( t ) {} 306 307 307 308 /// Get a name for the target type 308 const std::string&targetString() const;309 const char * targetString() const; 309 310 310 311 const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
Note: See TracChangeset
for help on using the changeset viewer.