source: src/SynTree/Declaration.h @ f196351

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f196351 was f196351, checked in by Andrew Beach <ajbeach@…>, 7 years ago

Scrubbing out more traces of TreeStruct?.

  • Property mode set to 100644
File size: 13.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
[cbce272]11// Last Modified By : Andrew Beach
[f196351]12// Last Modified On : Fri Aug 11 10:20:00 2017
13// Update Count     : 127
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b7345]17
[294647b]18#include <string>
19
20#include "BaseSyntaxNode.h"
[51b7345]21#include "Mutator.h"
[294647b]22#include "Visitor.h"
23#include "SynTree.h"
[51b7345]24#include "Parser/LinkageSpec.h"
[68cd1ce]25#include "Parser/ParseNode.h"
[51b7345]26
[294647b]27class Declaration : public BaseSyntaxNode {
[17cd4eb]28  public:
[65cdc1e]29        std::string name;
30        LinkageSpec::Spec linkage;
31        bool extension = false;
32
[68fe077a]33        Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
[0dd3a2f]34        Declaration( const Declaration &other );
35        virtual ~Declaration();
36
[5f2f2d7]37        const std::string &get_name() const { return name; }
[0dd3a2f]38        void set_name( std::string newValue ) { name = newValue; }
[a7c90d4]39
[68fe077a]40        Type::StorageClasses get_storageClasses() const { return storageClasses; }
[a7c90d4]41
[8b7ee09]42        LinkageSpec::Spec get_linkage() const { return linkage; }
43        void set_linkage( LinkageSpec::Spec newValue ) { linkage = newValue; }
[a7c90d4]44
[0dd3a2f]45        UniqueId get_uniqueId() const { return uniqueId; }
[a7c90d4]46
[8e9cbb2]47        bool get_extension() const { return extension; }
48        Declaration *set_extension( bool exten ) { extension = exten; return this; }
[0dd3a2f]49
50        void fixUniqueId( void );
51        virtual Declaration *clone() const = 0;
52        virtual void accept( Visitor &v ) = 0;
53        virtual Declaration *acceptMutator( Mutator &m ) = 0;
54        virtual void print( std::ostream &os, int indent = 0 ) const = 0;
55        virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
56
57        static void dumpIds( std::ostream &os );
58        static Declaration *declFromId( UniqueId id );
[65cdc1e]59
[17cd4eb]60  private:
[68fe077a]61        Type::StorageClasses storageClasses;
[0dd3a2f]62        UniqueId uniqueId;
[51b7345]63};
64
[17cd4eb]65class DeclarationWithType : public Declaration {
66  public:
[65cdc1e]67        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
68        std::string mangleName;
69        // need to remember the scope level at which the variable was declared, so that shadowed identifiers can be accessed
70        int scopeLevel = 0;
71
72        ConstantExpr *asmName;
73        std::list< Attribute * > attributes;
74
[ddfd945]75        DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
[0dd3a2f]76        DeclarationWithType( const DeclarationWithType &other );
77        virtual ~DeclarationWithType();
[51b7345]78
[0dd3a2f]79        std::string get_mangleName() const { return mangleName; }
[58dd019]80        DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
[17cd4eb]81
[f326f99]82        std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
83
84        int get_scopeLevel() const { return scopeLevel; }
[58dd019]85        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
86
87        ConstantExpr *get_asmName() const { return asmName; }
88        DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
[f326f99]89
[f9cebb5]90        std::list< Attribute * >& get_attributes() { return attributes; }
91        const std::list< Attribute * >& get_attributes() const { return attributes; }
92
[ddfd945]93        Type::FuncSpecifiers get_funcSpec() const { return fs; }
94        //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
[dd020c0]95
[0dd3a2f]96        virtual DeclarationWithType *clone() const = 0;
97        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
[17cd4eb]98
[0dd3a2f]99        virtual Type *get_type() const = 0;
100        virtual void set_type(Type *) = 0;
[f9cebb5]101
[65cdc1e]102  private:
[ddfd945]103        Type::FuncSpecifiers fs;
[51b7345]104};
105
[17cd4eb]106class ObjectDecl : public DeclarationWithType {
[0dd3a2f]107        typedef DeclarationWithType Parent;
[17cd4eb]108  public:
[65cdc1e]109        Type *type;
110        Initializer *init;
111        Expression *bitfieldWidth;
112
[68fe077a]113        ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
[ddfd945]114                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
[0dd3a2f]115        ObjectDecl( const ObjectDecl &other );
116        virtual ~ObjectDecl();
117
118        virtual Type *get_type() const { return type; }
119        virtual void set_type(Type *newType) { type = newType; }
120
121        Initializer *get_init() const { return init; }
122        void set_init( Initializer *newValue ) { init = newValue; }
[58dd019]123
[0dd3a2f]124        Expression *get_bitfieldWidth() const { return bitfieldWidth; }
125        void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
126
127        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
128        virtual void accept( Visitor &v ) { v.visit( this ); }
[1db21619]129        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[0dd3a2f]130        virtual void print( std::ostream &os, int indent = 0 ) const;
131        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[51b7345]132};
133
[17cd4eb]134class FunctionDecl : public DeclarationWithType {
[0dd3a2f]135        typedef DeclarationWithType Parent;
[17cd4eb]136  public:
[65cdc1e]137        FunctionType *type;
138        CompoundStmt *statements;
139
[68fe077a]140        FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
[ddfd945]141                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
[0dd3a2f]142        FunctionDecl( const FunctionDecl &other );
143        virtual ~FunctionDecl();
[51b7345]144
[0dd3a2f]145        Type *get_type() const;
146        virtual void set_type(Type *);
[51b7345]147
[0dd3a2f]148        FunctionType *get_functionType() const { return type; }
149        void set_functionType( FunctionType *newValue ) { type = newValue; }
150        CompoundStmt *get_statements() const { return statements; }
151        void set_statements( CompoundStmt *newValue ) { statements = newValue; }
152
153        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
154        virtual void accept( Visitor &v ) { v.visit( this ); }
155        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
156        virtual void print( std::ostream &os, int indent = 0 ) const;
157        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[51b7345]158};
159
[17cd4eb]160class NamedTypeDecl : public Declaration {
[0dd3a2f]161        typedef Declaration Parent;
[17cd4eb]162  public:
[65cdc1e]163        Type *base;
164        std::list< TypeDecl* > parameters;
165        std::list< DeclarationWithType* > assertions;
166
[68fe077a]167        NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
[46f6134]168        NamedTypeDecl( const NamedTypeDecl &other );
[0dd3a2f]169        virtual ~NamedTypeDecl();
170
171        Type *get_base() const { return base; }
172        void set_base( Type *newValue ) { base = newValue; }
173        std::list< TypeDecl* >& get_parameters() { return parameters; }
174        std::list< DeclarationWithType* >& get_assertions() { return assertions; }
175
[e39241b]176        virtual std::string typeString() const = 0;
177
[0dd3a2f]178        virtual NamedTypeDecl *clone() const = 0;
179        virtual void print( std::ostream &os, int indent = 0 ) const;
180        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[51b7345]181};
182
[17cd4eb]183class TypeDecl : public NamedTypeDecl {
[0dd3a2f]184        typedef NamedTypeDecl Parent;
[17cd4eb]185  public:
[8f60f0b]186        enum Kind { Any, Dtype, Ftype, Ttype };
[65cdc1e]187
188        Type * init;
189        bool sized;
190
[2c57025]191        /// Data extracted from a type decl
192        struct Data {
193                TypeDecl::Kind kind;
194                bool isComplete;
195                Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
196                Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
197                Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
198                bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; }
199                bool operator!=(const Data & other) const { return !(*this == other);}
200        };
[51b7345]201
[67cf18c]202        TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init = nullptr );
[0dd3a2f]203        TypeDecl( const TypeDecl &other );
[67cf18c]204        virtual ~TypeDecl();
[17cd4eb]205
[0dd3a2f]206        Kind get_kind() const { return kind; }
[51b7345]207
[67cf18c]208        Type * get_init() const { return init; }
209        TypeDecl * set_init( Type * newValue ) { init = newValue; return this; }
210
[2c57025]211        bool isComplete() const { return kind == Any || sized; }
212        bool get_sized() const { return sized; }
213        TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; }
214
[e39241b]215        virtual std::string typeString() const;
[bdd0755]216        virtual std::string genTypeString() const;
[e39241b]217
[0dd3a2f]218        virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
219        virtual void accept( Visitor &v ) { v.visit( this ); }
220        virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[67cf18c]221        virtual void print( std::ostream &os, int indent = 0 ) const;
222
[17cd4eb]223  private:
[0dd3a2f]224        Kind kind;
[51b7345]225};
226
[17cd4eb]227class TypedefDecl : public NamedTypeDecl {
[0dd3a2f]228        typedef NamedTypeDecl Parent;
[17cd4eb]229  public:
[cbce272]230        TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) : Parent( name, scs, type ) { set_linkage( spec ); }
[0dd3a2f]231        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
[17cd4eb]232
[e39241b]233        virtual std::string typeString() const;
234
[0dd3a2f]235        virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
236        virtual void accept( Visitor &v ) { v.visit( this ); }
237        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]238  private:
[51b7345]239};
240
[17cd4eb]241class AggregateDecl : public Declaration {
[0dd3a2f]242        typedef Declaration Parent;
[17cd4eb]243  public:
[65cdc1e]244        std::list<Declaration*> members;
245        std::list<TypeDecl*> parameters;
246        bool body;
247        std::list< Attribute * > attributes;
248
[fa4805f]249        AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
[0dd3a2f]250        AggregateDecl( const AggregateDecl &other );
251        virtual ~AggregateDecl();
[51b7345]252
[0dd3a2f]253        std::list<Declaration*>& get_members() { return members; }
254        std::list<TypeDecl*>& get_parameters() { return parameters; }
[17cd4eb]255
[c0aa336]256        std::list< Attribute * >& get_attributes() { return attributes; }
257        const std::list< Attribute * >& get_attributes() const { return attributes; }
258
[5d125e4]259        bool has_body() const { return body; }
260        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
261
[0dd3a2f]262        virtual void print( std::ostream &os, int indent = 0 ) const;
263        virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]264  protected:
[0dd3a2f]265        virtual std::string typeString() const = 0;
[51b7345]266};
267
[17cd4eb]268class StructDecl : public AggregateDecl {
[0dd3a2f]269        typedef AggregateDecl Parent;
[17cd4eb]270  public:
[f196351]271        StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {}
272        StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {}
[17cd4eb]273
[409433da]274        bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
275        bool is_monitor() { return kind == DeclarationNode::Monitor; }
276        bool is_thread() { return kind == DeclarationNode::Thread; }
277
[0dd3a2f]278        virtual StructDecl *clone() const { return new StructDecl( *this ); }
279        virtual void accept( Visitor &v ) { v.visit( this ); }
280        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]281  private:
[409433da]282        DeclarationNode::Aggregate kind;
[0dd3a2f]283        virtual std::string typeString() const;
[51b7345]284};
285
[17cd4eb]286class UnionDecl : public AggregateDecl {
[0dd3a2f]287        typedef AggregateDecl Parent;
[17cd4eb]288  public:
[fa4805f]289        UnionDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
[0dd3a2f]290        UnionDecl( const UnionDecl &other ) : Parent( other ) {}
[17cd4eb]291
[0dd3a2f]292        virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
293        virtual void accept( Visitor &v ) { v.visit( this ); }
294        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]295  private:
[0dd3a2f]296        virtual std::string typeString() const;
[51b7345]297};
298
[17cd4eb]299class EnumDecl : public AggregateDecl {
[0dd3a2f]300        typedef AggregateDecl Parent;
[17cd4eb]301  public:
[fa4805f]302        EnumDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
[0dd3a2f]303        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
[17cd4eb]304
[0dd3a2f]305        virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
306        virtual void accept( Visitor &v ) { v.visit( this ); }
307        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]308  private:
[0dd3a2f]309        virtual std::string typeString() const;
[51b7345]310};
311
[4040425]312class TraitDecl : public AggregateDecl {
[0dd3a2f]313        typedef AggregateDecl Parent;
[17cd4eb]314  public:
[c0aa336]315        TraitDecl( const std::string &name, const std::list< Attribute * > & attributes ) : Parent( name ) {
316                assertf( attributes.empty(), "attribute unsupported for traits" );
317        }
[4040425]318        TraitDecl( const TraitDecl &other ) : Parent( other ) {}
[17cd4eb]319
[4040425]320        virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
[0dd3a2f]321        virtual void accept( Visitor &v ) { v.visit( this ); }
322        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]323  private:
[0dd3a2f]324        virtual std::string typeString() const;
[51b7345]325};
326
[e994912]327class AsmDecl : public Declaration {
328  public:
[65cdc1e]329        AsmStmt *stmt;
330
[e994912]331        AsmDecl( AsmStmt *stmt );
332        AsmDecl( const AsmDecl &other );
333        virtual ~AsmDecl();
334
335        AsmStmt *get_stmt() { return stmt; }
336        void set_stmt( AsmStmt *newValue ) { stmt = newValue; }
337
338        virtual AsmDecl *clone() const { return new AsmDecl( *this ); }
339        virtual void accept( Visitor &v ) { v.visit( this ); }
340        virtual AsmDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
341        virtual void print( std::ostream &os, int indent = 0 ) const;
342        virtual void printShort( std::ostream &os, int indent = 0 ) const;
343};
344
[3906301]345std::ostream & operator<<( std::ostream & out, const Declaration * decl );
[2c57025]346std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
[baf7fee]347
[0dd3a2f]348// Local Variables: //
349// tab-width: 4 //
350// mode: c++ //
351// compile-command: "make install" //
352// End: //
Note: See TracBrowser for help on using the repository browser.