source: src/SynTree/Declaration.h @ 02c7d04

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 02c7d04 was 974906e2, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

propagate maybeConstructed flag through system, begin create constructor/destructor statements for further processing by Resolver

  • Property mode set to 100644
File size: 9.6 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[974906e2]7// Declaration.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[baf7fee]11// Last Modified By : Rob Schluntz
[974906e2]12// Last Modified On : Thu Jan 07 14:48:44 2016
13// Update Count     : 34
[0dd3a2f]14//
15
[51b7345]16#ifndef DECLARATION_H
17#define DECLARATION_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22#include "Parser/LinkageSpec.h"
[68cd1ce]23#include "Parser/ParseNode.h"
[51b7345]24
[17cd4eb]25class Declaration {
26  public:
[68cd1ce]27        Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
[0dd3a2f]28        Declaration( const Declaration &other );
29        virtual ~Declaration();
30
[5f2f2d7]31        const std::string &get_name() const { return name; }
[0dd3a2f]32        void set_name( std::string newValue ) { name = newValue; }
[68cd1ce]33        DeclarationNode::StorageClass get_storageClass() const { return storageClass; }
34        void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; }
[0dd3a2f]35        LinkageSpec::Type get_linkage() const { return linkage; }
36        void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
[1db21619]37        bool get_isInline() const { return isInline; }
38        void set_isInline( bool newValue ) { isInline = newValue; }
39        bool get_isNoreturn() const { return isNoreturn; }
40        void set_isNoreturn( bool newValue ) { isNoreturn = newValue; }
[0dd3a2f]41        UniqueId get_uniqueId() const { return uniqueId; }
42
43        void fixUniqueId( void );
44        virtual Declaration *clone() const = 0;
45        virtual void accept( Visitor &v ) = 0;
46        virtual Declaration *acceptMutator( Mutator &m ) = 0;
47        virtual void print( std::ostream &os, int indent = 0 ) const = 0;
48        virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
49
50        static void dumpIds( std::ostream &os );
51        static Declaration *declFromId( UniqueId id );
[17cd4eb]52  private:
[0dd3a2f]53        std::string name;
[68cd1ce]54        DeclarationNode::StorageClass storageClass;
[0dd3a2f]55        LinkageSpec::Type linkage;
[1db21619]56        bool isInline, isNoreturn;
[0dd3a2f]57        UniqueId uniqueId;
[51b7345]58};
59
[17cd4eb]60class DeclarationWithType : public Declaration {
61  public:
[68cd1ce]62        DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
[0dd3a2f]63        DeclarationWithType( const DeclarationWithType &other );
64        virtual ~DeclarationWithType();
[51b7345]65
[0dd3a2f]66        std::string get_mangleName() const { return mangleName; }
67        void set_mangleName( std::string newValue ) { mangleName = newValue; }
[17cd4eb]68
[0dd3a2f]69        virtual DeclarationWithType *clone() const = 0;
70        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
[17cd4eb]71
[0dd3a2f]72        virtual Type *get_type() const = 0;
73        virtual void set_type(Type *) = 0;
[17cd4eb]74  private:
[0dd3a2f]75        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
76        std::string mangleName;
[51b7345]77};
78
[17cd4eb]79class ObjectDecl : public DeclarationWithType {
[0dd3a2f]80        typedef DeclarationWithType Parent;
[17cd4eb]81  public:
[1db21619]82        ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline = false, bool isNoreturn = false );
[0dd3a2f]83        ObjectDecl( const ObjectDecl &other );
84        virtual ~ObjectDecl();
85
86        virtual Type *get_type() const { return type; }
87        virtual void set_type(Type *newType) { type = newType; }
88
89        Initializer *get_init() const { return init; }
90        void set_init( Initializer *newValue ) { init = newValue; }
91        Expression *get_bitfieldWidth() const { return bitfieldWidth; }
92        void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
[974906e2]93        ExprStmt * get_ctor() const { return ctor; }
94        void set_ctor( ExprStmt * newValue ) { ctor = newValue; }
[0dd3a2f]95
96        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
97        virtual void accept( Visitor &v ) { v.visit( this ); }
[1db21619]98        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[0dd3a2f]99        virtual void print( std::ostream &os, int indent = 0 ) const;
100        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]101  private:
[0dd3a2f]102        Type *type;
103        Initializer *init;
104        Expression *bitfieldWidth;
[974906e2]105        ExprStmt * ctor;
[51b7345]106};
107
[17cd4eb]108class FunctionDecl : public DeclarationWithType {
[0dd3a2f]109        typedef DeclarationWithType Parent;
[17cd4eb]110  public:
[de62360d]111        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn );
[0dd3a2f]112        FunctionDecl( const FunctionDecl &other );
113        virtual ~FunctionDecl();
[51b7345]114
[0dd3a2f]115        Type *get_type() const;
116        virtual void set_type(Type *);
[51b7345]117
[0dd3a2f]118        FunctionType *get_functionType() const { return type; }
119        void set_functionType( FunctionType *newValue ) { type = newValue; }
120        CompoundStmt *get_statements() const { return statements; }
121        void set_statements( CompoundStmt *newValue ) { statements = newValue; }
122        std::list< std::string >& get_oldIdents() { return oldIdents; }
123        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
124
125        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
126        virtual void accept( Visitor &v ) { v.visit( this ); }
127        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
128        virtual void print( std::ostream &os, int indent = 0 ) const;
129        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]130  private:
[0dd3a2f]131        FunctionType *type;
132        CompoundStmt *statements;
133        std::list< std::string > oldIdents;
134        std::list< Declaration* > oldDecls;
[51b7345]135};
136
[17cd4eb]137class NamedTypeDecl : public Declaration {
[0dd3a2f]138        typedef Declaration Parent;
[17cd4eb]139  public:
[68cd1ce]140        NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
[0dd3a2f]141        NamedTypeDecl( const TypeDecl &other );
142        virtual ~NamedTypeDecl();
143
144        Type *get_base() const { return base; }
145        void set_base( Type *newValue ) { base = newValue; }
146        std::list< TypeDecl* >& get_parameters() { return parameters; }
147        std::list< DeclarationWithType* >& get_assertions() { return assertions; }
148
149        virtual NamedTypeDecl *clone() const = 0;
150        virtual void print( std::ostream &os, int indent = 0 ) const;
151        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]152  protected:
[0dd3a2f]153        virtual std::string typeString() const = 0;
[17cd4eb]154  private:
[0dd3a2f]155        Type *base;
156        std::list< TypeDecl* > parameters;
157        std::list< DeclarationWithType* > assertions;
[51b7345]158};
159
[17cd4eb]160class TypeDecl : public NamedTypeDecl {
[0dd3a2f]161        typedef NamedTypeDecl Parent;
[17cd4eb]162  public:
[0dd3a2f]163        enum Kind { Any, Dtype, Ftype };
[51b7345]164
[68cd1ce]165        TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
[0dd3a2f]166        TypeDecl( const TypeDecl &other );
[17cd4eb]167
[0dd3a2f]168        Kind get_kind() const { return kind; }
[51b7345]169
[0dd3a2f]170        virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
171        virtual void accept( Visitor &v ) { v.visit( this ); }
172        virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]173  private:
[0dd3a2f]174        virtual std::string typeString() const;
175        Kind kind;
[51b7345]176};
177
[17cd4eb]178class TypedefDecl : public NamedTypeDecl {
[0dd3a2f]179        typedef NamedTypeDecl Parent;
[17cd4eb]180  public:
[68cd1ce]181        TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
[0dd3a2f]182        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
[17cd4eb]183
[0dd3a2f]184        virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
185        virtual void accept( Visitor &v ) { v.visit( this ); }
186        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]187  private:
[0dd3a2f]188        virtual std::string typeString() const;
[51b7345]189};
190
[17cd4eb]191class AggregateDecl : public Declaration {
[0dd3a2f]192        typedef Declaration Parent;
[17cd4eb]193  public:
[0dd3a2f]194        AggregateDecl( const std::string &name );
195        AggregateDecl( const AggregateDecl &other );
196        virtual ~AggregateDecl();
[51b7345]197
[0dd3a2f]198        std::list<Declaration*>& get_members() { return members; }
199        std::list<TypeDecl*>& get_parameters() { return parameters; }
[17cd4eb]200
[0dd3a2f]201        virtual void print( std::ostream &os, int indent = 0 ) const;
202        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]203  protected:
[0dd3a2f]204        virtual std::string typeString() const = 0;
[17cd4eb]205
206  private:
[0dd3a2f]207        std::list<Declaration*> members;
208        std::list<TypeDecl*> parameters;
[51b7345]209};
210
[17cd4eb]211class StructDecl : public AggregateDecl {
[0dd3a2f]212        typedef AggregateDecl Parent;
[17cd4eb]213  public:
[0dd3a2f]214        StructDecl( const std::string &name ) : Parent( name ) {}
215        StructDecl( const StructDecl &other ) : Parent( other ) {}
[17cd4eb]216
[0dd3a2f]217        virtual StructDecl *clone() const { return new StructDecl( *this ); }
218        virtual void accept( Visitor &v ) { v.visit( this ); }
219        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[51b7345]220
[17cd4eb]221  private:
[0dd3a2f]222        virtual std::string typeString() const;
[51b7345]223};
224
[17cd4eb]225class UnionDecl : public AggregateDecl {
[0dd3a2f]226        typedef AggregateDecl Parent;
[17cd4eb]227  public:
[0dd3a2f]228        UnionDecl( const std::string &name ) : Parent( name ) {}
229        UnionDecl( const UnionDecl &other ) : Parent( other ) {}
[17cd4eb]230
[0dd3a2f]231        virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
232        virtual void accept( Visitor &v ) { v.visit( this ); }
233        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]234  private:
[0dd3a2f]235        virtual std::string typeString() const;
[51b7345]236};
237
[17cd4eb]238class EnumDecl : public AggregateDecl {
[0dd3a2f]239        typedef AggregateDecl Parent;
[17cd4eb]240  public:
[0dd3a2f]241        EnumDecl( const std::string &name ) : Parent( name ) {}
242        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
[17cd4eb]243
[0dd3a2f]244        virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
245        virtual void accept( Visitor &v ) { v.visit( this ); }
246        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]247  private:
[0dd3a2f]248        virtual std::string typeString() const;
[51b7345]249};
250
[17cd4eb]251class ContextDecl : public AggregateDecl {
[0dd3a2f]252        typedef AggregateDecl Parent;
[17cd4eb]253  public:
[0dd3a2f]254        ContextDecl( const std::string &name ) : Parent( name ) {}
255        ContextDecl( const ContextDecl &other ) : Parent( other ) {}
[17cd4eb]256
[0dd3a2f]257        virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
258        virtual void accept( Visitor &v ) { v.visit( this ); }
259        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]260  private:
[0dd3a2f]261        virtual std::string typeString() const;
[51b7345]262};
263
[baf7fee]264std::ostream & operator<<( std::ostream & out, Declaration * decl );
265
[17cd4eb]266#endif // DECLARATION_H
[0dd3a2f]267
268// Local Variables: //
269// tab-width: 4 //
270// mode: c++ //
271// compile-command: "make install" //
272// End: //
Note: See TracBrowser for help on using the repository browser.