Changeset b1f2007 for src/Parser


Ignore:
Timestamp:
Dec 13, 2023, 9:17:13 AM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
4c2fe47
Parents:
c40157e
Message:

first attempt at simplifying SemanticError? and its usage

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    rc40157e rb1f2007  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Apr  3 17:55:00 2023
    13 // Update Count     : 942
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Dec  9 17:39:34 2023
     13// Update Count     : 945
    1414//
    1515
     
    3737class ExpressionNode;
    3838struct StatementNode;
     39
    3940
    4041//##############################################################################
     
    9798std::ostream & operator<<( std::ostream & out, const ParseNode * node );
    9899
     100__attribute__((noreturn)) static inline void SemanticError( const ParseNode * obj, const std::string & error ) {
     101        SemanticError( obj->location, toString( error, obj ) );
     102}
     103
    99104// Local Variables: //
    100105// tab-width: 4 //
  • src/Parser/TypeData.cc

    rc40157e rb1f2007  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:12:51 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr  4 13:39:00 2023
    13 // Update Count     : 680
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Nov 26 15:51:05 2023
     13// Update Count     : 681
    1414//
    1515
     
    864864
    865865static string genTSError( string msg, DeclarationNode::BasicType basictype ) {
    866         SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
     866        SemanticError( yylloc, "invalid type specifier \"%s\" for type \"%s\".", msg.c_str(), DeclarationNode::basicTypeNames[basictype] );
    867867} // genTSError
    868868
     
    15071507                } // for
    15081508                // declaration type still set => type not moved to a matching parameter so there is a missing parameter name
    1509                 if ( decl->type ) SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name );
     1509                if ( decl->type ) SemanticError( decl->location, "missing name in parameter list %s", decl->name->c_str() );
    15101510        } // for
    15111511
  • src/Parser/parser.yy

    rc40157e rb1f2007  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Oct  3 17:14:12 2023
    13 // Update Count     : 6396
     12// Last Modified On : Sun Nov 26 13:18:06 2023
     13// Update Count     : 6398
    1414//
    1515
     
    260260                } // if
    261261        } else {
    262                 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr;
     262                SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
    263263        } // if
    264264} // forCtrl
    265265
    266266static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
    267         SemanticError( yylloc, ::toString( "syntax error, adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
    268                                    "Possible cause is misspelled type name or missing generic parameter." ) );
     267        SemanticError( yylloc, "syntax error, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n"
     268                                   "Possible cause is misspelled type name or missing generic parameter.",
     269                                   identifier1.c_str(), identifier2.c_str(), kind );
    269270} // IdentifierBeforeIdentifier
    270271
    271272static void IdentifierBeforeType( string & identifier, const char * kind ) {
    272         SemanticError( yylloc, ::toString( "syntax error, identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
    273                                    "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
     273        SemanticError( yylloc, "syntax error, identifier \"%s\" cannot appear before a %s.\n"
     274                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter.",
     275                                   identifier.c_str(), kind );
    274276} // IdentifierBeforeType
    275277
     
    689691        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
    690692        | IDENTIFIER IDENTIFIER                                                         // invalid syntax rule
    691                 { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; }
     693                { IdentifierBeforeIdentifier( *$1.str, *$2.str, "expression" ); $$ = nullptr; }
    692694        | IDENTIFIER type_qualifier                                                     // invalid syntax rule
    693695                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
     
    11551157        | identifier_or_type_name ':' attribute_list_opt error // invalid syntax rule
    11561158                {
    1157                         SemanticError( yylloc, ::toString( "syntx error, label \"", *$1.str, "\" must be associated with a statement, "
    1158                                                                                            "where a declaration, case, or default is not a statement. "
    1159                                                                                            "Move the label or terminate with a semi-colon." ) );
     1159                        SemanticError( yylloc, "syntx error, label \"%s\" must be associated with a statement, "
     1160                                                   "where a declaration, case, or default is not a statement.\n"
     1161                                                   "Move the label or terminate with a semicolon.", $1.str->c_str() );
    11601162                        $$ = nullptr;
    11611163                }
     
    21012103        | sue_declaration_specifier invalid_types                       // invalid syntax rule
    21022104                {
    2103                         SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ",
    2104                                 $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ),
    2105                                 " declaration." ) );
     2105                        SemanticError( yylloc, "syntax error, expecting ';' at end of \"%s\" declaration.",
     2106                                                   $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ) );
    21062107                        $$ = nullptr;
    21072108                }
     
    21612162type_qualifier:
    21622163        type_qualifier_name
    2163         | attribute                                                                                     // trick handles most atrribute locations
     2164        | attribute                                                                                     // trick handles most attribute locations
    21642165        ;
    21652166
     
    25852586        | type_specifier field_declaring_list_opt '}'           // invalid syntax rule
    25862587                {
    2587                         SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) );
     2588                        SemanticError( yylloc, "syntax error, expecting ';' at end of previous declaration." );
    25882589                        $$ = nullptr;
    25892590                }
Note: See TracChangeset for help on using the changeset viewer.