Changeset 4e24610 for src/SynTree


Ignore:
Timestamp:
May 6, 2016, 1:56:08 PM (8 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:
d029162
Parents:
711eee5
Message:

Add constructor attribute to global initializer function, don't try to fix const globals, add Constructor/Destructor? attributes to FunctionDecl?

Location:
src/SynTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    r711eee5 r4e24610  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Declaration.h -- 
     7// Declaration.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:28:11 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri May 06 11:16:45 2016
    1313// Update Count     : 33
    1414//
     
    106106        typedef DeclarationWithType Parent;
    107107  public:
    108         FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn );
     108        // temporary - merge this into general GCC attributes
     109        enum Attribute {
     110                NoAttribute, Constructor, Destructor,
     111        };
     112
     113        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = NoAttribute );
    109114        FunctionDecl( const FunctionDecl &other );
    110115        virtual ~FunctionDecl();
     
    119124        std::list< std::string >& get_oldIdents() { return oldIdents; }
    120125        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
     126        Attribute get_attribute() const { return attribute; }
     127        void set_attribute( Attribute newValue ) { attribute = newValue; }
    121128
    122129        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
     
    130137        std::list< std::string > oldIdents;
    131138        std::list< Declaration* > oldDecls;
     139        Attribute attribute;
    132140};
    133141
  • src/SynTree/FunctionDecl.cc

    r711eee5 r4e24610  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Apr 01 11:40:07 2016
     12// Last Modified On : Fri May 06 11:35:09 2016
    1313// Update Count     : 19
    1414//
     
    2121#include "Common/utility.h"
    2222
    23 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn )
    24                 : Parent( name, sc, linkage ), type( type ), statements( statements ) {
     23FunctionDecl::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 ) {
    2525        set_isInline( isInline );
    2626        set_isNoreturn( isNoreturn );
     27        // this is a brazen hack to force the function "main" to have C linkage
     28        if ( name == "main" ) {
     29                set_linkage( LinkageSpec::C );
     30        } // if
    2731}
    2832
    2933FunctionDecl::FunctionDecl( const FunctionDecl &other )
    30         : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
     34        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), attribute( other.attribute ) {
    3135}
    3236
     
    6165                os << "_Noreturn ";
    6266        } // if
     67        switch ( attribute ) {
     68                case Constructor:
     69                        os << "Global Constructor ";
     70                        break;
     71                case Destructor:
     72                        os << "Global Destructor ";
     73                        break;
     74                default:
     75                        break;
     76        }
    6377        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
    6478                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
     
    100114                os << "_Noreturn ";
    101115        } // if
     116        switch ( attribute ) {
     117                case Constructor:
     118                        os << " Global Constructor ";
     119                        break;
     120                case Destructor:
     121                        os << " Global Destructor ";
     122                        break;
     123                default:
     124                        break;
     125        }
    102126        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
    103127                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
Note: See TracChangeset for help on using the changeset viewer.