Changeset 1531ef5 for src/AST/Decl.hpp


Ignore:
Timestamp:
May 10, 2019, 3:26:26 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
18d4dbd, 4ab0669, b78129a
Parents:
cdcd53dc (diff), 7e89526 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    rcdcd53dc r1531ef5  
    115115};
    116116
     117/// Base class for named type aliases
     118class NamedTypeDecl : public Decl {
     119public:
     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
     131private:
     132        NamedTypeDecl* clone() const override = 0;
     133};
     134
     135/// Cforall type variable: `dtype T`
     136class TypeDecl final : public NamedTypeDecl {
     137public:
     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 ); }
     169private:
     170        TypeDecl* clone() const override { return new TypeDecl{ *this }; }
     171};
     172
     173/// C-style typedef `typedef Foo Bar`
     174class TypedefDecl final : public NamedTypeDecl {
     175public:
     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 ); }
     183private:
     184        TypedefDecl* clone() const override { return new TypedefDecl{ *this }; }
     185};
     186
    117187/// Aggregate type declaration base class
    118188class AggregateDecl : public Decl {
Note: See TracChangeset for help on using the changeset viewer.