source: src/SynTree/Declaration.h @ 4e24610

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 4e24610 was 4e24610, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Add constructor attribute to global initializer function, don't try to fix const globals, add Constructor/Destructor? attributes to FunctionDecl?

  • Property mode set to 100644
File size: 9.8 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//
[4e24610]7// Declaration.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[4e24610]11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri May 06 11:16:45 2016
[4040425]13// Update Count     : 33
[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; }
93
94        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
95        virtual void accept( Visitor &v ) { v.visit( this ); }
[1db21619]96        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[0dd3a2f]97        virtual void print( std::ostream &os, int indent = 0 ) const;
98        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]99  private:
[0dd3a2f]100        Type *type;
101        Initializer *init;
102        Expression *bitfieldWidth;
[51b7345]103};
104
[17cd4eb]105class FunctionDecl : public DeclarationWithType {
[0dd3a2f]106        typedef DeclarationWithType Parent;
[17cd4eb]107  public:
[4e24610]108        // temporary - merge this into general GCC attributes
109        enum Attribute {
110                NoAttribute, Constructor, Destructor,
111        };
112
113        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = NoAttribute );
[0dd3a2f]114        FunctionDecl( const FunctionDecl &other );
115        virtual ~FunctionDecl();
[51b7345]116
[0dd3a2f]117        Type *get_type() const;
118        virtual void set_type(Type *);
[51b7345]119
[0dd3a2f]120        FunctionType *get_functionType() const { return type; }
121        void set_functionType( FunctionType *newValue ) { type = newValue; }
122        CompoundStmt *get_statements() const { return statements; }
123        void set_statements( CompoundStmt *newValue ) { statements = newValue; }
124        std::list< std::string >& get_oldIdents() { return oldIdents; }
125        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
[4e24610]126        Attribute get_attribute() const { return attribute; }
127        void set_attribute( Attribute newValue ) { attribute = newValue; }
[0dd3a2f]128
129        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
130        virtual void accept( Visitor &v ) { v.visit( this ); }
131        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
132        virtual void print( std::ostream &os, int indent = 0 ) const;
133        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]134  private:
[0dd3a2f]135        FunctionType *type;
136        CompoundStmt *statements;
137        std::list< std::string > oldIdents;
138        std::list< Declaration* > oldDecls;
[4e24610]139        Attribute attribute;
[51b7345]140};
141
[17cd4eb]142class NamedTypeDecl : public Declaration {
[0dd3a2f]143        typedef Declaration Parent;
[17cd4eb]144  public:
[68cd1ce]145        NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
[0dd3a2f]146        NamedTypeDecl( const TypeDecl &other );
147        virtual ~NamedTypeDecl();
148
149        Type *get_base() const { return base; }
150        void set_base( Type *newValue ) { base = newValue; }
151        std::list< TypeDecl* >& get_parameters() { return parameters; }
152        std::list< DeclarationWithType* >& get_assertions() { return assertions; }
153
154        virtual NamedTypeDecl *clone() const = 0;
155        virtual void print( std::ostream &os, int indent = 0 ) const;
156        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]157  protected:
[0dd3a2f]158        virtual std::string typeString() const = 0;
[17cd4eb]159  private:
[0dd3a2f]160        Type *base;
161        std::list< TypeDecl* > parameters;
162        std::list< DeclarationWithType* > assertions;
[51b7345]163};
164
[17cd4eb]165class TypeDecl : public NamedTypeDecl {
[0dd3a2f]166        typedef NamedTypeDecl Parent;
[17cd4eb]167  public:
[0dd3a2f]168        enum Kind { Any, Dtype, Ftype };
[51b7345]169
[68cd1ce]170        TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
[0dd3a2f]171        TypeDecl( const TypeDecl &other );
[17cd4eb]172
[0dd3a2f]173        Kind get_kind() const { return kind; }
[51b7345]174
[0dd3a2f]175        virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
176        virtual void accept( Visitor &v ) { v.visit( this ); }
177        virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]178  private:
[0dd3a2f]179        virtual std::string typeString() const;
180        Kind kind;
[51b7345]181};
182
[17cd4eb]183class TypedefDecl : public NamedTypeDecl {
[0dd3a2f]184        typedef NamedTypeDecl Parent;
[17cd4eb]185  public:
[68cd1ce]186        TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
[0dd3a2f]187        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
[17cd4eb]188
[0dd3a2f]189        virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
190        virtual void accept( Visitor &v ) { v.visit( this ); }
191        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]192  private:
[0dd3a2f]193        virtual std::string typeString() const;
[51b7345]194};
195
[17cd4eb]196class AggregateDecl : public Declaration {
[0dd3a2f]197        typedef Declaration Parent;
[17cd4eb]198  public:
[0dd3a2f]199        AggregateDecl( const std::string &name );
200        AggregateDecl( const AggregateDecl &other );
201        virtual ~AggregateDecl();
[51b7345]202
[0dd3a2f]203        std::list<Declaration*>& get_members() { return members; }
204        std::list<TypeDecl*>& get_parameters() { return parameters; }
[17cd4eb]205
[0dd3a2f]206        virtual void print( std::ostream &os, int indent = 0 ) const;
207        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]208  protected:
[0dd3a2f]209        virtual std::string typeString() const = 0;
[17cd4eb]210
211  private:
[0dd3a2f]212        std::list<Declaration*> members;
213        std::list<TypeDecl*> parameters;
[51b7345]214};
215
[17cd4eb]216class StructDecl : public AggregateDecl {
[0dd3a2f]217        typedef AggregateDecl Parent;
[17cd4eb]218  public:
[0dd3a2f]219        StructDecl( const std::string &name ) : Parent( name ) {}
220        StructDecl( const StructDecl &other ) : Parent( other ) {}
[17cd4eb]221
[0dd3a2f]222        virtual StructDecl *clone() const { return new StructDecl( *this ); }
223        virtual void accept( Visitor &v ) { v.visit( this ); }
224        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[51b7345]225
[17cd4eb]226  private:
[0dd3a2f]227        virtual std::string typeString() const;
[51b7345]228};
229
[17cd4eb]230class UnionDecl : public AggregateDecl {
[0dd3a2f]231        typedef AggregateDecl Parent;
[17cd4eb]232  public:
[0dd3a2f]233        UnionDecl( const std::string &name ) : Parent( name ) {}
234        UnionDecl( const UnionDecl &other ) : Parent( other ) {}
[17cd4eb]235
[0dd3a2f]236        virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
237        virtual void accept( Visitor &v ) { v.visit( this ); }
238        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]239  private:
[0dd3a2f]240        virtual std::string typeString() const;
[51b7345]241};
242
[17cd4eb]243class EnumDecl : public AggregateDecl {
[0dd3a2f]244        typedef AggregateDecl Parent;
[17cd4eb]245  public:
[0dd3a2f]246        EnumDecl( const std::string &name ) : Parent( name ) {}
247        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
[17cd4eb]248
[0dd3a2f]249        virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
250        virtual void accept( Visitor &v ) { v.visit( this ); }
251        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]252  private:
[0dd3a2f]253        virtual std::string typeString() const;
[51b7345]254};
255
[4040425]256class TraitDecl : public AggregateDecl {
[0dd3a2f]257        typedef AggregateDecl Parent;
[17cd4eb]258  public:
[4040425]259        TraitDecl( const std::string &name ) : Parent( name ) {}
260        TraitDecl( const TraitDecl &other ) : Parent( other ) {}
[17cd4eb]261
[4040425]262        virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
[0dd3a2f]263        virtual void accept( Visitor &v ) { v.visit( this ); }
264        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]265  private:
[0dd3a2f]266        virtual std::string typeString() const;
[51b7345]267};
268
[baf7fee]269std::ostream & operator<<( std::ostream & out, Declaration * decl );
270
[17cd4eb]271#endif // DECLARATION_H
[0dd3a2f]272
273// Local Variables: //
274// tab-width: 4 //
275// mode: c++ //
276// compile-command: "make install" //
277// End: //
Note: See TracBrowser for help on using the repository browser.