Changeset 7baed7d for src/SynTree


Ignore:
Timestamp:
Jun 6, 2016, 5:46:09 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
64a32c6
Parents:
64071c2
Message:

generalize notion of a GCC attribute

Location:
src/SynTree
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    r64071c2 r7baed7d  
    115115        typedef DeclarationWithType Parent;
    116116  public:
    117         // temporary - merge this into general GCC attributes
    118         struct Attribute {
    119                 enum Type {
    120                         NoAttribute, Constructor, Destructor,
    121                 } type;
    122                 enum Priority {
    123                         // priorities 0-100 are reserved by gcc, so it's okay to use 100 an exceptional case
    124                         Default = 100, High,
    125                 } priority;
    126                 Attribute(Type t = NoAttribute, Priority p = Default) : type(t), priority(p) {};
    127         };
    128 
    129         FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = Attribute() );
     117        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 * >() );
    130118        FunctionDecl( const FunctionDecl &other );
    131119        virtual ~FunctionDecl();
     
    140128        std::list< std::string >& get_oldIdents() { return oldIdents; }
    141129        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
    142         Attribute get_attribute() const { return attribute; }
    143         void set_attribute( Attribute newValue ) { attribute = newValue; }
     130        std::list< Attribute * >& get_attributes() { return attributes; }
    144131
    145132        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
     
    153140        std::list< std::string > oldIdents;
    154141        std::list< Declaration* > oldDecls;
    155         Attribute attribute;
     142        std::list< Attribute * > attributes;
    156143};
    157144
  • src/SynTree/FunctionDecl.cc

    r64071c2 r7baed7d  
    1919#include "Statement.h"
    2020#include "Type.h"
     21#include "Attribute.h"
    2122#include "Common/utility.h"
    2223
    23 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute )
    24                 : Parent( name, sc, linkage ), type( type ), statements( statements ), attribute( attribute ) {
     24FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
     25                : Parent( name, sc, linkage ), type( type ), statements( statements ), attributes( attributes ) {
    2526        set_isInline( isInline );
    2627        set_isNoreturn( isNoreturn );
     
    3233
    3334FunctionDecl::FunctionDecl( const FunctionDecl &other )
    34         : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), attribute( other.attribute ) {
     35        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
     36                cloneAll( other.attributes, attributes );
    3537}
    3638
     
    3840        delete type;
    3941        delete statements;
     42        deleteAll( attributes );
    4043}
    4144
     
    6568                os << "_Noreturn ";
    6669        } // if
    67         switch ( attribute.type ) {
    68                 case Attribute::Constructor:
    69                         os << "Global Constructor ";
    70                         break;
    71                 case Attribute::Destructor:
    72                         os << "Global Destructor ";
    73                         break;
    74                 default:
    75                         break;
    76         }
    77         if ( attribute.priority != Attribute::Default ) {
    78                 os << "with priority " << attribute.priority << " ";
    79         }
     70
     71        printAll( attributes, os, indent );
     72
    8073        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
    8174                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
     
    118111                os << "_Noreturn ";
    119112        } // if
    120         switch ( attribute.type ) {
    121                 case Attribute::Constructor:
    122                         os << " Global Constructor ";
    123                         break;
    124                 case Attribute::Destructor:
    125                         os << " Global Destructor ";
    126                         break;
    127                 default:
    128                         break;
    129         }
    130         if ( attribute.priority != Attribute::Default ) {
    131                 os << "with priority " << attribute.priority << " ";
    132         }
     113
     114        // xxx - should printShort print attributes?
     115
    133116        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
    134117                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
  • src/SynTree/SynTree.h

    r64071c2 r7baed7d  
    118118class TypeSubstitution;
    119119
     120// gcc attribute
     121class Attribute;
     122
    120123#endif // SYNTREE_H
    121124
  • src/SynTree/module.mk

    r64071c2 r7baed7d  
    66## file "LICENCE" distributed with Cforall.
    77##
    8 ## module.mk -- 
     8## module.mk --
    99##
    1010## Author           : Richard C. Bilson
     
    4646       SynTree/Visitor.cc \
    4747       SynTree/Mutator.cc \
    48        SynTree/TypeSubstitution.cc
     48       SynTree/TypeSubstitution.cc \
     49       SynTree/Attribute.cc
    4950
Note: See TracChangeset for help on using the changeset viewer.