Changeset e04ef3a for src/Parser


Ignore:
Timestamp:
Jun 14, 2016, 12:53:03 PM (8 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, with_gc
Children:
c8c03683
Parents:
55ba733
Message:

add gcc extension, first attempt, not done yet

Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r55ba733 re04ef3a  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr  8 15:43:05 2016
    13 // Update Count     : 296
     12// Last Modified On : Mon Jun 13 14:46:17 2016
     13// Update Count     : 307
    1414//
    1515
     
    3232using namespace std;
    3333
    34 ExpressionNode::ExpressionNode() : ParseNode(), argName( 0 ) {}
    35 
    36 ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ), argName( 0 ) {}
    37 
    38 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ) {
     34ExpressionNode::ExpressionNode() : ParseNode() {}
     35
     36ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ) {}
     37
     38ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ), extension( other.extension ) {
    3939        if ( other.argName ) {
    4040                argName = other.argName->clone();
     
    344344
    345345Expression *DesignatorNode::build() const {
    346         Expression * ret = get_argName()->build();
     346        Expression * ret = maybeBuild<Expression>(get_argName());
    347347
    348348        if ( isArrayIndex ) {
     
    389389        "Cond", "NCond",
    390390        // diadic
    391         "SizeOf", "AlignOf", "OffsetOf", "Attr", "CompLit", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&",
     391        "SizeOf", "AlignOf", "OffsetOf", "Attr", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&",
    392392        "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?",
    393393        "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?",
     
    466466
    467467        if ( ! ( op = dynamic_cast<OperatorNode *>( function ) ) ) { // function as opposed to operator
    468                 return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));
     468                return new UntypedExpr( maybeBuild<Expression>(function), args, maybeBuild< Expression >( get_argName() ));
    469469        } // if
    470470
     
    550550                        if ( dynamic_cast< VoidType* >( targetType ) ) {
    551551                                delete targetType;
    552                                 return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );
     552                                return new CastExpr( maybeBuild<Expression>(expr_node), maybeBuild< Expression >( get_argName() ) );
    553553                        } else {
    554                                 return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
     554                                return new CastExpr( maybeBuild<Expression>(expr_node),targetType, maybeBuild< Expression >( get_argName() ) );
    555555                        } // if
    556556                }
     
    621621                        assert( var );
    622622                        if ( ! get_args()->get_link() ) {
    623                                 return new AttrExpr( var->build(), ( Expression*)0);
     623                                return new AttrExpr( maybeBuild<Expression>(var), ( Expression*)0);
    624624                        } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {
    625                                 return new AttrExpr( var->build(), arg->get_decl()->buildType());
     625                                return new AttrExpr( maybeBuild<Expression>(var), arg->get_decl()->buildType());
    626626                        } else {
    627                                 return new AttrExpr( var->build(), args.back());
    628                         } // if
    629                 }
    630           case OperatorNode::CompLit:
    631                 throw UnimplementedError( "C99 compound literals" );
    632                 // the short-circuited operators
     627                                return new AttrExpr( maybeBuild<Expression>(var), args.back());
     628                        } // if
     629                }
    633630          case OperatorNode::Or:
    634631          case OperatorNode::And:
     
    719716
    720717Expression *AsmExprNode::build() const {
    721         return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *)constraint->build(), operand->build() );
     718        return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *)maybeBuild<Expression>(constraint), maybeBuild<Expression>(operand) );
    722719}
    723720
     
    796793
    797794Expression *ValofExprNode::build() const {
    798         return new UntypedValofExpr ( get_body()->build(), maybeBuild< Expression >( get_argName() ) );
     795        return new UntypedValofExpr ( maybeBuild<Statement>(get_body()), maybeBuild< Expression >( get_argName() ) );
    799796}
    800797
     
    908905
    909906Expression *CompoundLiteralNode::build() const {
    910         Declaration * newDecl = type->build();                          // compound literal type
     907        Declaration * newDecl = maybeBuild<Declaration>(type); // compound literal type
    911908        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
    912                 return new CompoundLiteralExpr( newDeclWithType->get_type(), kids->build() );
     909                return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) );
    913910        // these types do not have associated type information
    914911        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
    915                 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), kids->build() );
     912                return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) );
    916913        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
    917                 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), kids->build() );
     914                return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) );
    918915        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
    919                 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), kids->build() );
     916                return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) );
    920917        } else {
    921918                assert( false );
  • src/Parser/ParseNode.h

    r55ba733 re04ef3a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Apr 14 15:37:52 2016
    13 // Update Count     : 205
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jun 13 16:04:47 2016
     13// Update Count     : 240
    1414//
    1515
     
    2020#include <list>
    2121#include <iterator>
     22#include <memory>
    2223
    2324#include "Common/utility.h"
    2425#include "Parser/LinkageSpec.h"
    2526#include "SynTree/Type.h"
     27#include "SynTree/Expression.h"
    2628//#include "SynTree/Declaration.h"
    2729#include "Common/UniqueName.h"
     
    7981        ExpressionNode *set_argName( const std::string *aName );
    8082        ExpressionNode *set_argName( ExpressionNode *aDesignator );
     83        bool get_extension() const { return extension; }
     84        ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
    8185
    8286        virtual void print( std::ostream &, int indent = 0) const = 0;
     
    8791        void printDesignation ( std::ostream &, int indent = 0) const;
    8892  private:
    89         ExpressionNode *argName;
     93        ExpressionNode *argName = 0;
     94        bool extension = false;
     95};
     96
     97template< typename T >
     98struct maybeBuild_t<Expression, T> {
     99        static inline Expression * doit( const T *orig ) {
     100                if ( orig ) {
     101                        Expression *p = orig->build();
     102                        p->set_extension( orig->get_extension() );
     103                        return p;
     104                } else {
     105                        return 0;
     106                } // if
     107        }
    90108};
    91109
     
    179197                                Cond, NCond,
    180198                                // diadic
    181                                 SizeOf, AlignOf, OffsetOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And,
     199                                SizeOf, AlignOf, OffsetOf, Attr, Plus, Minus, Mul, Div, Mod, Or, And,
    182200                                BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
    183201                                Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
     
    574592        while ( cur ) {
    575593                try {
    576                         SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() );
     594//                      SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) );
     595                        SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) );
    577596                        if ( result ) {
    578597                                *out++ = result;
  • src/Parser/StatementNode.cc

    r55ba733 re04ef3a  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 30 14:39:39 2015
    13 // Update Count     : 130
     12// Last Modified On : Thu Jun  9 14:18:46 2016
     13// Update Count     : 132
    1414//
    1515
     
    222222                                branches.pop_front();
    223223                        } // if
    224                         return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb );
     224                        return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb );
    225225                }
    226226          case While:
    227227                assert( branches.size() == 1 );
    228                 return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front() );
     228                return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() );
    229229          case Do:
    230230                assert( branches.size() == 1 );
    231                 return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front(), true );
     231                return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true );
    232232          case For:
    233233                {
     
    244244                        Expression *cond = 0;
    245245                        if ( ctl->get_condition() != 0 )
    246                                 cond = notZeroExpr( ctl->get_condition()->build() );
     246                                cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) );
    247247
    248248                        Expression *incr = 0;
    249249                        if ( ctl->get_change() != 0 )
    250                                 incr = ctl->get_change()->build();
     250                                incr = maybeBuild<Expression>(ctl->get_change());
    251251
    252252                        return new ForStmt( labs, init, cond, incr, branches.front() );
    253253                }
    254254          case Switch:
    255                 return new SwitchStmt( labs, get_control()->build(), branches );
     255                return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches );
    256256          case Choose:
    257                 return new ChooseStmt( labs, get_control()->build(), branches );
     257                return new ChooseStmt( labs, maybeBuild<Expression>(get_control()), branches );
    258258          case Fallthru:
    259259                return new FallthruStmt( labs );
    260260          case Case:
    261                 return new CaseStmt( labs, get_control()->build(), branches );
     261                return new CaseStmt( labs, maybeBuild<Expression>(get_control()), branches );
    262262          case Default:
    263263                return new CaseStmt( labs, 0, branches, true );
     
    266266                        if ( get_target() == "" ) {                                     // computed goto
    267267                                assert( get_control() != 0 );
    268                                 return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto );
     268                                return new BranchStmt( labs, maybeBuild<Expression>(get_control()), BranchStmt::Goto );
    269269                        } // if
    270270
  • src/Parser/parser.cc

    r55ba733 re04ef3a  
    52995299/* Line 1806 of yacc.c  */
    53005300#line 432 "parser.yy"
    5301     { (yyval.en) = (yyvsp[(2) - (2)].en); }
     5301    { (yyval.en) = (yyvsp[(2) - (2)].en)->set_extension( true ); }
    53025302    break;
    53035303
     
    58095809/* Line 1806 of yacc.c  */
    58105810#line 685 "parser.yy"
    5811     { (yyval.sn) = new StatementNode( (yyvsp[(2) - (2)].decl) ); }
     5811    { (yyval.sn) = new StatementNode( (yyvsp[(2) - (2)].decl) )/*->set_extension( true )*/; }
    58125812    break;
    58135813
     
    71227122/* Line 1806 of yacc.c  */
    71237123#line 1475 "parser.yy"
    7124     { (yyval.decl) = (yyvsp[(2) - (3)].decl); }
     7124    { (yyval.decl) = (yyvsp[(2) - (3)].decl)/*->set_extension( true )*/; }
    71257125    break;
    71267126
     
    71297129/* Line 1806 of yacc.c  */
    71307130#line 1478 "parser.yy"
    7131     { (yyval.decl) = (yyvsp[(2) - (3)].decl); }
     7131    { (yyval.decl) = (yyvsp[(2) - (3)].decl)/*->set_extension( true )*/; }
    71327132    break;
    71337133
     
    79137913/* Line 1806 of yacc.c  */
    79147914#line 1994 "parser.yy"
    7915     { (yyval.decl) = (yyvsp[(2) - (2)].decl); }
     7915    { (yyval.decl) = (yyvsp[(2) - (2)].decl)/*->set_extension( true )*/; }
    79167916    break;
    79177917
  • src/Parser/parser.yy

    r55ba733 re04ef3a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun  7 08:08:31 2016
    13 // Update Count     : 1560
     12// Last Modified On : Mon Jun 13 15:00:23 2016
     13// Update Count     : 1578
    1414//
    1515
     
    430430                { $$ = $1; }
    431431        | EXTENSION cast_expression                                                     // GCC
    432                 { $$ = $2; }
     432                { $$ = $2->set_extension( true ); }
    433433        | ptrref_operator cast_expression                                       // CFA
    434434                { $$ = new CompositeExprNode( $1, $2 ); }
     
    683683                { $$ = new StatementNode( $1 ); }
    684684        | EXTENSION declaration                                                         // GCC
    685                 { $$ = new StatementNode( $2 ); }
     685                { $$ = new StatementNode( $2 )/*->set_extension( true )*/; }
    686686        | function_definition
    687687                { $$ = new StatementNode( $1 ); }
     
    14731473        new_field_declaring_list ';'                                            // CFA, new style field declaration
    14741474        | EXTENSION new_field_declaring_list ';'                        // GCC
    1475                 { $$ = $2; }
     1475                { $$ = $2/*->set_extension( true )*/; }
    14761476        | field_declaring_list ';'
    14771477        | EXTENSION field_declaring_list ';'                            // GCC
    1478                 { $$ = $2; }
     1478                { $$ = $2/*->set_extension( true )*/; }
    14791479        ;
    14801480
     
    19921992                }
    19931993        | EXTENSION external_definition
    1994                 { $$ = $2; }
     1994                { $$ = $2/*->set_extension( true )*/; }
    19951995        ;
    19961996
Note: See TracChangeset for help on using the changeset viewer.