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
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// Last Modified By : Rob Schluntz
12// Last Modified On : Thu Jan 07 14:48:44 2016
13// Update Count     : 34
14//
15
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"
23#include "Parser/ParseNode.h"
24
25class Declaration {
26  public:
27        Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
28        Declaration( const Declaration &other );
29        virtual ~Declaration();
30
31        const std::string &get_name() const { return name; }
32        void set_name( std::string newValue ) { name = newValue; }
33        DeclarationNode::StorageClass get_storageClass() const { return storageClass; }
34        void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; }
35        LinkageSpec::Type get_linkage() const { return linkage; }
36        void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
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; }
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 );
52  private:
53        std::string name;
54        DeclarationNode::StorageClass storageClass;
55        LinkageSpec::Type linkage;
56        bool isInline, isNoreturn;
57        UniqueId uniqueId;
58};
59
60class DeclarationWithType : public Declaration {
61  public:
62        DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
63        DeclarationWithType( const DeclarationWithType &other );
64        virtual ~DeclarationWithType();
65
66        std::string get_mangleName() const { return mangleName; }
67        void set_mangleName( std::string newValue ) { mangleName = newValue; }
68
69        virtual DeclarationWithType *clone() const = 0;
70        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
71
72        virtual Type *get_type() const = 0;
73        virtual void set_type(Type *) = 0;
74  private:
75        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
76        std::string mangleName;
77};
78
79class ObjectDecl : public DeclarationWithType {
80        typedef DeclarationWithType Parent;
81  public:
82        ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline = false, bool isNoreturn = false );
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        ExprStmt * get_ctor() const { return ctor; }
94        void set_ctor( ExprStmt * newValue ) { ctor = newValue; }
95
96        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
97        virtual void accept( Visitor &v ) { v.visit( this ); }
98        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
99        virtual void print( std::ostream &os, int indent = 0 ) const;
100        virtual void printShort( std::ostream &os, int indent = 0 ) const;
101  private:
102        Type *type;
103        Initializer *init;
104        Expression *bitfieldWidth;
105        ExprStmt * ctor;
106};
107
108class FunctionDecl : public DeclarationWithType {
109        typedef DeclarationWithType Parent;
110  public:
111        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn );
112        FunctionDecl( const FunctionDecl &other );
113        virtual ~FunctionDecl();
114
115        Type *get_type() const;
116        virtual void set_type(Type *);
117
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;
130  private:
131        FunctionType *type;
132        CompoundStmt *statements;
133        std::list< std::string > oldIdents;
134        std::list< Declaration* > oldDecls;
135};
136
137class NamedTypeDecl : public Declaration {
138        typedef Declaration Parent;
139  public:
140        NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
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;
152  protected:
153        virtual std::string typeString() const = 0;
154  private:
155        Type *base;
156        std::list< TypeDecl* > parameters;
157        std::list< DeclarationWithType* > assertions;
158};
159
160class TypeDecl : public NamedTypeDecl {
161        typedef NamedTypeDecl Parent;
162  public:
163        enum Kind { Any, Dtype, Ftype };
164
165        TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
166        TypeDecl( const TypeDecl &other );
167
168        Kind get_kind() const { return kind; }
169
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 ); }
173  private:
174        virtual std::string typeString() const;
175        Kind kind;
176};
177
178class TypedefDecl : public NamedTypeDecl {
179        typedef NamedTypeDecl Parent;
180  public:
181        TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
182        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
183
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 ); }
187  private:
188        virtual std::string typeString() const;
189};
190
191class AggregateDecl : public Declaration {
192        typedef Declaration Parent;
193  public:
194        AggregateDecl( const std::string &name );
195        AggregateDecl( const AggregateDecl &other );
196        virtual ~AggregateDecl();
197
198        std::list<Declaration*>& get_members() { return members; }
199        std::list<TypeDecl*>& get_parameters() { return parameters; }
200
201        virtual void print( std::ostream &os, int indent = 0 ) const;
202        virtual void printShort( std::ostream &os, int indent = 0 ) const;
203  protected:
204        virtual std::string typeString() const = 0;
205
206  private:
207        std::list<Declaration*> members;
208        std::list<TypeDecl*> parameters;
209};
210
211class StructDecl : public AggregateDecl {
212        typedef AggregateDecl Parent;
213  public:
214        StructDecl( const std::string &name ) : Parent( name ) {}
215        StructDecl( const StructDecl &other ) : Parent( other ) {}
216
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 ); }
220
221  private:
222        virtual std::string typeString() const;
223};
224
225class UnionDecl : public AggregateDecl {
226        typedef AggregateDecl Parent;
227  public:
228        UnionDecl( const std::string &name ) : Parent( name ) {}
229        UnionDecl( const UnionDecl &other ) : Parent( other ) {}
230
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 ); }
234  private:
235        virtual std::string typeString() const;
236};
237
238class EnumDecl : public AggregateDecl {
239        typedef AggregateDecl Parent;
240  public:
241        EnumDecl( const std::string &name ) : Parent( name ) {}
242        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
243
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 ); }
247  private:
248        virtual std::string typeString() const;
249};
250
251class ContextDecl : public AggregateDecl {
252        typedef AggregateDecl Parent;
253  public:
254        ContextDecl( const std::string &name ) : Parent( name ) {}
255        ContextDecl( const ContextDecl &other ) : Parent( other ) {}
256
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 ); }
260  private:
261        virtual std::string typeString() const;
262};
263
264std::ostream & operator<<( std::ostream & out, Declaration * decl );
265
266#endif // DECLARATION_H
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.