Changeset 360b2e13
- Timestamp:
- May 10, 2019, 2:28:54 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7e89526, b96d7c1
- Parents:
- 9131e54
- Location:
- src/AST
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
r9131e54 r360b2e13 14 14 // 15 15 16 #include <cassert> // for assert, strict_dynamic_cast 16 #include "Decl.hpp" 17 18 #include <cassert> // for assert, strict_dynamic_cast 19 #include <string> 17 20 #include <unordered_map> 18 21 19 #include "Decl.hpp" 20 21 #include "Fwd.hpp" // for UniqueId 22 #include "Fwd.hpp" // for UniqueId 22 23 #include "Init.hpp" 23 #include "Node.hpp" // for readonly 24 #include "Node.hpp" // for readonly 25 #include "Parser/ParseNode.h" // for DeclarationNode 24 26 25 27 namespace ast { … … 41 43 if ( i != idMap.end() ) return i->second; 42 44 return {}; 45 } 46 47 // --- TypeDecl 48 49 std::string TypeDecl::typeString() const { 50 static const std::string kindNames[] = { "object type", "function type", "tuple type" }; 51 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, 52 "typeString: kindNames is out of sync." ); 53 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); 54 return (sized ? "sized " : "") + kindNames[ kind ]; 55 } 56 57 std::string TypeDecl::genTypeString() const { 58 static const std::string kindNames[] = { "dtype", "ftype", "ttype" }; 59 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." ); 60 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); 61 return kindNames[ kind ]; 43 62 } 44 63 -
src/AST/Decl.hpp
r9131e54 r360b2e13 115 115 }; 116 116 117 /// Base class for named type aliases 118 class NamedTypeDecl : public Decl { 119 public: 120 ptr<Type> base; 121 std::vector<ptr<TypeDecl>> parameters; 122 std::vector<ptr<DeclWithType>> assertions; 123 124 NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 125 Type* b, Linkage::Spec spec = Linkage::Cforall ) 126 : Decl( loc, name, storage, spec ), base( b ), parameters(), assertions() {} 127 128 /// Produces a name for the kind of alias 129 virtual std::string typeString() const = 0; 130 131 private: 132 NamedTypeDecl* clone() const override = 0; 133 }; 134 135 /// Cforall type variable: `dtype T` 136 class TypeDecl final : public NamedTypeDecl { 137 public: 138 /// type variable variants. otype is a specialized dtype 139 enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS } kind; 140 bool sized; 141 ptr<Type> init; 142 143 /// Data extracted from a type decl 144 struct Data { 145 Kind kind; 146 bool isComplete; 147 148 Data() : kind( (Kind)-1 ), isComplete( false ) {} 149 Data( TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {} 150 Data( Kind k, bool c ) : kind( k ), isComplete( c ) {} 151 Data( const Data& d1, const Data& d2 ) 152 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 153 154 bool operator== ( const Data& o ) const { 155 return kind == o.kind && isComplete == o.isComplete; 156 } 157 bool operator!= ( const Data& o ) const { return !(*this == o); } 158 }; 159 160 TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b, 161 Kind k, bool s, Type* i = nullptr ) 162 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == Ttype || s ), init( i ) {} 163 164 std::string typeString() const override; 165 /// Produces a name for generated code 166 std::string genTypeString() const; 167 168 Decl* accept( Visitor& v ) override { return v.visit( this ); } 169 private: 170 TypeDecl* clone() const override { return new TypeDecl{ *this }; } 171 }; 172 173 /// C-style typedef `typedef Foo Bar` 174 class TypedefDecl final : public NamedTypeDecl { 175 public: 176 TypedefDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 177 Type* b, Linkage::Spec spec = Linkage::Cforall ) 178 : NamedTypeDecl( loc, name, storage, b, spec ) {} 179 180 std::string typeString() const override { return "typedef"; } 181 182 Decl* accept( Visitor& v ) override { return v.visit( this ); } 183 private: 184 TypedefDecl* clone() const override { return new TypedefDecl{ *this }; } 185 }; 186 117 187 /// Aggregate type declaration base class 118 188 class AggregateDecl : public Decl { -
src/AST/porting.md
r9131e54 r360b2e13 89 89 * allows `newObject` as just default settings 90 90 91 `TypeDecl` 92 * stripped `isComplete()` accessor in favour of direct access to `sized` 93 91 94 `EnumDecl` 92 95 * **TODO** rebuild `eval` for new AST (re: `valueOf` implementation)
Note: See TracChangeset
for help on using the changeset viewer.