source: src/SynTree/Declaration.h @ 919d1ba

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 919d1ba was 8e9cbb2, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

add more code to handle gcc extension and test program, second attempt

  • Property mode set to 100644
File size: 10.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//
[974906e2]7// Declaration.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[8e9cbb2]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Jun 30 21:17:24 2016
13// Update Count     : 38
[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"
[f326f99]24#include <string>
[51b7345]25
[17cd4eb]26class Declaration {
27  public:
[68cd1ce]28        Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
[0dd3a2f]29        Declaration( const Declaration &other );
30        virtual ~Declaration();
31
[5f2f2d7]32        const std::string &get_name() const { return name; }
[0dd3a2f]33        void set_name( std::string newValue ) { name = newValue; }
[68cd1ce]34        DeclarationNode::StorageClass get_storageClass() const { return storageClass; }
35        void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; }
[0dd3a2f]36        LinkageSpec::Type get_linkage() const { return linkage; }
37        void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
[1db21619]38        bool get_isInline() const { return isInline; }
39        void set_isInline( bool newValue ) { isInline = newValue; }
40        bool get_isNoreturn() const { return isNoreturn; }
41        void set_isNoreturn( bool newValue ) { isNoreturn = newValue; }
[0dd3a2f]42        UniqueId get_uniqueId() const { return uniqueId; }
[8e9cbb2]43        bool get_extension() const { return extension; }
44        Declaration *set_extension( bool exten ) { extension = exten; return this; }
[0dd3a2f]45
46        void fixUniqueId( void );
47        virtual Declaration *clone() const = 0;
48        virtual void accept( Visitor &v ) = 0;
49        virtual Declaration *acceptMutator( Mutator &m ) = 0;
50        virtual void print( std::ostream &os, int indent = 0 ) const = 0;
51        virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
52
53        static void dumpIds( std::ostream &os );
54        static Declaration *declFromId( UniqueId id );
[17cd4eb]55  private:
[0dd3a2f]56        std::string name;
[68cd1ce]57        DeclarationNode::StorageClass storageClass;
[0dd3a2f]58        LinkageSpec::Type linkage;
[1db21619]59        bool isInline, isNoreturn;
[0dd3a2f]60        UniqueId uniqueId;
[8e9cbb2]61        bool extension = false;
[51b7345]62};
63
[17cd4eb]64class DeclarationWithType : public Declaration {
65  public:
[68cd1ce]66        DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
[0dd3a2f]67        DeclarationWithType( const DeclarationWithType &other );
68        virtual ~DeclarationWithType();
[51b7345]69
[0dd3a2f]70        std::string get_mangleName() const { return mangleName; }
71        void set_mangleName( std::string newValue ) { mangleName = newValue; }
[17cd4eb]72
[f326f99]73        std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
74
75        int get_scopeLevel() const { return scopeLevel; }
76        void set_scopeLevel( int newValue ) { scopeLevel = newValue; }
77
[0dd3a2f]78        virtual DeclarationWithType *clone() const = 0;
79        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
[17cd4eb]80
[0dd3a2f]81        virtual Type *get_type() const = 0;
82        virtual void set_type(Type *) = 0;
[17cd4eb]83  private:
[0dd3a2f]84        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
85        std::string mangleName;
[f326f99]86        // need to remember the scope level at which the variable was declared, so that
87        // shadowed identifiers can be accessed
88        int scopeLevel = 0;
[51b7345]89};
90
[17cd4eb]91class ObjectDecl : public DeclarationWithType {
[0dd3a2f]92        typedef DeclarationWithType Parent;
[17cd4eb]93  public:
[1db21619]94        ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline = false, bool isNoreturn = false );
[0dd3a2f]95        ObjectDecl( const ObjectDecl &other );
96        virtual ~ObjectDecl();
97
98        virtual Type *get_type() const { return type; }
99        virtual void set_type(Type *newType) { type = newType; }
100
101        Initializer *get_init() const { return init; }
102        void set_init( Initializer *newValue ) { init = newValue; }
103        Expression *get_bitfieldWidth() const { return bitfieldWidth; }
104        void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
105
106        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
107        virtual void accept( Visitor &v ) { v.visit( this ); }
[1db21619]108        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[0dd3a2f]109        virtual void print( std::ostream &os, int indent = 0 ) const;
110        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]111  private:
[0dd3a2f]112        Type *type;
113        Initializer *init;
114        Expression *bitfieldWidth;
[51b7345]115};
116
[17cd4eb]117class FunctionDecl : public DeclarationWithType {
[0dd3a2f]118        typedef DeclarationWithType Parent;
[17cd4eb]119  public:
[7baed7d]120        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, const std::list< Attribute * > attributes = std::list< Attribute * >() );
[0dd3a2f]121        FunctionDecl( const FunctionDecl &other );
122        virtual ~FunctionDecl();
[51b7345]123
[0dd3a2f]124        Type *get_type() const;
125        virtual void set_type(Type *);
[51b7345]126
[0dd3a2f]127        FunctionType *get_functionType() const { return type; }
128        void set_functionType( FunctionType *newValue ) { type = newValue; }
129        CompoundStmt *get_statements() const { return statements; }
130        void set_statements( CompoundStmt *newValue ) { statements = newValue; }
131        std::list< std::string >& get_oldIdents() { return oldIdents; }
132        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
[7baed7d]133        std::list< Attribute * >& get_attributes() { return attributes; }
[0dd3a2f]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;
[17cd4eb]140  private:
[0dd3a2f]141        FunctionType *type;
142        CompoundStmt *statements;
143        std::list< std::string > oldIdents;
144        std::list< Declaration* > oldDecls;
[7baed7d]145        std::list< Attribute * > attributes;
[51b7345]146};
147
[17cd4eb]148class NamedTypeDecl : public Declaration {
[0dd3a2f]149        typedef Declaration Parent;
[17cd4eb]150  public:
[68cd1ce]151        NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
[0dd3a2f]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;
[17cd4eb]163  protected:
[0dd3a2f]164        virtual std::string typeString() const = 0;
[17cd4eb]165  private:
[0dd3a2f]166        Type *base;
167        std::list< TypeDecl* > parameters;
168        std::list< DeclarationWithType* > assertions;
[51b7345]169};
170
[17cd4eb]171class TypeDecl : public NamedTypeDecl {
[0dd3a2f]172        typedef NamedTypeDecl Parent;
[17cd4eb]173  public:
[0dd3a2f]174        enum Kind { Any, Dtype, Ftype };
[51b7345]175
[68cd1ce]176        TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
[0dd3a2f]177        TypeDecl( const TypeDecl &other );
[17cd4eb]178
[0dd3a2f]179        Kind get_kind() const { return kind; }
[51b7345]180
[0dd3a2f]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 ); }
[17cd4eb]184  private:
[0dd3a2f]185        virtual std::string typeString() const;
186        Kind kind;
[51b7345]187};
188
[17cd4eb]189class TypedefDecl : public NamedTypeDecl {
[0dd3a2f]190        typedef NamedTypeDecl Parent;
[17cd4eb]191  public:
[68cd1ce]192        TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
[0dd3a2f]193        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
[17cd4eb]194
[0dd3a2f]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 ); }
[17cd4eb]198  private:
[0dd3a2f]199        virtual std::string typeString() const;
[51b7345]200};
201
[17cd4eb]202class AggregateDecl : public Declaration {
[0dd3a2f]203        typedef Declaration Parent;
[17cd4eb]204  public:
[0dd3a2f]205        AggregateDecl( const std::string &name );
206        AggregateDecl( const AggregateDecl &other );
207        virtual ~AggregateDecl();
[51b7345]208
[0dd3a2f]209        std::list<Declaration*>& get_members() { return members; }
210        std::list<TypeDecl*>& get_parameters() { return parameters; }
[17cd4eb]211
[0dd3a2f]212        virtual void print( std::ostream &os, int indent = 0 ) const;
213        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]214  protected:
[0dd3a2f]215        virtual std::string typeString() const = 0;
[17cd4eb]216
217  private:
[0dd3a2f]218        std::list<Declaration*> members;
219        std::list<TypeDecl*> parameters;
[51b7345]220};
221
[17cd4eb]222class StructDecl : public AggregateDecl {
[0dd3a2f]223        typedef AggregateDecl Parent;
[17cd4eb]224  public:
[0dd3a2f]225        StructDecl( const std::string &name ) : Parent( name ) {}
226        StructDecl( const StructDecl &other ) : Parent( other ) {}
[17cd4eb]227
[0dd3a2f]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 ); }
[51b7345]231
[17cd4eb]232  private:
[0dd3a2f]233        virtual std::string typeString() const;
[51b7345]234};
235
[17cd4eb]236class UnionDecl : public AggregateDecl {
[0dd3a2f]237        typedef AggregateDecl Parent;
[17cd4eb]238  public:
[0dd3a2f]239        UnionDecl( const std::string &name ) : Parent( name ) {}
240        UnionDecl( const UnionDecl &other ) : Parent( other ) {}
[17cd4eb]241
[0dd3a2f]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 ); }
[17cd4eb]245  private:
[0dd3a2f]246        virtual std::string typeString() const;
[51b7345]247};
248
[17cd4eb]249class EnumDecl : public AggregateDecl {
[0dd3a2f]250        typedef AggregateDecl Parent;
[17cd4eb]251  public:
[0dd3a2f]252        EnumDecl( const std::string &name ) : Parent( name ) {}
253        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
[17cd4eb]254
[0dd3a2f]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 ); }
[17cd4eb]258  private:
[0dd3a2f]259        virtual std::string typeString() const;
[51b7345]260};
261
[4040425]262class TraitDecl : public AggregateDecl {
[0dd3a2f]263        typedef AggregateDecl Parent;
[17cd4eb]264  public:
[4040425]265        TraitDecl( const std::string &name ) : Parent( name ) {}
266        TraitDecl( const TraitDecl &other ) : Parent( other ) {}
[17cd4eb]267
[4040425]268        virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
[0dd3a2f]269        virtual void accept( Visitor &v ) { v.visit( this ); }
270        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]271  private:
[0dd3a2f]272        virtual std::string typeString() const;
[51b7345]273};
274
[baf7fee]275std::ostream & operator<<( std::ostream & out, Declaration * decl );
276
[17cd4eb]277#endif // DECLARATION_H
[0dd3a2f]278
279// Local Variables: //
280// tab-width: 4 //
281// mode: c++ //
282// compile-command: "make install" //
283// End: //
Note: See TracBrowser for help on using the repository browser.