Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    r65cdc1e rfa4805f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  9 14:45:00 2017
    13 // Update Count     : 126
    14 //
    15 
    16 #pragma once
     12// Last Modified On : Tus Jun 27 15:31:00 2017
     13// Update Count     : 122
     14//
     15
     16#ifndef DECLARATION_H
     17#define DECLARATION_H
    1718
    1819#include <string>
     
    2728class Declaration : public BaseSyntaxNode {
    2829  public:
    29         std::string name;
    30         LinkageSpec::Spec linkage;
    31         bool extension = false;
    32 
    3330        Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
    3431        Declaration( const Declaration &other );
     
    5754        static void dumpIds( std::ostream &os );
    5855        static Declaration *declFromId( UniqueId id );
    59 
    60   private:
     56  private:
     57        std::string name;
    6158        Type::StorageClasses storageClasses;
     59        LinkageSpec::Spec linkage;
    6260        UniqueId uniqueId;
     61        bool extension = false;
    6362};
    6463
    6564class DeclarationWithType : public Declaration {
    6665  public:
     66        DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
     67        DeclarationWithType( const DeclarationWithType &other );
     68        virtual ~DeclarationWithType();
     69
     70        std::string get_mangleName() const { return mangleName; }
     71        DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
     72
     73        std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
     74
     75        int get_scopeLevel() const { return scopeLevel; }
     76        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
     77
     78        ConstantExpr *get_asmName() const { return asmName; }
     79        DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
     80
     81        std::list< Attribute * >& get_attributes() { return attributes; }
     82        const std::list< Attribute * >& get_attributes() const { return attributes; }
     83
     84        Type::FuncSpecifiers get_funcSpec() const { return fs; }
     85        //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
     86
     87        virtual DeclarationWithType *clone() const = 0;
     88        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
     89
     90        virtual Type *get_type() const = 0;
     91        virtual void set_type(Type *) = 0;
     92  private:
    6793        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
    6894        std::string mangleName;
     
    7298        ConstantExpr *asmName;
    7399        std::list< Attribute * > attributes;
    74 
    75         DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
    76         DeclarationWithType( const DeclarationWithType &other );
    77         virtual ~DeclarationWithType();
    78 
    79         std::string get_mangleName() const { return mangleName; }
    80         DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
    81 
    82         std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
    83 
    84         int get_scopeLevel() const { return scopeLevel; }
    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; }
    89 
    90         std::list< Attribute * >& get_attributes() { return attributes; }
    91         const std::list< Attribute * >& get_attributes() const { return attributes; }
    92 
    93         Type::FuncSpecifiers get_funcSpec() const { return fs; }
    94         //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
    95 
    96         virtual DeclarationWithType *clone() const = 0;
    97         virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
    98 
    99         virtual Type *get_type() const = 0;
    100         virtual void set_type(Type *) = 0;
    101 
    102   private:
    103100        Type::FuncSpecifiers fs;
    104101};
     
    107104        typedef DeclarationWithType Parent;
    108105  public:
    109         Type *type;
    110         Initializer *init;
    111         Expression *bitfieldWidth;
    112 
    113106        ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
    114107                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
     
    130123        virtual void print( std::ostream &os, int indent = 0 ) const;
    131124        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     125  private:
     126        Type *type;
     127        Initializer *init;
     128        Expression *bitfieldWidth;
    132129};
    133130
     
    135132        typedef DeclarationWithType Parent;
    136133  public:
    137         FunctionType *type;
    138         CompoundStmt *statements;
    139 
    140134        FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
    141135                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
     
    156150        virtual void print( std::ostream &os, int indent = 0 ) const;
    157151        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     152  private:
     153        FunctionType *type;
     154        CompoundStmt *statements;
    158155};
    159156
     
    161158        typedef Declaration Parent;
    162159  public:
    163         Type *base;
    164         std::list< TypeDecl* > parameters;
    165         std::list< DeclarationWithType* > assertions;
    166 
    167160        NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
    168161        NamedTypeDecl( const NamedTypeDecl &other );
     
    179172        virtual void print( std::ostream &os, int indent = 0 ) const;
    180173        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     174  protected:
     175  private:
     176        Type *base;
     177        std::list< TypeDecl* > parameters;
     178        std::list< DeclarationWithType* > assertions;
    181179};
    182180
     
    185183  public:
    186184        enum Kind { Any, Dtype, Ftype, Ttype };
    187 
    188         Type * init;
    189         bool sized;
    190 
    191185        /// Data extracted from a type decl
    192186        struct Data {
     
    223217  private:
    224218        Kind kind;
     219        Type * init;
     220        bool sized;
    225221};
    226222
     
    228224        typedef NamedTypeDecl Parent;
    229225  public:
    230         TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) : Parent( name, scs, type ) { set_linkage( spec ); }
     226        TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type ) : Parent( name, scs, type ) {}
    231227        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    232228
     
    242238        typedef Declaration Parent;
    243239  public:
     240        AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
     241        AggregateDecl( const AggregateDecl &other );
     242        virtual ~AggregateDecl();
     243
     244        std::list<Declaration*>& get_members() { return members; }
     245        std::list<TypeDecl*>& get_parameters() { return parameters; }
     246
     247        std::list< Attribute * >& get_attributes() { return attributes; }
     248        const std::list< Attribute * >& get_attributes() const { return attributes; }
     249
     250        bool has_body() const { return body; }
     251        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
     252
     253        virtual void print( std::ostream &os, int indent = 0 ) const;
     254        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     255  protected:
     256        virtual std::string typeString() const = 0;
     257
     258  private:
    244259        std::list<Declaration*> members;
    245260        std::list<TypeDecl*> parameters;
    246261        bool body;
    247262        std::list< Attribute * > attributes;
    248 
    249         AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
    250         AggregateDecl( const AggregateDecl &other );
    251         virtual ~AggregateDecl();
    252 
    253         std::list<Declaration*>& get_members() { return members; }
    254         std::list<TypeDecl*>& get_parameters() { return parameters; }
    255 
    256         std::list< Attribute * >& get_attributes() { return attributes; }
    257         const std::list< Attribute * >& get_attributes() const { return attributes; }
    258 
    259         bool has_body() const { return body; }
    260         AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    261 
    262         virtual void print( std::ostream &os, int indent = 0 ) const;
    263         virtual void printShort( std::ostream &os, int indent = 0 ) const;
    264   protected:
    265         virtual std::string typeString() const = 0;
    266263};
    267264
     
    269266        typedef AggregateDecl Parent;
    270267  public:
    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 ), tagged( false ), parent_name( "" ) {}
    272         StructDecl( const std::string &name, const std::string *parent, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( DeclarationNode::Struct ), tagged( true ), parent_name( parent ? *parent : "" ) {}
     268        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 ) {}
    273269        StructDecl( const StructDecl &other ) : Parent( other ) {}
    274270
     
    277273        bool is_thread() { return kind == DeclarationNode::Thread; }
    278274
    279         // Tagged/Tree Structure Excetion
    280         bool get_tagged() { return tagged; }
    281         void set_tagged( bool newValue ) { tagged = newValue; }
    282         bool has_parent() { return parent_name != ""; }
    283         std::string get_parentName() { return parent_name; }
    284 
    285275        virtual StructDecl *clone() const { return new StructDecl( *this ); }
    286276        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    289279        DeclarationNode::Aggregate kind;
    290280        virtual std::string typeString() const;
    291 
    292         bool tagged;
    293         std::string parent_name;
    294281};
    295282
     
    337324class AsmDecl : public Declaration {
    338325  public:
    339         AsmStmt *stmt;
    340 
    341326        AsmDecl( AsmStmt *stmt );
    342327        AsmDecl( const AsmDecl &other );
     
    351336        virtual void print( std::ostream &os, int indent = 0 ) const;
    352337        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     338  private:
     339        AsmStmt *stmt;
    353340};
    354341
    355342std::ostream & operator<<( std::ostream & out, const Declaration * decl );
    356343std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
     344
     345#endif // DECLARATION_H
    357346
    358347// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.