Changeset 17cd4eb for translator/Parser


Ignore:
Timestamp:
Jan 7, 2015, 6:04:42 PM (11 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:
0b8cd722
Parents:
d9a0e76
Message:

fixed restrict, fixed parameter copy, introduced name table for types, changed variable after to string

Location:
translator/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/DeclarationNode.cc

    rd9a0e76 r17cd4eb  
    1919/* these must remain in the same order as the corresponding DeclarationNode enumerations */
    2020const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue" };
    21 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "bool", "complex", "imaginary" };
     21const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" };
    2222const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" };
    2323const char *DeclarationNode::tyConName[] = { "struct", "union", "context" };
     
    799799                } else if ( StructDecl *agg = dynamic_cast< StructDecl* >( decl ) ) {
    800800                    StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    801                    *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );
     801                    *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );
    802802                    delete agg;
    803803                } else if ( UnionDecl *agg = dynamic_cast< UnionDecl* >( decl ) ) {
    804804                    UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    805                    *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );
     805                    *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );
    806806                }
    807807            }
  • translator/Parser/InitializerNode.cc

    rd9a0e76 r17cd4eb  
    4343        if ( designator != 0 ) {
    4444            os << "designated by: (";
    45             ExpressionNode  *curdes = designator;
     45            ExpressionNode *curdes = designator;
    4646            while( curdes != 0) {
    4747                curdes->printOneLine(os);
    4848                curdes = (ExpressionNode *)(curdes->get_link());
    4949                if ( curdes ) os << ", ";
    50             }
     50            } // while
    5151            os << ")";
    52         }
     52        } // if
    5353        if ( expr ) expr->printOneLine(os);
    5454    } else {  // It's an aggregate
     
    5757            next_init()->printOneLine(os);
    5858        if (aggregate) os << "--]";
    59     }
     59    } // if
    6060
    6161    InitializerNode *moreInit;
     
    8888        if ( get_expression() != 0)
    8989            return new SingleInit( get_expression()->build(), designators );
    90     }
     90    } // if
    9191
    9292    return 0;
  • translator/Parser/ParseNode.h

    rd9a0e76 r17cd4eb  
    456456  ExpressionNode *get_expression() const { return expr; }
    457457
    458   InitializerNode *set_designators( ExpressionNode *des ) { designator = des;  return this; }
     458  InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
    459459  ExpressionNode *get_designators() const { return designator; }
    460460
  • translator/Parser/TypeData.cc

    rd9a0e76 r17cd4eb  
    560560            if ( *i == DeclarationNode::Void ) {
    561561                if ( basic->typeSpec.size() != 1 || !basic->modifiers.empty() ) {
    562                     throw SemanticError( "invalid type specifier \"void\" in type ", this );
     562                    throw SemanticError( "invalid type specifier \"void\" in type: ", this );
    563563                } else {
    564564                    return new VoidType( buildQualifiers() );
     
    571571              case DeclarationNode::Float:
    572572                if ( sawDouble ) {
    573                     throw SemanticError( "invalid type specifier \"float\" in type ", this );
     573                    throw SemanticError( "invalid type specifier \"float\" in type: ", this );
    574574                } else {
    575575                    switch ( ret ) {
     
    581581                        break;
    582582                      default:
    583                         throw SemanticError( "invalid type specifier \"float\" in type ", this );
     583                        throw SemanticError( "invalid type specifier \"float\" in type: ", this );
    584584                    }
    585585                }
     
    587587              case DeclarationNode::Double:
    588588                if ( sawDouble ) {
    589                     throw SemanticError( "duplicate type specifier \"double\" in type ", this );
     589                    throw SemanticError( "duplicate type specifier \"double\" in type: ", this );
    590590                } else {
    591591                    switch ( ret ) {
     
    594594                        break;
    595595                      default:
    596                         throw SemanticError( "invalid type specifier \"double\" in type ", this );
     596                        throw SemanticError( "invalid type specifier \"double\" in type: ", this );
    597597                    }
    598598                }
     
    609609                    break;
    610610                  default:
    611                     throw SemanticError( "invalid type specifier \"complex\" in type ", this );
     611                    throw SemanticError( "invalid type specifier \"_Complex\" in type: ", this );
    612612                }
    613613                break;
     
    623623                    break;
    624624                  default:
    625                     throw SemanticError( "invalid type specifier \"imaginary\" in type ", this );
     625                    throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", this );
    626626                }
    627627                break;
    628628       
    629629              default:
    630                 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type ", this );
     630                throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", this );
    631631            }
    632632        }
     
    666666                    break;
    667667                  default:
    668                     throw SemanticError( "invalid type modifier \"long\" in type ", this );
     668                    throw SemanticError( "invalid type modifier \"long\" in type: ", this );
    669669                }
    670670            }
     
    683683                    break;
    684684                  default:
    685                     throw SemanticError( "invalid type modifier \"short\" in type ", this );
     685                    throw SemanticError( "invalid type modifier \"short\" in type: ", this );
    686686                }
    687687            }
     
    692692                ret = BasicType::SignedInt;
    693693            } else if ( sawSigned ) {
    694                 throw SemanticError( "duplicate type modifer \"signed\" in type ", this );
     694                throw SemanticError( "duplicate type modifer \"signed\" in type: ", this );
    695695            } else {
    696696                switch ( ret ) {
     
    702702                    break;
    703703                  default:
    704                     throw SemanticError( "invalid type modifer \"signed\" in type ", this );
     704                    throw SemanticError( "invalid type modifer \"signed\" in type: ", this );
    705705                }
    706706            }
     
    711711                ret = BasicType::UnsignedInt;
    712712            } else if ( sawSigned ) {
    713                 throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );
     713                throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this );
    714714            } else {
    715715                switch ( ret ) {
     
    727727                    break;
    728728                  default:
    729                     throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );
     729                    throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this );
    730730                }
    731731            }
  • translator/Parser/cfa.y

    rd9a0e76 r17cd4eb  
    1010 * Created On       : Sat Sep  1 20:22:55 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue Nov 25 23:52:54 2014
    13  * Update Count     : 890
     12 * Last Modified On : Wed Jan  7 09:19:57 2015
     13 * Update Count     : 906
    1414 */
    1515
     
    294294                /* ENUMERATIONconstant is not included here; it is treated as a variable with type
    295295                   "enumeration constant". */
    296         INTEGERconstant         { $$ = new ConstantNode(ConstantNode::Integer,   $1); }
    297         | FLOATINGconstant      { $$ = new ConstantNode(ConstantNode::Float,     $1); }
    298         | CHARACTERconstant     { $$ = new ConstantNode(ConstantNode::Character, $1); }
     296        INTEGERconstant                                 { $$ = new ConstantNode(ConstantNode::Integer,   $1); }
     297        | FLOATINGconstant                              { $$ = new ConstantNode(ConstantNode::Float,     $1); }
     298        | CHARACTERconstant                             { $$ = new ConstantNode(ConstantNode::Character, $1); }
    299299        ;
    300300
     
    320320
    321321string_literal_list:                                    /* juxtaposed strings are concatenated */
    322         STRINGliteral                           { $$ = new ConstantNode(ConstantNode::String, $1); }
    323         | string_literal_list STRINGliteral     { $$ = $1->append( $2 ); }
     322        STRINGliteral                                   { $$ = new ConstantNode(ConstantNode::String, $1); }
     323        | string_literal_list STRINGliteral             { $$ = $1->append( $2 ); }
    324324        ;
    325325
     
    352352                { $$ = new CompositeExprNode($1, $3); }
    353353        | postfix_expression '.' no_attr_identifier
    354                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), $1,
    355                                              new VarRefNode($3)); }
     354                { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), $1, new VarRefNode($3)); }
    356355        | postfix_expression '.' '[' push field_list pop ']' /* CFA, tuple field selector */
    357356        | postfix_expression ARROW no_attr_identifier
    358                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), $1,
    359                                              new VarRefNode($3)); }
     357                { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), $1, new VarRefNode($3)); }
    360358        | postfix_expression ARROW '[' push field_list pop ']' /* CFA, tuple field selector */
    361359        | postfix_expression ICR
     
    371369        argument_expression
    372370        | argument_expression_list ',' argument_expression
    373                                                 { $$ = (ExpressionNode *)($1->set_link($3)); }
     371                                                        { $$ = (ExpressionNode *)($1->set_link($3)); }
    374372        ;
    375373
     
    379377        | assignment_expression
    380378        | no_attr_identifier ':' assignment_expression
    381                                                 { $$ = $3->set_asArgName($1); }
     379                                                        { $$ = $3->set_asArgName($1); }
    382380                /* Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there
    383381                   is insufficient look ahead to distinguish between this list of parameter names and a tuple,
     
    391389field_list:                                             /* CFA, tuple field selector */
    392390        field
    393         | field_list ',' field                  { $$ = (ExpressionNode *)$1->set_link( $3 ); }
     391        | field_list ',' field                          { $$ = (ExpressionNode *)$1->set_link( $3 ); }
    394392        ;
    395393
    396394field:                                                  /* CFA, tuple field selector */
    397395        no_attr_identifier
    398                                                 { $$ = new VarRefNode( $1 ); }
     396                                                        { $$ = new VarRefNode( $1 ); }
    399397        | no_attr_identifier '.' field
    400                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $3); }
     398                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $3); }
    401399        | no_attr_identifier '.' '[' push field_list pop ']'
    402                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $5); }
     400                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $5); }
    403401        | no_attr_identifier ARROW field
    404                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $3); }
     402                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $3); }
    405403        | no_attr_identifier ARROW '[' push field_list pop ']'
    406                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $5); }
     404                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $5); }
    407405        ;
    408406
     
    440438                { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::AlignOf), new TypeValueNode($3)); }
    441439        | ANDAND no_attr_identifier                     /* GCC, address of label */
    442                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LabelAddress),
    443                                              new VarRefNode($2, true)); }
     440                { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LabelAddress), new VarRefNode($2, true)); }
    444441        ;
    445442
    446443unary_operator:
    447         '&'                               { $$ = new OperatorNode(OperatorNode::AddressOf); }
    448         | '+'                             { $$ = new OperatorNode(OperatorNode::UnPlus); }
    449         | '-'                             { $$ = new OperatorNode(OperatorNode::UnMinus); }
    450         | '~'                             { $$ = new OperatorNode(OperatorNode::BitNeg); }
     444        '&'                                             { $$ = new OperatorNode(OperatorNode::AddressOf); }
     445        | '+'                                           { $$ = new OperatorNode(OperatorNode::UnPlus); }
     446        | '-'                                           { $$ = new OperatorNode(OperatorNode::UnMinus); }
     447        | '~'                                           { $$ = new OperatorNode(OperatorNode::BitNeg); }
    451448        ;
    452449
     
    454451        unary_expression
    455452        | '(' type_name_no_function ')' cast_expression
    456                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast),
    457                                                                        new TypeValueNode($2), $4); }
     453                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); }
    458454        | '(' type_name_no_function ')' tuple
    459                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast),
    460                                                                        new TypeValueNode($2), $4); }
     455                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); }
    461456        ;
    462457
     
    464459        cast_expression
    465460        | multiplicative_expression '*' cast_expression
    466                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mul),$1,$3); }
     461                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mul),$1,$3); }
    467462        | multiplicative_expression '/' cast_expression
    468                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Div),$1,$3); }
     463                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Div),$1,$3); }
    469464        | multiplicative_expression '%' cast_expression
    470                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mod),$1,$3); }
     465                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mod),$1,$3); }
    471466        ;
    472467
     
    474469        multiplicative_expression
    475470        | additive_expression '+' multiplicative_expression
    476                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Plus),$1,$3); }
     471                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Plus),$1,$3); }
    477472        | additive_expression '-' multiplicative_expression
    478                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Minus),$1,$3); }
     473                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Minus),$1,$3); }
    479474        ;
    480475
     
    482477        additive_expression
    483478        | shift_expression LS additive_expression
    484                                                 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LShift),$1,$3); }
     479                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LShift),$1,$3); }
    485480        | shift_expression RS additive_expression
    486481                                                { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::RShift),$1,$3); }
     
    558553        conditional_expression
    559554        | unary_expression '=' assignment_expression
    560                                                 { $$ =new CompositeExprNode(new OperatorNode(OperatorNode::Assign), $1, $3); }
     555                                                        { $$ =new CompositeExprNode(new OperatorNode(OperatorNode::Assign), $1, $3); }
    561556        | unary_expression assignment_operator assignment_expression
    562                                                 { $$ =new CompositeExprNode($2, $1, $3); }
     557                                                        { $$ =new CompositeExprNode($2, $1, $3); }
    563558        | tuple assignment_opt                          /* CFA, tuple expression */
    564559                {
     
    12091204                        typedefTable.enterScope();
    12101205                }
    1211           type_parameter_list ')'               /* CFA */
     1206          type_parameter_list ')'                       /* CFA */
    12121207                {
    12131208                        typedefTable.leaveScope();
     
    16301625
    16311626initializer_opt:
    1632         /* empty */                             { $$ = 0; }
    1633         | '=' initializer                       { $$ = $2; }
     1627        /* empty */                                     { $$ = 0; }
     1628        | '=' initializer                               { $$ = $2; }
    16341629        ;
    16351630
    16361631initializer:
    1637         assignment_expression                   { $$ = new InitializerNode($1); }
    1638         | '{' initializer_list comma_opt '}'    { $$ = new InitializerNode($2, true); }
     1632        assignment_expression                           { $$ = new InitializerNode($1); }
     1633        | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode($2, true); }
    16391634        ;
    16401635
    16411636initializer_list:
    16421637        initializer
    1643         | designation initializer                            { $$ = $2->set_designators( $1 ); }
    1644         | initializer_list ',' initializer                   { $$ = (InitializerNode *)( $1->set_link($3) ); }
     1638        | designation initializer                       { $$ = $2->set_designators( $1 ); }
     1639        | initializer_list ',' initializer              { $$ = (InitializerNode *)( $1->set_link($3) ); }
    16451640        | initializer_list ',' designation initializer
    1646                                            { $$ = (InitializerNode *)( $1->set_link( $4->set_designators($3) ) ); }
     1641                                                        { $$ = (InitializerNode *)( $1->set_link( $4->set_designators($3) ) ); }
    16471642        ;
    16481643
     
    16591654designation:
    16601655        designator_list ':'                             /* ANSI99, CFA uses ":" instead of "=" */
    1661         | no_attr_identifier_or_typedef_name ':'                /* GCC, field name */
    1662                                                        { $$ = new VarRefNode( $1 ); }
     1656        | no_attr_identifier_or_typedef_name ':'        /* GCC, field name */
     1657                                                        { $$ = new VarRefNode( $1 ); }
    16631658        ;
    16641659
    16651660designator_list:                                        /* ANSI99 */
    16661661        designator
    1667         | designator_list designator                   { $$ = (ExpressionNode *)($1->set_link( $2 )); }
     1662        | designator_list designator                    { $$ = (ExpressionNode *)($1->set_link( $2 )); }
    16681663        ;
    16691664
    16701665designator:
    16711666        '.' no_attr_identifier_or_typedef_name          /* ANSI99, field name */
    1672                                                        { $$ = new VarRefNode( $2 ); }
     1667                                                        { $$ = new VarRefNode( $2 ); }
    16731668        | '[' push assignment_expression pop ']'        /* ANSI99, single array element */
    16741669                /* assignment_expression used instead of constant_expression because of shift/reduce conflicts
    16751670                   with tuple. */
    1676                                                        { $$ = $3; }
     1671                                                        { $$ = $3; }
    16771672        | '[' push subrange pop ']'                     /* CFA, multiple array elements */
    1678                                                        { $$ = $3; }
     1673                                                        { $$ = $3; }
    16791674        | '[' push constant_expression ELLIPSIS constant_expression pop ']' /* GCC, multiple array elements */
    1680                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range), $3, $5); }
     1675                                                        { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range), $3, $5); }
    16811676        | '.' '[' push field_list pop ']'               /* CFA, tuple field selector */
    1682                                                        { $$ = $4; }
     1677                                                        { $$ = $4; }
    16831678        ;
    16841679
     
    24922487        ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall
    24932488        appear only in a declaration of a function parameter with an array type, and then only in the
    2494         outermost array type derivation."
    2495    */
     2489        outermost array type derivation." */
    24962490
    24972491array_parameter_1st_dimension:
    24982492        '[' push pop ']'
    24992493                { $$ = DeclarationNode::newArray( 0, 0, false ); }
     2494        // multi_array_dimension handles the '[' '*' ']' case
    25002495        | '[' push type_qualifier_list '*' pop ']'      /* remaining ANSI99 */
    25012496                { $$ = DeclarationNode::newVarArray( $3 ); }
     2497        | '[' push type_qualifier_list pop ']'
     2498                { $$ = DeclarationNode::newArray( 0, $3, false ); }
     2499        // multi_array_dimension handles the '[' assignment_expression ']' case
    25022500        | '[' push type_qualifier_list assignment_expression pop ']'
    25032501                { $$ = DeclarationNode::newArray( $4, $3, false ); }
    2504         | '[' push STATIC assignment_expression pop ']'
    2505                 { $$ = DeclarationNode::newArray( $4, 0, true ); }
    2506         | '[' push STATIC type_qualifier_list assignment_expression pop ']'
     2502        | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
    25072503                { $$ = DeclarationNode::newArray( $5, $4, true ); }
     2504        | '[' push type_qualifier_list STATIC assignment_expression pop ']'
     2505                { $$ = DeclarationNode::newArray( $5, $3, true ); }
    25082506        ;
    25092507
Note: See TracChangeset for help on using the changeset viewer.