source: src/SynTree/Declaration.h@ 334163c

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 334163c was 367e082, checked in by Rob Schluntz <rschlunt@…>, 10 years ago

generated assignment routine will not attempt to assign to a const array field

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