Changeset bdd516a for translator/Parser


Ignore:
Timestamp:
Apr 28, 2015, 4:21:36 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, string, with_gc
Children:
42e2ad7
Parents:
ad17ba6a
Message:

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

Location:
translator/Parser
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/DeclarationNode.cc

    rad17ba6a rbdd516a  
    55#include <cassert>
    66
    7 #include "ParseNode.h"
    87#include "TypeData.h"
    9 #include "utility.h"
    10 #include "SynTree/Declaration.h"
    118#include "SynTree/Expression.h"
    12 #include "SynTree/Initializer.h"
    13 #include "SemanticError.h"
    14 #include "UniqueName.h"
    15 #include "LinkageSpec.h"
     9
    1610
    1711using namespace std;
    1812
    19 /* these must remain in the same order as the corresponding DeclarationNode enumerations */
    20 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue" };
     13// These must remain in the same order as the corresponding DeclarationNode enumerations.
     14const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    2115const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" };
    2216const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" };
     
    6761    os << string(indent, ' ' );
    6862    if ( name == "" ) {
    69 ///     os << "An unnamed ";
     63        os << "unnamed: ";
    7064    } else {
    71         os << name << ": a ";
     65        os << name << ": ";
    7266    }
    7367
     
    862856              ret = new StructInstType( type->buildQualifiers(), type->aggregate->name );
    863857              break;
    864 
    865858            case DeclarationNode::Union:
    866859              ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
    867860              break;
    868 
    869861            case DeclarationNode::Context:
    870862              ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );
    871863              break;
    872 
    873864            default:
    874865              assert( false );
    875           }
     866          } // switch
    876867          buildList( type->aggregate->actuals, ret->get_parameters() );
    877868          return ret;
     
    884875      default:
    885876        return type->build();
    886     }
     877    } // switch
    887878}
    888879
  • translator/Parser/ExpressionNode.cc

    rad17ba6a rbdd516a  
    1616ExpressionNode::ExpressionNode() : ParseNode(), argName( 0 ) {}
    1717
    18 ExpressionNode::ExpressionNode(string *name_) : ParseNode( *name_ ), argName( 0 ) {
     18ExpressionNode::ExpressionNode( string *name_) : ParseNode( *name_ ), argName( 0 ) {
    1919    delete name_;
    2020}
     
    2525    } else {
    2626        argName = 0;
    27     }
     27    } // if
    2828}
    2929
    3030ExpressionNode * ExpressionNode::set_asArgName( std::string *aName ) {
    31     argName = new VarRefNode(aName);
     31    argName = new VarRefNode( aName );
    3232    return this;
    3333}
     
    4040void ExpressionNode::printDesignation( std::ostream &os, int indent ) const {
    4141    if ( argName ) {
    42         os << string(' ', indent) << "(designated by:  ";
    43         argName->printOneLine(os, indent );
     42        os << string(' ', indent ) << "(designated by:  ";
     43        argName->printOneLine( os, indent );
    4444        os << ")" << std::endl;
    45     }
     45    } // if
    4646}
    4747
     
    5252}
    5353
    54 void NullExprNode::print(std::ostream & os, int indent) const {
    55     printDesignation(os);
     54void NullExprNode::print( std::ostream & os, int indent ) const {
     55    printDesignation( os );
    5656    os << "null expression";
    5757}
    5858
    59 void NullExprNode::printOneLine(std::ostream & os, int indent) const {
    60     printDesignation(os);
     59void NullExprNode::printOneLine( std::ostream & os, int indent ) const {
     60    printDesignation( os );
    6161    os << "null";
    6262}
     
    6666}
    6767
    68 CommaExprNode *ExpressionNode::add_to_list(ExpressionNode *exp){
    69     return new CommaExprNode(this, exp );
     68CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp ){
     69    return new CommaExprNode( this, exp );
    7070}
    7171
    7272//  enum ConstantNode::Type =  { Integer, Float, Character, String, Range }
    7373
    74 ConstantNode::ConstantNode(void) : ExpressionNode(), sign(true), longs(0), size(0) {}
    75 
    76 ConstantNode::ConstantNode(string *name_) : ExpressionNode(name_), sign(true), longs(0), size(0) {}
    77 
    78 ConstantNode::ConstantNode(Type t, string *inVal) : type(t), sign(true), longs(0), size(0) {
     74ConstantNode::ConstantNode( void ) : ExpressionNode(), sign( true ), longs(0), size(0) {}
     75
     76ConstantNode::ConstantNode( string *name_) : ExpressionNode( name_), sign( true ), longs(0), size(0) {}
     77
     78ConstantNode::ConstantNode( Type t, string *inVal ) : type( t ), sign( true ), longs(0), size(0) {
    7979    if ( inVal ) {
    8080        value = *inVal;
     
    8282    } else {
    8383        value = "";
    84     }
    85 
    86     classify(value);
     84    } // if
     85
     86    classify( value );
    8787}
    8888
     
    9696}
    9797
    98 void ConstantNode::classify(std::string &str){
    99     switch (type){
     98void ConstantNode::classify( std::string &str ){
     99    switch ( type ){
    100100      case Integer:
    101101      case Float:
     
    105105            int i = str.length() - 1;
    106106
    107             while ( i >= 0 && !isxdigit(c = str.at(i--)) )
     107            while ( i >= 0 && !isxdigit( c = str.at( i--)) )
    108108                sfx += c;
    109109
     
    111111
    112112            // get rid of underscores
    113             value.erase(remove(value.begin(), value.end(), '_'), value.end());
    114 
    115             std::transform(sfx.begin(), sfx.end(), sfx.begin(), tolower_hack);
     113            value.erase( remove( value.begin(), value.end(), '_'), value.end());
     114
     115            std::transform( sfx.begin(), sfx.end(), sfx.begin(), tolower_hack );
    116116
    117117            if ( sfx.find("ll") != string::npos ){
    118118                longs = 2;
    119             } else if (sfx.find("l") != string::npos ){
     119            } else if ( sfx.find("l") != string::npos ){
    120120                longs = 1;
    121             }
    122 
    123             assert((longs >= 0) && (longs <= 2));
     121            } // if
     122
     123            assert(( longs >= 0) && ( longs <= 2));
    124124
    125125            if ( sfx.find("u") != string::npos )
     
    131131        {
    132132            // remove underscores from hex and oct escapes
    133             if (str.substr(1,2) == "\\x")
    134                 value.erase(remove(value.begin(), value.end(), '_'), value.end());
     133            if ( str.substr(1,2) == "\\x")
     134                value.erase( remove( value.begin(), value.end(), '_'), value.end());
    135135
    136136            break;
     
    142142}
    143143
    144 ConstantNode::Type ConstantNode::get_type(void) const {
     144ConstantNode::Type ConstantNode::get_type( void ) const {
    145145    return type;
    146146}
     
    148148ConstantNode *ConstantNode::append( std::string *newValue ) {
    149149    if ( newValue ) {
    150         if (type == String){
     150        if ( type == String ){
    151151            std::string temp = *newValue;
    152152            value.resize( value.size() - 1 );
     
    156156
    157157        delete newValue;
    158     }
     158    } // if
    159159    return this;
    160160}
    161161
    162 void ConstantNode::printOneLine(std::ostream &os, int indent ) const {
    163     os << string(indent, ' ');
    164     printDesignation(os);
     162void ConstantNode::printOneLine( std::ostream &os, int indent ) const {
     163    os << string( indent, ' ');
     164    printDesignation( os );
    165165
    166166    switch ( type ) {
     
    185185}
    186186
    187 void ConstantNode::print(std::ostream &os, int indent ) const {
     187void ConstantNode::print( std::ostream &os, int indent ) const {
    188188    printOneLine( os, indent );
    189189    os << endl;
     
    194194    BasicType *bt;
    195195
    196     switch (get_type()){
     196    switch ( get_type()){
    197197      case Integer:
    198198        /* Cfr. standard 6.4.4.1 */
    199         //bt.set_kind(BasicType::SignedInt);
    200         bt = new BasicType(q, BasicType::SignedInt);
     199        //bt.set_kind( BasicType::SignedInt );
     200        bt = new BasicType( q, BasicType::SignedInt );
    201201        break;
    202202      case Float:
    203         bt = new BasicType(q, BasicType::Float);
     203        bt = new BasicType( q, BasicType::Float );
    204204        break;
    205205      case Character:
    206         bt = new BasicType(q, BasicType::Char);
     206        bt = new BasicType( q, BasicType::Char );
    207207        break;
    208208      case String:
     
    210210        ArrayType *at;
    211211        std::string value = get_value();
    212         at = new ArrayType(q, new BasicType(q, BasicType::Char),
    213                            new ConstantExpr( Constant( new BasicType(q, BasicType::SignedInt),
     212        at = new ArrayType( q, new BasicType( q, BasicType::Char ),
     213                           new ConstantExpr( Constant( new BasicType( q, BasicType::SignedInt ),
    214214                                                       toString( value.size() - 1 ) ) ),  // account for '\0'
    215215                           false, false );
    216         return new ConstantExpr( Constant(at, value), maybeBuild< Expression >( get_argName() ) );
     216        return new ConstantExpr( Constant( at, value ), maybeBuild< Expression >( get_argName() ) );
    217217    }
    218     return new ConstantExpr(  Constant(bt, get_value()),  maybeBuild< Expression >( get_argName() ) );
    219 }
    220 
    221 VarRefNode::VarRefNode() : isLabel(false) {}
    222 
    223 VarRefNode::VarRefNode(string *name_, bool labelp) : ExpressionNode(name_), isLabel(labelp) {}
     218    return new ConstantExpr(  Constant( bt, get_value()),  maybeBuild< Expression >( get_argName() ) );
     219}
     220
     221VarRefNode::VarRefNode() : isLabel( false ) {}
     222
     223VarRefNode::VarRefNode( string *name_, bool labelp ) : ExpressionNode( name_), isLabel( labelp ) {}
    224224
    225225VarRefNode::VarRefNode( const VarRefNode &other ) : ExpressionNode( other ), isLabel( other.isLabel ) {
     
    230230}
    231231
    232 void VarRefNode::printOneLine(std::ostream &os, int indent ) const {
    233     printDesignation(os);
     232void VarRefNode::printOneLine( std::ostream &os, int indent ) const {
     233    printDesignation( os );
    234234    os << get_name() << ' ';
    235235}
    236236
    237 void VarRefNode::print(std::ostream &os, int indent ) const {
    238     printDesignation(os);
    239     os << '\r' << string(indent, ' ') << "Referencing: ";
     237void VarRefNode::print( std::ostream &os, int indent ) const {
     238    printDesignation( os );
     239    os << '\r' << string( indent, ' ') << "Referencing: ";
    240240    os << "Variable: " << get_name();
    241241    os << endl;
    242242}
    243243
    244 OperatorNode::OperatorNode(Type t) : type(t) {}
     244OperatorNode::OperatorNode( Type t ) : type( t ) {}
    245245
    246246OperatorNode::OperatorNode( const OperatorNode &other ) : ExpressionNode( other ), type( other.type ) {
     
    249249OperatorNode::~OperatorNode() {}
    250250
    251 OperatorNode::Type OperatorNode::get_type(void) const{
     251OperatorNode::Type OperatorNode::get_type( void ) const{
    252252    return type;
    253253}
    254254
    255255void OperatorNode::printOneLine( std::ostream &os, int indent ) const {
    256     printDesignation(os);
     256    printDesignation( os );
    257257    os << OpName[ type ] << ' ';
    258258}
    259259
    260260void OperatorNode::print( std::ostream &os, int indent ) const{
    261     printDesignation(os);
    262     os << '\r' << string(indent, ' ') << "Operator: " << OpName[type] << endl;
     261    printDesignation( os );
     262    os << '\r' << string( indent, ' ') << "Operator: " << OpName[type] << endl;
    263263    return;
    264264}
    265265
    266 std::string OperatorNode::get_typename(void) const{
    267     return string(OpName[ type ]);
     266std::string OperatorNode::get_typename( void ) const{
     267    return string( OpName[ type ]);
    268268}
    269269
     
    282282};
    283283
    284 CompositeExprNode::CompositeExprNode(void) : ExpressionNode(), function( 0 ), arguments( 0 ) {
    285 }
    286 
    287 CompositeExprNode::CompositeExprNode(string *name_) : ExpressionNode(name_), function( 0 ), arguments( 0 ) {
    288 }
    289 
    290 CompositeExprNode::CompositeExprNode(ExpressionNode *f, ExpressionNode *args):
    291     function(f), arguments(args) {
    292 }
    293 
    294 CompositeExprNode::CompositeExprNode(ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2):
    295     function(f), arguments(arg1) {
    296     arguments->set_link(arg2);
     284CompositeExprNode::CompositeExprNode( void ) : ExpressionNode(), function( 0 ), arguments( 0 ) {
     285}
     286
     287CompositeExprNode::CompositeExprNode( string *name_) : ExpressionNode( name_), function( 0 ), arguments( 0 ) {
     288}
     289
     290CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *args ):
     291    function( f ), arguments( args ) {
     292}
     293
     294CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2):
     295    function( f ), arguments( arg1) {
     296    arguments->set_link( arg2);
    297297}
    298298
     
    303303            arguments->set_link( cur->clone() );
    304304        } else {
    305             arguments = (ExpressionNode*)cur->clone();
    306         }
     305            arguments = ( ExpressionNode*)cur->clone();
     306        } // if
    307307        cur = cur->get_link();
    308308    }
     
    333333    std::list<Expression *> args;
    334334
    335     buildList(get_args(), args);
    336 
    337     if ( ! ( op = dynamic_cast<OperatorNode *>(function)) ) {
     335    buildList( get_args(), args );
     336
     337    if ( ! ( op = dynamic_cast<OperatorNode *>( function )) ) {
    338338        // a function as opposed to an operator
    339         return new UntypedExpr(function->build(), args, maybeBuild< Expression >( get_argName() ));
     339        return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));
    340340    } else {
    341         switch (op->get_type()){
     341        switch ( op->get_type()){
    342342          case OperatorNode::Incr:
    343343          case OperatorNode::Decr:
     
    412412          case OperatorNode::Cast:
    413413            {
    414                 TypeValueNode * arg = dynamic_cast<TypeValueNode *>(get_args());
     414                TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args());
    415415                assert( arg );
    416416
    417417                DeclarationNode *decl_node = arg->get_decl();
    418                 ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>(arg->get_link());
     418                ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link());
    419419
    420420                Type *targetType = decl_node->buildType();
     
    423423                    return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );
    424424                } else {
    425                     return new CastExpr(expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
    426                 }
     425                    return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
     426                } // if
    427427            }
    428428          case OperatorNode::FieldSel:
     
    430430                assert( args.size() == 2 );
    431431
    432                 NameExpr *member = dynamic_cast<NameExpr *>(args.back());
    433                 // TupleExpr *memberTup = dynamic_cast<TupleExpr *>(args.back());
    434 
    435                 if ( member != 0 )
    436                     {
    437                         UntypedMemberExpr *ret = new UntypedMemberExpr(member->get_name(), args.front());
    438                         delete member;
    439                         return ret;
    440                     }
     432                NameExpr *member = dynamic_cast<NameExpr *>( args.back());
     433                // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back());
     434
     435                if ( member != 0 ) {
     436                    UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front());
     437                    delete member;
     438                    return ret;
    441439                /* else if ( memberTup != 0 )
    442440                   {
    443                    UntypedMemberExpr *ret = new UntypedMemberExpr(memberTup->get_name(), args.front());
     441                   UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front());
    444442                   delete member;
    445443                   return ret;
    446444                   } */
    447                 else
     445                } else
    448446                    assert( false );
    449447            }
     
    452450                assert( args.size() == 2 );
    453451
    454                 NameExpr *member = dynamic_cast<NameExpr *>(args.back());  // modify for Tuples   xxx
     452                NameExpr *member = dynamic_cast<NameExpr *>( args.back());  // modify for Tuples   xxx
    455453                assert( member != 0 );
    456454
     
    458456                deref->get_args().push_back( args.front() );
    459457
    460                 UntypedMemberExpr *ret = new UntypedMemberExpr(member->get_name(), deref);
     458                UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
    461459                delete member;
    462460                return ret;
     
    465463          case OperatorNode::SizeOf:
    466464            {
    467 ///     bool isSizeOf = (op->get_type() == OperatorNode::SizeOf);
    468 
    469                 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>(get_args()) ) {
    470                     return new SizeofExpr(arg->get_decl()->buildType());
     465///     bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
     466
     467                if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
     468                    return new SizeofExpr( arg->get_decl()->buildType());
    471469                } else {
    472                     return new SizeofExpr(args.front());
    473                 }
     470                    return new SizeofExpr( args.front());
     471                } // if
    474472            }
    475473          case OperatorNode::Attr:
    476474            {
    477                 VarRefNode *var = dynamic_cast<VarRefNode *>(get_args());
     475                VarRefNode *var = dynamic_cast<VarRefNode *>( get_args());
    478476                assert( var );
    479477                if ( !get_args()->get_link() ) {
    480                     return new AttrExpr(var->build(), (Expression*)0);
    481                 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>(get_args()->get_link()) ) {
    482                     return new AttrExpr(var->build(), arg->get_decl()->buildType());
     478                    return new AttrExpr( var->build(), ( Expression*)0);
     479                } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {
     480                    return new AttrExpr( var->build(), arg->get_decl()->buildType());
    483481                } else {
    484                     return new AttrExpr(var->build(), args.back());
    485                 }
     482                    return new AttrExpr( var->build(), args.back());
     483                } // if
    486484            }
    487485          case OperatorNode::CompLit:
     
    490488          case OperatorNode::Or:
    491489          case OperatorNode::And:
    492             assert(args.size() == 2);
    493             return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), (op->get_type() == OperatorNode::And) );
     490            assert( args.size() == 2);
     491            return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) );
    494492          case OperatorNode::Cond:
    495493            {
    496                 assert(args.size() == 3);
     494                assert( args.size() == 3);
    497495                std::list< Expression* >::const_iterator i = args.begin();
    498496                Expression *arg1 = notZeroExpr( *i++ );
     
    505503          case OperatorNode::Comma:
    506504            {
    507                 assert(args.size() == 2);
     505                assert( args.size() == 2);
    508506                std::list< Expression* >::const_iterator i = args.begin();
    509507                Expression *ret = *i++;
     
    527525}
    528526
    529 void CompositeExprNode::printOneLine(std::ostream &os, int indent) const {
    530     printDesignation(os);
     527void CompositeExprNode::printOneLine( std::ostream &os, int indent ) const {
     528    printDesignation( os );
    531529    os << "( ";
    532530    function->printOneLine( os, indent );
    533     for( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) {
     531    for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) {
    534532        cur->printOneLine( os, indent );
    535533    }
     
    537535}
    538536
    539 void CompositeExprNode::print(std::ostream &os, int indent) const {
    540     printDesignation(os);
    541     os << '\r' << string(indent, ' ') << "Application of: " << endl;
     537void CompositeExprNode::print( std::ostream &os, int indent ) const {
     538    printDesignation( os );
     539    os << '\r' << string( indent, ' ') << "Application of: " << endl;
    542540    function->print( os, indent + ParseNode::indent_by );
    543541
    544     os << '\r' << string(indent, ' ') ;
     542    os << '\r' << string( indent, ' ') ;
    545543    if ( arguments ) {
    546544        os << "... on arguments: " << endl;
    547         arguments->printList(os, indent + ParseNode::indent_by);
     545        arguments->printList( os, indent + ParseNode::indent_by );
    548546    } else
    549547        os << "... on no arguments: " << endl;
    550548}
    551549
    552 void CompositeExprNode::set_function(ExpressionNode *f){
     550void CompositeExprNode::set_function( ExpressionNode *f ){
    553551    function = f;
    554552}
    555553
    556 void CompositeExprNode::set_args(ExpressionNode *args){
     554void CompositeExprNode::set_args( ExpressionNode *args ){
    557555    arguments = args;
    558556}
    559557
    560 ExpressionNode *CompositeExprNode::get_function(void) const {
     558ExpressionNode *CompositeExprNode::get_function( void ) const {
    561559    return function;
    562560}
    563561
    564 ExpressionNode *CompositeExprNode::get_args(void) const {
     562ExpressionNode *CompositeExprNode::get_args( void ) const {
    565563    return arguments;
    566564}
    567565
    568 void CompositeExprNode::add_arg(ExpressionNode *arg){
    569     if (arguments)
    570         arguments->set_link(arg);
     566void CompositeExprNode::add_arg( ExpressionNode *arg ){
     567    if ( arguments )
     568        arguments->set_link( arg );
    571569    else
    572         set_args(arg);
    573 }
    574 
    575 CommaExprNode::CommaExprNode(): CompositeExprNode(new OperatorNode(OperatorNode::Comma)) {}
    576 
    577 CommaExprNode::CommaExprNode(ExpressionNode *exp) : CompositeExprNode( new OperatorNode(OperatorNode::Comma), exp ) {
    578 }
    579 
    580 CommaExprNode::CommaExprNode(ExpressionNode *exp1, ExpressionNode *exp2) : CompositeExprNode(new OperatorNode(OperatorNode::Comma), exp1, exp2) {
    581 }
    582 
    583 CommaExprNode *CommaExprNode::add_to_list(ExpressionNode *exp){
    584     add_arg(exp);
     570        set_args( arg );
     571}
     572
     573CommaExprNode::CommaExprNode(): CompositeExprNode( new OperatorNode( OperatorNode::Comma )) {}
     574
     575CommaExprNode::CommaExprNode( ExpressionNode *exp ) : CompositeExprNode( new OperatorNode( OperatorNode::Comma ), exp ) {
     576}
     577
     578CommaExprNode::CommaExprNode( ExpressionNode *exp1, ExpressionNode *exp2) : CompositeExprNode( new OperatorNode( OperatorNode::Comma ), exp1, exp2) {
     579}
     580
     581CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ){
     582    add_arg( exp );
    585583
    586584    return this;
     
    590588}
    591589
    592 ValofExprNode::ValofExprNode(StatementNode *s): body(s) {}
     590ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {}
    593591
    594592ValofExprNode::ValofExprNode( const ValofExprNode &other ) : ExpressionNode( other ), body( maybeClone( body ) ) {
     
    600598
    601599void ValofExprNode::print( std::ostream &os, int indent ) const {
    602     printDesignation(os);
    603     os << string(indent, ' ') << "Valof Expression:" << std::endl;
    604     get_body()->print(os, indent + 4);
     600    printDesignation( os );
     601    os << string( indent, ' ') << "Valof Expression:" << std::endl;
     602    get_body()->print( os, indent + 4);
    605603}
    606604
     
    613611}
    614612
    615 ForCtlExprNode::ForCtlExprNode(ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr) throw (SemanticError) : condition(cond), change(incr) {
     613ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) {
    616614    if ( init_ == 0 )
    617615        init = 0;
     
    620618        ExpressionNode *exp;
    621619
    622         if ((decl = dynamic_cast<DeclarationNode *>(init_)) != 0)
    623             init = new StatementNode(decl);
    624         else if ((exp = dynamic_cast<ExpressionNode *>(init_)) != 0)
    625             init = new StatementNode(StatementNode::Exp, exp);
     620        if (( decl = dynamic_cast<DeclarationNode *>( init_)) != 0)
     621            init = new StatementNode( decl );
     622        else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0)
     623            init = new StatementNode( StatementNode::Exp, exp );
    626624        else
    627625            throw SemanticError("Error in for control expression");
     
    646644
    647645void ForCtlExprNode::print( std::ostream &os, int indent ) const{
    648     os << string(indent,' ') << "For Control Expression -- : " << endl;
    649 
    650     os << "\r" << string(indent + 2,' ') << "initialization: ";
    651     if (init != 0)
    652         init->print(os, indent + 4);
    653 
    654     os << "\n\r" << string(indent + 2,' ') << "condition: ";
    655     if (condition != 0)
    656         condition->print(os, indent + 4);
    657     os << "\n\r" << string(indent + 2,' ') << "increment: ";
    658     if (change != 0)
    659         change->print(os, indent + 4);
     646    os << string( indent,' ') << "For Control Expression -- : " << endl;
     647
     648    os << "\r" << string( indent + 2,' ') << "initialization: ";
     649    if ( init != 0)
     650        init->print( os, indent + 4);
     651
     652    os << "\n\r" << string( indent + 2,' ') << "condition: ";
     653    if ( condition != 0)
     654        condition->print( os, indent + 4);
     655    os << "\n\r" << string( indent + 2,' ') << "increment: ";
     656    if ( change != 0)
     657        change->print( os, indent + 4);
    660658}
    661659
     
    664662}
    665663
    666 TypeValueNode::TypeValueNode(DeclarationNode *decl)
     664TypeValueNode::TypeValueNode( DeclarationNode *decl )
    667665    : decl( decl ) {
    668666}
     
    676674}
    677675
    678 void TypeValueNode::print(std::ostream &os, int indent) const {
     676void TypeValueNode::print( std::ostream &os, int indent ) const {
    679677    os << std::string( indent, ' ' ) << "Type:";
    680     get_decl()->print(os, indent + 2);
    681 }
    682 
    683 void TypeValueNode::printOneLine(std::ostream &os, int indent) const {
     678    get_decl()->print( os, indent + 2);
     679}
     680
     681void TypeValueNode::printOneLine( std::ostream &os, int indent ) const {
    684682    os << "Type:";
    685     get_decl()->print(os, indent + 2);
     683    get_decl()->print( os, indent + 2);
    686684}
    687685
     
    690688        {
    691689            OperatorNode *op;
    692             if ( (op = dynamic_cast< OperatorNode * >( composite->get_function() )) && (op->get_type() == OperatorNode::Comma) )
     690            if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) )
    693691                {
    694692                    if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
     
    707705    if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( tuple ) ) {
    708706        OperatorNode *op = 0;
    709         if ( (op = dynamic_cast< OperatorNode * >( composite->get_function() )) && (op->get_type() == OperatorNode::TupleC) )
     707        if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::TupleC ) )
    710708            return composite->get_args();
    711709    }
  • translator/Parser/InitializerNode.cc

    rad17ba6a rbdd516a  
     1#include <cassert>
     2#include <iostream>
     3using namespace std;
     4
    15#include "ParseNode.h"
    26#include "SynTree/Expression.h"
    37#include "SynTree/Initializer.h"
    4 #include "utility.h"
    5 #include "SemanticError.h"
    6 // #include <cstdlib> // for strtol
    7 #include <cassert>
    8 
    9 #include <iostream>
    10 using namespace std;
    118
    129InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des )
  • translator/Parser/ParseNode.cc

    rad17ba6a rbdd516a  
    7373}
    7474
    75 ParseNode *mkList(ParseNode &pn){
     75ParseNode *mkList( ParseNode &pn ) {
    7676    /* it just relies on `operator,' to take care of the "arguments" and provides
    7777       a nice interface to an awful-looking address-of, rendering, for example
    7878       (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7))
    79        (although "nice"  is probably not the word)
     79       (although "nice" is probably not the word)
    8080    */
    8181    return &pn;
  • translator/Parser/ParseNode.h

    rad17ba6a rbdd516a  
    22#define PARSENODE_H
    33
    4 #include <iostream>
    54#include <string>
    65#include <list>
     
    87
    98#include "utility.h"
    10 #include "SynTree/SynTree.h"
    119#include "SynTree/Declaration.h"
    12 #include "SemanticError.h"
    1310#include "UniqueName.h"
    1411
     
    2320// Builder
    2421class ParseNode {
    25 public:
    26   ParseNode(void);
    27   ParseNode (std::string);
    28   virtual ~ParseNode(void);
    29 
    30   ParseNode *set_name (std::string) ;
    31   ParseNode *set_name (std::string *) ;
    32 
    33   std::string get_name(void);
    34 
    35   ParseNode *get_link(void) const;
    36   ParseNode *get_last(void);
    37   ParseNode *set_link(ParseNode *);
    38   void set_next( ParseNode *newlink ) { next = newlink; }
    39 
    40   virtual ParseNode *clone() const { return 0; };
    41 
    42   const std::string get_name(void) const;
    43   virtual void print( std::ostream &, int indent = 0 ) const;
    44   virtual void printList( std::ostream &, int indent = 0 ) const;
    45 
    46   ParseNode &operator,(ParseNode &);
    47 
    48 protected:
    49   std::string name;
    50   ParseNode *next;
    51   static int indent_by;
    52 };
    53 
    54 ParseNode *mkList(ParseNode &);
     22  public:
     23    ParseNode( void );
     24    ParseNode ( std::string );
     25    virtual ~ParseNode( void );
     26
     27    ParseNode *set_name ( std::string ) ;
     28    ParseNode *set_name ( std::string * ) ;
     29
     30    std::string get_name( void );
     31
     32    ParseNode *get_link( void ) const;
     33    ParseNode *get_last( void );
     34    ParseNode *set_link( ParseNode * );
     35    void set_next( ParseNode *newlink ) { next = newlink; }
     36
     37    virtual ParseNode *clone() const { return 0; };
     38
     39    const std::string get_name( void ) const;
     40    virtual void print( std::ostream &, int indent = 0 ) const;
     41    virtual void printList( std::ostream &, int indent = 0 ) const;
     42
     43    ParseNode &operator,( ParseNode &);
     44  protected:
     45    std::string name;
     46    ParseNode *next;
     47    static int indent_by;
     48};
     49
     50ParseNode *mkList( ParseNode & );
    5551
    5652class ExpressionNode : public ParseNode {
    57 public:
    58   ExpressionNode();
    59   ExpressionNode(std::string *);
    60   ExpressionNode( const ExpressionNode &other );
    61   virtual ~ExpressionNode() { /* can't delete asArgName because it might be referenced elsewhere */ };
    62 
    63   virtual ExpressionNode *clone() const = 0;
    64 
    65   virtual CommaExprNode *add_to_list(ExpressionNode *);
    66 
    67   ExpressionNode *get_argName() const { return argName; }
    68   ExpressionNode *set_asArgName( std::string *aName );
    69   ExpressionNode *set_asArgName( ExpressionNode *aDesignator );
    70 
    71   virtual void print(std::ostream &, int indent = 0) const = 0;
    72   virtual void printOneLine(std::ostream &, int indent = 0) const = 0;
    73 
    74   virtual Expression *build() const = 0;
    75 protected:
    76   void printDesignation (std::ostream &, int indent = 0) const;
    77 
    78 private:
    79   ExpressionNode *argName;
    80 };
    81 
    82 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted
    83 // e.g., [ 2, , 3 ]
    84 class NullExprNode : public ExpressionNode
    85 {
    86 public:
    87   NullExprNode();
    88 
    89   virtual NullExprNode *clone() const;
    90 
    91   virtual void print(std::ostream &, int indent = 0) const;
    92   virtual void printOneLine(std::ostream &, int indent = 0) const;
    93 
    94   virtual Expression *build() const;
     53  public:
     54    ExpressionNode();
     55    ExpressionNode( std::string * );
     56    ExpressionNode( const ExpressionNode &other );
     57    virtual ~ExpressionNode() { /* can't delete asArgName because it might be referenced elsewhere */ };
     58
     59    virtual ExpressionNode *clone() const = 0;
     60
     61    virtual CommaExprNode *add_to_list( ExpressionNode * );
     62
     63    ExpressionNode *get_argName() const { return argName; }
     64    ExpressionNode *set_asArgName( std::string *aName );
     65    ExpressionNode *set_asArgName( ExpressionNode *aDesignator );
     66
     67    virtual void print( std::ostream &, int indent = 0) const = 0;
     68    virtual void printOneLine( std::ostream &, int indent = 0) const = 0;
     69
     70    virtual Expression *build() const = 0;
     71  protected:
     72    void printDesignation ( std::ostream &, int indent = 0) const;
     73  private:
     74    ExpressionNode *argName;
     75};
     76
     77// NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ]
     78class NullExprNode : public ExpressionNode {
     79  public:
     80    NullExprNode();
     81
     82    virtual NullExprNode *clone() const;
     83
     84    virtual void print( std::ostream &, int indent = 0) const;
     85    virtual void printOneLine( std::ostream &, int indent = 0) const;
     86
     87    virtual Expression *build() const;
    9588};
    9689
    9790class ConstantNode : public ExpressionNode {
    98 public:
    99   enum Type {
    100     Integer, Float, Character, String /* , Range, EnumConstant  */
    101   };
    102 
    103   ConstantNode(void);
    104   ConstantNode(std::string *);
    105   ConstantNode(Type, std::string *);
    106   ConstantNode( const ConstantNode &other );
    107 
    108   virtual ConstantNode *clone() const { return new ConstantNode( *this ); }
    109 
    110   Type get_type(void) const ;
    111   virtual void print(std::ostream &, int indent = 0) const;
    112   virtual void printOneLine(std::ostream &, int indent = 0) const;
    113 
    114   std::string get_value() const { return value; }
    115   ConstantNode *append( std::string *newValue );
    116 
    117   Expression *build() const;
    118 
    119 private:
    120   void classify(std::string &);
    121   Type type;
    122   std::string value;
    123   bool sign;
    124   short base;
    125   int longs, size;
     91  public:
     92    enum Type {
     93        Integer, Float, Character, String /* , Range, EnumConstant  */
     94    };
     95
     96    ConstantNode( void );
     97    ConstantNode( std::string * );
     98    ConstantNode( Type, std::string * );
     99    ConstantNode( const ConstantNode &other );
     100
     101    virtual ConstantNode *clone() const { return new ConstantNode( *this ); }
     102
     103    Type get_type( void ) const ;
     104    virtual void print( std::ostream &, int indent = 0) const;
     105    virtual void printOneLine( std::ostream &, int indent = 0) const;
     106
     107    std::string get_value() const { return value; }
     108    ConstantNode *append( std::string *newValue );
     109
     110    Expression *build() const;
     111  private:
     112    void classify( std::string &);
     113    Type type;
     114    std::string value;
     115    bool sign;
     116    short base;
     117    int longs, size;
    126118};
    127119
    128120class VarRefNode : public ExpressionNode {
    129 public:
    130   VarRefNode();
    131   VarRefNode(std::string *, bool isLabel = false );
    132   VarRefNode( const VarRefNode &other );
    133 
    134   virtual Expression *build() const ;
    135 
    136   virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
    137 
    138   virtual void print(std::ostream &, int indent = 0) const;
    139   virtual void printOneLine(std::ostream &, int indent = 0) const;
    140 private:
    141   bool isLabel;
    142 };
    143 
    144 class TypeValueNode : public ExpressionNode
    145 {
    146 public:
    147   TypeValueNode(DeclarationNode *);
    148   TypeValueNode( const TypeValueNode &other );
    149 
    150   DeclarationNode *get_decl() const { return decl; }
    151 
    152   virtual Expression *build() const ;
    153 
    154   virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }
    155 
    156   virtual void print(std::ostream &, int indent = 0) const;
    157   virtual void printOneLine(std::ostream &, int indent = 0) const;
    158 private:
    159   DeclarationNode *decl;
     121  public:
     122    VarRefNode();
     123    VarRefNode( std::string *, bool isLabel = false );
     124    VarRefNode( const VarRefNode &other );
     125
     126    virtual Expression *build() const ;
     127
     128    virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
     129
     130    virtual void print( std::ostream &, int indent = 0) const;
     131    virtual void printOneLine( std::ostream &, int indent = 0) const;
     132  private:
     133    bool isLabel;
     134};
     135
     136class TypeValueNode : public ExpressionNode {
     137  public:
     138    TypeValueNode( DeclarationNode * );
     139    TypeValueNode( const TypeValueNode &other );
     140
     141    DeclarationNode *get_decl() const { return decl; }
     142
     143    virtual Expression *build() const ;
     144
     145    virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }
     146
     147    virtual void print( std::ostream &, int indent = 0) const;
     148    virtual void printOneLine( std::ostream &, int indent = 0) const;
     149  private:
     150    DeclarationNode *decl;
    160151};
    161152
    162153class OperatorNode : public ExpressionNode {
    163 public:
    164   enum Type { TupleC, Comma, TupleFieldSel,
    165               Cond, NCond,
    166               SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And,
     154  public:
     155    enum Type { TupleC, Comma, TupleFieldSel,
     156                Cond, NCond,
     157                SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And,
    167158                BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
    168159                Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn,
    169160                ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range,
    170               UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress
    171             };
    172 
    173   OperatorNode(Type t);
    174   OperatorNode( const OperatorNode &other );
    175   virtual ~OperatorNode();
    176 
    177   virtual OperatorNode *clone() const { return new OperatorNode( *this ); }
    178 
    179   Type get_type(void) const;
    180   std::string get_typename(void) const;
    181 
    182   virtual void print(std::ostream &, int indent = 0) const;
    183   virtual void printOneLine(std::ostream &, int indent = 0) const;
    184 
    185   virtual Expression *build() const { return 0; }
     161                UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress
     162    };
     163
     164    OperatorNode( Type t );
     165    OperatorNode( const OperatorNode &other );
     166    virtual ~OperatorNode();
     167
     168    virtual OperatorNode *clone() const { return new OperatorNode( *this ); }
     169
     170    Type get_type( void ) const;
     171    std::string get_typename( void ) const;
     172
     173    virtual void print( std::ostream &, int indent = 0) const;
     174    virtual void printOneLine( std::ostream &, int indent = 0) const;
     175
     176    virtual Expression *build() const { return 0; }
     177  private:
     178    Type type;
     179    static const char *OpName[];
     180};
     181
     182
     183class CompositeExprNode : public ExpressionNode {
     184  public:
     185    CompositeExprNode( void );
     186    CompositeExprNode( std::string * );
     187    CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 );
     188    CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 );
     189    CompositeExprNode( const CompositeExprNode &other );
     190    virtual ~CompositeExprNode();
     191
     192    virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); }
     193    virtual Expression *build() const;
     194
     195    virtual void print( std::ostream &, int indent = 0) const;
     196    virtual void printOneLine( std::ostream &, int indent = 0) const;
     197
     198    void set_function( ExpressionNode * );
     199    void set_args( ExpressionNode * );
     200
     201    void add_arg( ExpressionNode * );
     202
     203    ExpressionNode *get_function() const;
     204    ExpressionNode *get_args() const;
     205  private:
     206    ExpressionNode *function;
     207    ExpressionNode *arguments;
     208};
     209
     210class CommaExprNode : public CompositeExprNode {
     211  public:
     212    CommaExprNode();
     213    CommaExprNode( ExpressionNode * );
     214    CommaExprNode( ExpressionNode *, ExpressionNode * );
     215    CommaExprNode( const CommaExprNode &other );
     216
     217    virtual CommaExprNode *add_to_list( ExpressionNode * );
     218    virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
     219};
     220
     221class ForCtlExprNode : public ExpressionNode {
     222  public:
     223    ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError );
     224    ForCtlExprNode( const ForCtlExprNode &other );
     225    ~ForCtlExprNode();
     226
     227    StatementNode *get_init() const { return init; }
     228    ExpressionNode *get_condition() const { return condition; }
     229    ExpressionNode *get_change() const { return change; }
     230
     231    virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }
     232    virtual Expression *build() const;
     233
     234    virtual void print( std::ostream &, int indent = 0 ) const;
     235    virtual void printOneLine( std::ostream &, int indent = 0 ) const;
     236  private:
     237    StatementNode *init;
     238    ExpressionNode *condition;
     239    ExpressionNode *change;
     240};
     241
     242class ValofExprNode : public ExpressionNode {
     243  public:
     244    ValofExprNode();
     245    ValofExprNode( StatementNode *s = 0 );
     246    ValofExprNode( const ValofExprNode &other );
     247    ~ValofExprNode();
    186248 
    187 private:
    188   Type type;
    189   static const char *OpName[];
    190 };
    191 
    192 
    193 class CompositeExprNode : public ExpressionNode {
    194 public:
    195   CompositeExprNode(void);
    196   CompositeExprNode(std::string *);
    197   CompositeExprNode(ExpressionNode *f, ExpressionNode *args = 0);
    198   CompositeExprNode(ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2);
    199   CompositeExprNode( const CompositeExprNode &other );
    200   virtual ~CompositeExprNode();
    201 
    202   virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); }
    203   virtual Expression *build() const;
    204 
    205   virtual void print(std::ostream &, int indent = 0) const;
    206   virtual void printOneLine(std::ostream &, int indent = 0) const;
    207 
    208   void set_function(ExpressionNode *);
    209   void set_args(ExpressionNode *);
    210 
    211   void add_arg(ExpressionNode *);
    212 
    213   ExpressionNode *get_function() const;
    214   ExpressionNode *get_args() const;
    215 
    216 private:
    217   ExpressionNode *function;
    218   ExpressionNode *arguments;
    219 };
    220 
    221 class CommaExprNode : public CompositeExprNode {
    222 public:
    223   CommaExprNode();
    224   CommaExprNode(ExpressionNode *);
    225   CommaExprNode(ExpressionNode *, ExpressionNode *);
    226   CommaExprNode( const CommaExprNode &other );
    227 
    228   virtual CommaExprNode *add_to_list(ExpressionNode *);
    229   virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
    230 };
    231 
    232 class ForCtlExprNode : public ExpressionNode {
    233 public:
    234   ForCtlExprNode(ParseNode *, ExpressionNode *, ExpressionNode *) throw (SemanticError);
    235   ForCtlExprNode( const ForCtlExprNode &other );
    236   ~ForCtlExprNode();
    237 
    238   StatementNode *get_init() const { return init; }
    239   ExpressionNode *get_condition() const { return condition; }
    240   ExpressionNode *get_change() const { return change; }
    241 
    242   virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }
    243   virtual Expression *build() const;
    244 
    245   virtual void print( std::ostream &, int indent = 0 ) const;
    246   virtual void printOneLine( std::ostream &, int indent = 0 ) const;
    247 private:
    248   StatementNode *init;
    249   ExpressionNode *condition;
    250   ExpressionNode *change;
    251 };
    252 
    253 class ValofExprNode : public ExpressionNode {
    254 public:
    255   ValofExprNode();
    256   ValofExprNode( StatementNode *s = 0 );
    257   ValofExprNode( const ValofExprNode &other );
    258   ~ValofExprNode();
    259  
    260   virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
    261 
    262   StatementNode *get_body() const { return body; }
    263   void print( std::ostream &, int indent = 0 ) const;
    264   void printOneLine( std::ostream &, int indent = 0 ) const;
    265   Expression *build() const;
    266 
    267 private:
    268   StatementNode *body;
     249    virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
     250
     251    StatementNode *get_body() const { return body; }
     252    void print( std::ostream &, int indent = 0 ) const;
     253    void printOneLine( std::ostream &, int indent = 0 ) const;
     254    Expression *build() const;
     255
     256  private:
     257    StatementNode *body;
    269258};
    270259
    271260class TypeData;
    272261
    273 class DeclarationNode : public ParseNode
    274 {
    275 public:
    276   enum Qualifier { Const, Restrict, Volatile, Lvalue };
    277   enum StorageClass { Static, Auto, Extern, Register, Inline, Fortran };
    278   enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
    279   enum Modifier { Signed, Unsigned, Short, Long };
    280   enum TyCon { Struct, Union, Context };
    281   enum TypeClass { Type, Dtype, Ftype };
    282 
    283   static const char *qualifierName[];
    284   static const char *basicTypeName[];
    285   static const char *modifierName[];
    286   static const char *tyConName[];
    287   static const char *typeClassName[];
    288 
    289   static DeclarationNode *newFunction( std::string* name, DeclarationNode *ret, DeclarationNode *param,
    290                                        StatementNode *body, bool newStyle = false );
    291   static DeclarationNode *newQualifier( Qualifier );
    292   static DeclarationNode *newStorageClass( StorageClass );
    293   static DeclarationNode *newBasicType( BasicType );
    294   static DeclarationNode *newModifier( Modifier );
    295   static DeclarationNode *newForall( DeclarationNode* );
    296   static DeclarationNode *newFromTypedef( std::string* );
    297   static DeclarationNode *newAggregate( TyCon kind, std::string* name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields );
    298   static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
    299   static DeclarationNode *newEnumConstant( std::string* name, ExpressionNode *constant );
    300   static DeclarationNode *newName( std::string* );
    301   static DeclarationNode *newFromTypeGen( std::string*, ExpressionNode *params );
    302   static DeclarationNode *newTypeParam( TypeClass, std::string* );
    303   static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
    304   static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params );
    305   static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams );
    306   static DeclarationNode *newPointer( DeclarationNode *qualifiers );
    307   static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic );
    308   static DeclarationNode *newVarArray( DeclarationNode *qualifiers );
    309   static DeclarationNode *newBitfield( ExpressionNode *size );
    310   static DeclarationNode *newTuple( DeclarationNode *members );
    311   static DeclarationNode *newTypeof( ExpressionNode *expr );
    312   static DeclarationNode *newAttr( std::string*, ExpressionNode *expr );
    313   static DeclarationNode *newAttr( std::string*, DeclarationNode *type );
    314 
    315   DeclarationNode *addQualifiers( DeclarationNode* );
    316   DeclarationNode *copyStorageClasses( DeclarationNode* );
    317   DeclarationNode *addType( DeclarationNode* );
    318   DeclarationNode *addTypedef();
    319   DeclarationNode *addAssertions( DeclarationNode* );
    320   DeclarationNode *addName( std::string* );
    321   DeclarationNode *addBitfield( ExpressionNode *size );
    322   DeclarationNode *addVarArgs();
    323   DeclarationNode *addFunctionBody( StatementNode *body );
    324   DeclarationNode *addOldDeclList( DeclarationNode *list );
    325   DeclarationNode *addPointer( DeclarationNode *qualifiers );
    326   DeclarationNode *addArray( DeclarationNode *array );
    327   DeclarationNode *addNewPointer( DeclarationNode *pointer );
    328   DeclarationNode *addNewArray( DeclarationNode *array );
    329   DeclarationNode *addParamList( DeclarationNode *list );
    330   DeclarationNode *addIdList( DeclarationNode *list );       // old-style functions
    331   DeclarationNode *addInitializer( InitializerNode *init );
    332 
    333   DeclarationNode *cloneType( std::string *newName );
    334   DeclarationNode *cloneType( DeclarationNode *existing );
    335   DeclarationNode *cloneType( int ) { return cloneType( (std::string*)0 ); }
    336   DeclarationNode *cloneBaseType( std::string *newName );
    337   DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
    338 
    339   DeclarationNode *appendList( DeclarationNode * );
    340 
    341   DeclarationNode *clone() const;
    342   void print( std::ostream &, int indent = 0 ) const;
    343   void printList( std::ostream &, int indent = 0 ) const;
    344 
    345   Declaration *build() const;
    346   ::Type *buildType() const;
    347 
    348   bool get_hasEllipsis() const;
    349   std::string get_name() const { return name; }
    350   LinkageSpec::Type get_linkage() const { return linkage; }
    351   DeclarationNode *extractAggregate() const;
    352 
    353   DeclarationNode();
    354   ~DeclarationNode();
    355 private:
    356   Declaration::StorageClass buildStorageClass() const;
    357   bool buildInline() const;
    358 
    359   TypeData *type;
    360   std::string name;
    361   std::list< StorageClass > storageClasses;
    362   ExpressionNode *bitfieldWidth;
    363   InitializerNode *initializer;
    364   bool hasEllipsis;
    365   LinkageSpec::Type linkage;
    366 
    367   static UniqueName anonymous;
     262class DeclarationNode : public ParseNode {
     263  public:
     264    enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic };
     265    enum StorageClass { Static, Auto, Extern, Register, Inline, Fortran };
     266    enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
     267    enum Modifier { Signed, Unsigned, Short, Long };
     268    enum TyCon { Struct, Union, Context };
     269    enum TypeClass { Type, Dtype, Ftype };
     270
     271    static const char *qualifierName[];
     272    static const char *basicTypeName[];
     273    static const char *modifierName[];
     274    static const char *tyConName[];
     275    static const char *typeClassName[];
     276
     277    static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param,
     278                                         StatementNode *body, bool newStyle = false );
     279    static DeclarationNode *newQualifier( Qualifier );
     280    static DeclarationNode *newStorageClass( StorageClass );
     281    static DeclarationNode *newBasicType( BasicType );
     282    static DeclarationNode *newModifier( Modifier );
     283    static DeclarationNode *newForall( DeclarationNode *);
     284    static DeclarationNode *newFromTypedef( std::string *);
     285    static DeclarationNode *newAggregate( TyCon kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields );
     286    static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
     287    static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
     288    static DeclarationNode *newName( std::string *);
     289    static DeclarationNode *newFromTypeGen( std::string*, ExpressionNode *params );
     290    static DeclarationNode *newTypeParam( TypeClass, std::string *);
     291    static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
     292    static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params );
     293    static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams );
     294    static DeclarationNode *newPointer( DeclarationNode *qualifiers );
     295    static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic );
     296    static DeclarationNode *newVarArray( DeclarationNode *qualifiers );
     297    static DeclarationNode *newBitfield( ExpressionNode *size );
     298    static DeclarationNode *newTuple( DeclarationNode *members );
     299    static DeclarationNode *newTypeof( ExpressionNode *expr );
     300    static DeclarationNode *newAttr( std::string*, ExpressionNode *expr );
     301    static DeclarationNode *newAttr( std::string*, DeclarationNode *type );
     302
     303    DeclarationNode *addQualifiers( DeclarationNode *);
     304    DeclarationNode *copyStorageClasses( DeclarationNode *);
     305    DeclarationNode *addType( DeclarationNode *);
     306    DeclarationNode *addTypedef();
     307    DeclarationNode *addAssertions( DeclarationNode *);
     308    DeclarationNode *addName( std::string *);
     309    DeclarationNode *addBitfield( ExpressionNode *size );
     310    DeclarationNode *addVarArgs();
     311    DeclarationNode *addFunctionBody( StatementNode *body );
     312    DeclarationNode *addOldDeclList( DeclarationNode *list );
     313    DeclarationNode *addPointer( DeclarationNode *qualifiers );
     314    DeclarationNode *addArray( DeclarationNode *array );
     315    DeclarationNode *addNewPointer( DeclarationNode *pointer );
     316    DeclarationNode *addNewArray( DeclarationNode *array );
     317    DeclarationNode *addParamList( DeclarationNode *list );
     318    DeclarationNode *addIdList( DeclarationNode *list );       // old-style functions
     319    DeclarationNode *addInitializer( InitializerNode *init );
     320
     321    DeclarationNode *cloneType( std::string *newName );
     322    DeclarationNode *cloneType( DeclarationNode *existing );
     323    DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); }
     324    DeclarationNode *cloneBaseType( std::string *newName );
     325    DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
     326
     327    DeclarationNode *appendList( DeclarationNode  *);
     328
     329    DeclarationNode *clone() const;
     330    void print( std::ostream &, int indent = 0 ) const;
     331    void printList( std::ostream &, int indent = 0 ) const;
     332
     333    Declaration *build() const;
     334    ::Type *buildType() const;
     335
     336    bool get_hasEllipsis() const;
     337    std::string get_name() const { return name; }
     338    LinkageSpec::Type get_linkage() const { return linkage; }
     339    DeclarationNode *extractAggregate() const;
     340
     341    DeclarationNode();
     342    ~DeclarationNode();
     343  private:
     344    Declaration::StorageClass buildStorageClass() const;
     345    bool buildInline() const;
     346
     347    TypeData *type;
     348    std::string name;
     349    std::list< StorageClass > storageClasses;
     350    ExpressionNode *bitfieldWidth;
     351    InitializerNode *initializer;
     352    bool hasEllipsis;
     353    LinkageSpec::Type linkage;
     354
     355    static UniqueName anonymous;
    368356};
    369357
    370358class StatementNode : public ParseNode {
    371 public:
    372   enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru,
    373               While, Do,        For,
    374               Goto,  Continue,  Break,   Return,  Throw,
    375               Try,   Catch,     Finally, Asm,
    376               Decl
    377             };
    378 
    379   StatementNode( void );
    380   StatementNode( std::string );
    381   StatementNode( Type, ExpressionNode *e = 0, StatementNode *s = 0 );
    382   StatementNode( Type, std::string *target );
    383   StatementNode( DeclarationNode *decl );
    384 
    385 
    386   ~StatementNode(void);
    387 
    388   static StatementNode * newCatchStmt(DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
    389 
    390   void set_control(ExpressionNode *);
    391   StatementNode * set_block(StatementNode *);
    392 
    393   ExpressionNode *get_control() const ;
    394   StatementNode *get_block() const;
    395   StatementNode::Type get_type(void) const;
    396 
    397   StatementNode *add_label(std::string *);
    398   std::list<std::string> *get_labels() const;
    399 
    400   void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
    401   void setCatchRest( bool newVal ) { isCatchRest = newVal; }
    402 
    403   std::string get_target() const;
    404 
    405   StatementNode *add_controlexp(ExpressionNode *);
    406   StatementNode *append_block(StatementNode *);
    407   StatementNode *append_last_case(StatementNode *);
    408 
    409   void print( std::ostream &, int indent = 0) const;
    410 
    411   virtual StatementNode *clone() const;
    412 
    413   virtual Statement *build() const;
    414 
    415 private:
    416   static const char *StType[];
    417   Type type;
    418   ExpressionNode *control;
    419   StatementNode *block;
    420   std::list<std::string> *labels;
    421   std::string *target; // target label for jump statements
    422   DeclarationNode *decl;
    423 
    424   bool isCatchRest;
     359  public:
     360    enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru,
     361                While, Do,        For,
     362                Goto,  Continue,  Break,   Return,  Throw,
     363                Try,   Catch,     Finally, Asm,
     364                Decl
     365    };
     366
     367    StatementNode( void );
     368    StatementNode( std::string );
     369    StatementNode( Type, ExpressionNode *e = 0, StatementNode *s = 0 );
     370    StatementNode( Type, std::string *target );
     371    StatementNode( DeclarationNode *decl );
     372
     373
     374    ~StatementNode( void );
     375
     376    static StatementNode  *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
     377
     378    void set_control( ExpressionNode * );
     379    StatementNode * set_block( StatementNode * );
     380
     381    ExpressionNode *get_control() const ;
     382    StatementNode *get_block() const;
     383    StatementNode::Type get_type( void ) const;
     384
     385    StatementNode *add_label( std::string * );
     386    std::list<std::string> *get_labels() const;
     387
     388    void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
     389    void setCatchRest( bool newVal ) { isCatchRest = newVal; }
     390
     391    std::string get_target() const;
     392
     393    StatementNode *add_controlexp( ExpressionNode * );
     394    StatementNode *append_block( StatementNode * );
     395    StatementNode *append_last_case( StatementNode * );
     396
     397    void print( std::ostream &, int indent = 0) const;
     398
     399    virtual StatementNode *clone() const;
     400
     401    virtual Statement *build() const;
     402  private:
     403    static const char *StType[];
     404    Type type;
     405    ExpressionNode *control;
     406    StatementNode *block;
     407    std::list<std::string> *labels;
     408    std::string *target;                                // target label for jump statements
     409    DeclarationNode *decl;
     410
     411    bool isCatchRest;
    425412};
    426413
    427414class CompoundStmtNode : public StatementNode {
    428 public:
    429   CompoundStmtNode(void);
    430   CompoundStmtNode(std::string *);
    431   CompoundStmtNode(StatementNode *);
    432   ~CompoundStmtNode();
    433 
    434   void add_statement(StatementNode *);
    435 
    436   void print( std::ostream &, int indent = 0 ) const;
    437 
    438   virtual Statement *build() const;
    439 
    440 private:
    441   StatementNode *first, *last;
     415  public:
     416    CompoundStmtNode( void );
     417    CompoundStmtNode( std::string * );
     418    CompoundStmtNode( StatementNode * );
     419    ~CompoundStmtNode();
     420
     421    void add_statement( StatementNode * );
     422
     423    void print( std::ostream &, int indent = 0 ) const;
     424
     425    virtual Statement *build() const;
     426  private:
     427    StatementNode *first, *last;
    442428};
    443429
    444430class NullStmtNode : public CompoundStmtNode {
    445 public:
    446   Statement *build() const;
    447   void print(std::ostream &, int indent = 0) const;
     431  public:
     432    Statement *build() const;
     433    void print( std::ostream &, int indent = 0) const;
    448434};
    449435
    450436class InitializerNode : public ParseNode {
    451 public:
    452   InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 );
    453   InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
    454   ~InitializerNode();
    455 
    456   ExpressionNode *get_expression() const { return expr; }
    457 
    458   InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
    459   ExpressionNode *get_designators() const { return designator; }
    460 
    461   InitializerNode *next_init() const { return kids; }
    462 
    463   void print( std::ostream &, int indent = 0 ) const;
    464   void printOneLine( std::ostream & ) const;
    465 
    466   virtual Initializer *build() const;
    467 
    468 private:
    469   ExpressionNode *expr;
    470   bool aggregate;
    471   ExpressionNode *designator; // may be list
    472   InitializerNode *kids;
     437  public:
     438    InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 );
     439    InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
     440    ~InitializerNode();
     441
     442    ExpressionNode *get_expression() const { return expr; }
     443
     444    InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
     445    ExpressionNode *get_designators() const { return designator; }
     446
     447    InitializerNode *next_init() const { return kids; }
     448
     449    void print( std::ostream &, int indent = 0 ) const;
     450    void printOneLine( std::ostream & ) const;
     451
     452    virtual Initializer *build() const;
     453  private:
     454    ExpressionNode *expr;
     455    bool aggregate;
     456    ExpressionNode *designator; // may be list
     457    InitializerNode *kids;
    473458};
    474459
     
    477462template< typename SynTreeType, typename NodeType >
    478463void
    479 buildList( const NodeType *firstNode, std::list< SynTreeType* > &outputList )
     464buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList )
    480465{
    481   SemanticError errors;
    482   std::back_insert_iterator< std::list< SynTreeType* > > out( outputList );
    483   const NodeType *cur = firstNode;
    484 
    485   while( cur ) {
    486     try {
    487       SynTreeType *result = dynamic_cast< SynTreeType* >( cur->build() );
    488       if( result ) {
    489         *out++ = result;
    490       } else {
    491       }
    492     } catch( SemanticError &e ) {
    493       errors.append( e );
    494     }
    495     cur = dynamic_cast< NodeType* >( cur->get_link() );
    496   }
    497   if( !errors.isEmpty() ) {
    498     throw errors;
    499   }
     466    SemanticError errors;
     467    std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
     468    const NodeType *cur = firstNode;
     469
     470    while ( cur ) {
     471        try {
     472            SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() );
     473            if ( result ) {
     474                *out++ = result;
     475            } else {
     476            } // if
     477        } catch( SemanticError &e ) {
     478            errors.append( e );
     479        } // try
     480        cur = dynamic_cast< NodeType *>( cur->get_link() );
     481    } // while
     482    if ( !errors.isEmpty() ) {
     483        throw errors;
     484    } // if
    500485}
    501486
    502487// in DeclarationNode.cc
    503 void buildList( const DeclarationNode *firstNode, std::list< Declaration* > &outputList );
    504 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType* > &outputList );
    505 void buildTypeList( const DeclarationNode *firstNode, std::list< Type* > &outputList );
     488void buildList( const DeclarationNode *firstNode, std::list< Declaration *> &outputList );
     489void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
     490void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList );
    506491
    507492// in ExpressionNode.cc
     
    509494ExpressionNode *tupleContents( ExpressionNode *tuple );
    510495
    511 #endif /* #ifndef PARSENODE_H */
     496#endif // PARSENODE_H
    512497
    513498// Local Variables: //
  • translator/Parser/TypeData.cc

    rad17ba6a rbdd516a  
    541541          case DeclarationNode::Lvalue:
    542542            q.isLvalue = true;
     543            break;
     544          case DeclarationNode::Atomic:
     545            q.isAtomic = true;
    543546            break;
    544547        }
  • translator/Parser/TypeData.h

    rad17ba6a rbdd516a  
    33
    44#include <list>
     5
    56#include "ParseNode.h"
    6 #include "SynTree/SynTree.h"
    77#include "SynTree/Type.h"
    8 #include "SynTree/Declaration.h"
    9 #include "SemanticError.h"
    10 #include "LinkageSpec.h"
    118
    129struct TypeData {
  • translator/Parser/cfa.y

    rad17ba6a rbdd516a  
    1010 * Created On       : Sat Sep  1 20:22:55 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sat Jan 17 09:23:45 2015
    13  * Update Count     : 908
     12 * Last Modified On : Wed Apr 15 15:11:16 2015
     13 * Update Count     : 913
    1414 */
    1515
     
    11441144        declaration_specifier declarator asm_name_opt initializer_opt
    11451145                {
    1146                         typedefTable.addToEnclosingScope( TypedefTable::ID);
     1146                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11471147                        $$ = ($2->addType( $1 ))->addInitializer($4);
    11481148                }
     
    12011201        | LVALUE                                        /* CFA */
    12021202                { $$ = DeclarationNode::newQualifier( DeclarationNode::Lvalue ); }
     1203        | ATOMIC
     1204                { $$ = DeclarationNode::newQualifier( DeclarationNode::Atomic ); }
    12031205        | FORALL '('
    12041206                {
  • translator/Parser/parseutility.cc

    rad17ba6a rbdd516a  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: parseutility.cc,v 1.2 2005/08/29 20:14:15 rcbilson Exp $
    5  *
    6  */
    7 
    81#include "parseutility.h"
    92#include "SynTree/Type.h"
     
    114
    125
    13 Expression *
    14 notZeroExpr( Expression *orig )
    15 {
     6Expression *notZeroExpr( Expression *orig ) {
    167      UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) );
    178      comparison->get_args().push_back( orig );
  • translator/Parser/parseutility.h

    rad17ba6a rbdd516a  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: parseutility.h,v 1.2 2005/08/29 20:14:15 rcbilson Exp $
    5  *
    6  */
    7 
    81#ifndef PARSER_PARSEUTILITY_H
    92#define PARSER_PARSEUTILITY_H
     
    136Expression *notZeroExpr( Expression *orig );
    147
    15 #endif /* #ifndef PARSER_PARSEUTILITY_H */
     8#endif // PARSER_PARSEUTILITY_H
Note: See TracChangeset for help on using the changeset viewer.