Changeset 7030dab for src/AST/Decl.hpp
- Timestamp:
- Apr 6, 2020, 4:46:28 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e3bc51c
- Parents:
- 71d6bd8 (diff), 057298e (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.hpp
r71d6bd8 r7030dab 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 : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 17:38:33 2019 13 // Update Count : 29 14 14 // 15 15 … … 20 20 #include <unordered_map> 21 21 #include <vector> 22 #include <algorithm> 22 23 23 24 #include "FunctionSpec.hpp" … … 27 28 #include "ParseNode.hpp" 28 29 #include "StorageClasses.hpp" 29 #include "TypeVar.hpp"30 30 #include "Visitor.hpp" 31 #include "Parser/ParseNode.h" // for DeclarationNode::Aggregate 31 #include "Common/utility.h" 32 #include "Common/SemanticError.h" // error_str 32 33 33 34 // Must be included in *all* AST classes; should be #undef'd at the end of the file … … 127 128 std::vector< ptr<Expr> > withExprs; 128 129 129 FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,130 FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type, 130 131 CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, 131 132 std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}) … … 138 139 bool has_body() const { return stmts; } 139 140 140 const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }141 const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); } 141 142 private: 142 143 FunctionDecl * clone() const override { return new FunctionDecl( *this ); } … … 151 152 std::vector<ptr<DeclWithType>> assertions; 152 153 153 NamedTypeDecl( 154 NamedTypeDecl( 154 155 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 155 156 const Type * b, Linkage::Spec spec = Linkage::Cforall ) … … 157 158 158 159 /// Produces a name for the kind of alias 159 virtual std::stringtypeString() const = 0;160 virtual const char * typeString() const = 0; 160 161 161 162 private: … … 166 167 /// Cforall type variable: `dtype T` 167 168 class TypeDecl final : public NamedTypeDecl { 168 public: 169 TypeVar::Kind kind; 169 public: 170 enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS }; 171 172 Kind kind; 170 173 bool sized; 171 174 ptr<Type> init; … … 173 176 /// Data extracted from a type decl 174 177 struct Data { 175 TypeVar::Kind kind;178 Kind kind; 176 179 bool isComplete; 177 180 178 Data() : kind( (TypeVar::Kind)-1), isComplete( false ) {}181 Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {} 179 182 Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {} 180 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}183 Data( Kind k, bool c ) : kind( k ), isComplete( c ) {} 181 184 Data( const Data & d1, const Data & d2 ) 182 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 183 184 bool operator== ( const Data & o ) const { 185 return kind == o.kind && isComplete == o.isComplete; 186 } 187 bool operator!= ( const Data & o ) const { return !(*this == o); } 185 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 186 187 bool operator==( const Data & o ) const { return kind == o.kind && isComplete == o.isComplete; } 188 bool operator!=( const Data & o ) const { return !(*this == o); } 188 189 }; 189 190 190 TypeDecl( 191 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 191 TypeDecl( 192 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 192 193 const Type * b, TypeVar::Kind k, bool s, const Type * i = nullptr ) 193 194 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ), 194 195 init( i ) {} 195 196 196 std::stringtypeString() const override;197 const char * typeString() const override; 197 198 /// Produces a name for generated code 198 std::stringgenTypeString() const;199 const char * genTypeString() const; 199 200 200 201 /// convenience accessor to match Type::isComplete() … … 202 203 203 204 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 204 private:205 private: 205 206 TypeDecl * clone() const override { return new TypeDecl{ *this }; } 206 207 MUTATE_FRIEND … … 216 217 : NamedTypeDecl( loc, name, storage, b, spec ) {} 217 218 218 std::stringtypeString() const override { return "typedef"; }219 const char * typeString() const override { return "typedef"; } 219 220 220 221 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } … … 227 228 class AggregateDecl : public Decl { 228 229 public: 230 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate }; 231 static const char * aggrString( Aggregate aggr ); 232 229 233 std::vector<ptr<Decl>> members; 230 234 std::vector<ptr<TypeDecl>> params; … … 241 245 242 246 /// Produces a name for the kind of aggregate 243 virtual std::stringtypeString() const = 0;247 virtual const char * typeString() const = 0; 244 248 245 249 private: … … 251 255 class StructDecl final : public AggregateDecl { 252 256 public: 253 DeclarationNode::Aggregate kind;257 Aggregate kind; 254 258 255 259 StructDecl( const CodeLocation& loc, const std::string& name, 256 DeclarationNode::Aggregate kind = DeclarationNode::Struct,260 Aggregate kind = Struct, 257 261 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall ) 258 262 : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {} 259 263 260 bool is_coroutine() { return kind == DeclarationNode::Coroutine; } 261 bool is_monitor() { return kind == DeclarationNode::Monitor; } 262 bool is_thread() { return kind == DeclarationNode::Thread; } 263 264 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 265 266 std::string typeString() const override { return "struct"; } 264 bool is_coroutine() { return kind == Coroutine; } 265 bool is_generator() { return kind == Generator; } 266 bool is_monitor () { return kind == Monitor ; } 267 bool is_thread () { return kind == Thread ; } 268 269 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 270 271 const char * typeString() const override { return aggrString( kind ); } 267 272 268 273 private: … … 280 285 const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 281 286 282 std::string typeString() const override { return "union"; }287 const char * typeString() const override { return aggrString( Union ); } 283 288 284 289 private: … … 299 304 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 300 305 301 std::string typeString() const override { return "enum"; }306 const char * typeString() const override { return aggrString( Enum ); } 302 307 303 308 private: … … 318 323 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 319 324 320 std::stringtypeString() const override { return "trait"; }325 const char * typeString() const override { return "trait"; } 321 326 322 327 private: … … 344 349 ptr<AsmStmt> stmt; 345 350 346 AsmDecl( const CodeLocation & loc, AsmStmt * stmt )351 AsmDecl( const CodeLocation & loc, AsmStmt * stmt ) 347 352 : Decl( loc, "", {}, {} ), stmt(stmt) {} 348 353 349 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }350 private: 351 AsmDecl * clone() const override { return new AsmDecl( *this ); }354 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); } 355 private: 356 AsmDecl * clone() const override { return new AsmDecl( *this ); } 352 357 MUTATE_FRIEND 353 358 }; … … 361 366 : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {} 362 367 363 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }368 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); } 364 369 private: 365 370 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
Note: See TracChangeset
for help on using the changeset viewer.