Changes in / [1531ef5:cdcd53dc]
- Location:
- src/AST
- Files:
-
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
r1531ef5 rcdcd53dc 14 14 // 15 15 16 #include <cassert> // for assert, strict_dynamic_cast 17 #include <unordered_map> 18 16 19 #include "Decl.hpp" 17 20 18 #include <cassert> // for assert, strict_dynamic_cast 19 #include <string> 20 #include <unordered_map> 21 22 #include "Fwd.hpp" // for UniqueId 21 #include "Fwd.hpp" // for UniqueId 23 22 #include "Init.hpp" 24 #include "Node.hpp" // for readonly 25 #include "Parser/ParseNode.h" // for DeclarationNode 23 #include "Node.hpp" // for readonly 26 24 27 25 namespace ast { … … 43 41 if ( i != idMap.end() ) return i->second; 44 42 return {}; 45 }46 47 // --- TypeDecl48 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 ];62 43 } 63 44 -
src/AST/Decl.hpp
r1531ef5 rcdcd53dc 115 115 }; 116 116 117 /// Base class for named type aliases118 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 alias129 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 dtype139 enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS } kind;140 bool sized;141 ptr<Type> init;142 143 /// Data extracted from a type decl144 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 code166 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 187 117 /// Aggregate type declaration base class 188 118 class AggregateDecl : public Decl { -
src/AST/Init.hpp
r1531ef5 rcdcd53dc 1 //2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo3 //4 // The contents of this file are covered under the licence agreement in the5 // file "LICENCE" distributed with Cforall.6 //7 // Init.hpp --8 //9 // Author : Aaron B. Moss10 // Created On : Fri May 10 10:30:00 201911 // Last Modified By : Aaron B. Moss12 // Created On : Fri May 10 10:30:00 201913 // Update Count : 114 //15 16 #pragma once17 18 #include <utility> // for move19 #include <vector>20 21 #include "ParseNode.hpp"22 #include "Node.hpp" // for ptr23 #include "Visitor.hpp"24 25 namespace ast {26 27 class Expr;28 class Stmt;29 30 /// List of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an31 /// object being initialized32 class Designation final : public ParseNode {33 public:34 std::vector<ptr<Expr>> designators;35 36 Designation( const CodeLocation& loc, std::vector<ptr<Expr>>&& ds = {} )37 : ParseNode( loc ), designators( std::move(ds) ) {}38 39 Designation* accept( Visitor& v ) override { return v.visit( this ); }40 private:41 Designation* clone() const override { return new Designation{ *this }; }42 };43 44 /// Object initializer base class45 class Init : public ParseNode {46 public:47 bool maybeConstructed;48 49 Init( const CodeLocation& loc, bool mc ) : ParseNode( loc ), maybeConstructed( mc ) {}50 51 virtual Init* accept( Visitor& v ) override = 0;52 private:53 virtual Init* clone() const override = 0;54 };55 56 /// Initializer for a common object: `int x = 4`57 class SingleInit final : public Init {58 public:59 /// value to initialize to. Must be compile-time constant.60 ptr<Expr> value;61 62 SingleInit( const CodeLocation& loc, Expr* val, bool mc = false )63 : Init( loc, mc ), value( val ) {}64 65 Init* accept( Visitor& v ) override { return v.visit( this ); }66 private:67 SingleInit* clone() const override { return new SingleInit{ *this }; }68 };69 70 /// Initializer recursively composed of a list of initializers.71 /// Used to initialize an array or aggregate: `int a[] = { 1, 2, 3 }`72 class ListInit final : public Init {73 public:74 /// list of initializers75 std::vector<ptr<Init>> initializers;76 /// list of designators; order/length is consistent with initializers77 std::vector<ptr<Designation>> designations;78 79 ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is,80 std::vector<ptr<Designation>>&& ds = {}, bool mc = false );81 82 using iterator = std::vector<ptr<Init>>::iterator;83 using const_iterator = std::vector<ptr<Init>>::const_iterator;84 iterator begin() { return initializers.begin(); }85 iterator end() { return initializers.end(); }86 const_iterator begin() const { return initializers.begin(); }87 const_iterator end() const { return initializers.end(); }88 89 Init* accept( Visitor& v ) override { return v.visit( this ); }90 private:91 ListInit* clone() const override { return new ListInit{ *this }; }92 };93 94 /// Either a constructor expression or a C-style initializer.95 /// Should not be necessary to create manually; instead set `maybeConstructed` true on `SingleInit`96 /// or `ListInit` if the object should be constructed.97 class ConstructorInit final : public Init {98 public:99 ptr<Stmt> ctor;100 ptr<Stmt> dtor;101 /// C-style initializer made up of SingleInit/ListInit nodes to use as a fallback if an102 /// appropriate constructor definition is not found by the resolver.103 ptr<Init> init;104 105 ConstructorInit( const CodeLocation& loc, Stmt* ctor, Stmt* dtor, Init* init )106 : Init( loc, true ), ctor( ctor ), dtor( dtor ), init( init ) {}107 108 Init* accept( Visitor& v ) override { return v.visit( this ); }109 private:110 ConstructorInit* clone() const override { return new ConstructorInit{ *this }; }111 };112 113 }114 115 // Local Variables: //116 // tab-width: 4 //117 // mode: c++ //118 // compile-command: "make install" //119 // End: // -
src/AST/porting.md
r1531ef5 rcdcd53dc 89 89 * allows `newObject` as just default settings 90 90 91 `TypeDecl`92 * stripped `isComplete()` accessor in favour of direct access to `sized`93 94 91 `EnumDecl` 95 92 * **TODO** rebuild `eval` for new AST (re: `valueOf` implementation)
Note: See TracChangeset
for help on using the changeset viewer.