source: src/SynTree/Declaration.h @ 7c64920

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 7c64920 was 7c64920, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

formatting

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