Changeset b1f2007


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

first attempt at simplifying SemanticError? and its usage

Location:
src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    rc40157e rb1f2007  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 15 17:00:00 2019
    11 // Last Modified By : Andrew Beach
     11// Last Modified By : Peter A. Buhr
    1212// Created On       : Wed May 18 13:56:00 2022
    13 // Update Count     : 8
     13// Update Count     : 12
    1414//
    1515
     
    168168                        return addrType( refType->base );
    169169                } else {
    170                         SemanticError( loc, arg->result.get(),
    171                                 "Attempt to take address of non-lvalue expression: " );
     170                        SemanticError( loc, "Attempt to take address of non-lvalue expression %s",
     171                                                   toString( arg->result.get() ).c_str() );
    172172                }
    173173        }
     
    240240                return 1;
    241241        }
    242         SemanticError( this, "Constant expression of non-integral type " );
     242        SemanticError( this->location, "Constant expression of non-integral type %s",
     243                                   toString( this ).c_str() );
    243244}
    244245
  • src/AST/LinkageSpec.cpp

    rc40157e rb1f2007  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 11 16:08:58 2023
     13// Update Count     : 2
    1414//
    1515
     
    3737                return spec;
    3838        } else {
    39                 SemanticError( loc, "Invalid linkage specifier " + *cmd );
     39                SemanticError( loc, "Invalid linkage specifier %s", cmd->c_str() );
    4040        }
    4141}
  • src/AST/TypeSubstitution.hpp

    rc40157e rb1f2007  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May 25 12:31:00 2023
    13 // Update Count     : 10
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 11 16:07:30 2023
     13// Update Count     : 15
    1414//
    1515
     
    156156                                } // if
    157157                        } else {
    158                                 SemanticError( formal, toString( "Attempt to provide non-type parameter: ", toString( *actualIt ).c_str(), " for type parameter " ) );
     158                                SemanticError( formal->location, "Attempt to provide non-type parameter %s for type parameter %s",
     159                                                           toString( *actualIt ).c_str(), formal->name.c_str() );
    159160                        } // if
    160161                } else {
  • src/Common/SemanticError.cc

    rc40157e rb1f2007  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 08:05:26 2018
    13 // Update Count     : 10
     12// Last Modified On : Mon Dec 11 15:59:09 2023
     13// Update Count     : 14
    1414//
    1515
     
    7070//-----------------------------------------------------------------------------
    7171// Semantic Error
     72
    7273bool SemanticErrorThrow = false;
    7374
     
    101102                std::cerr << ErrorHelpers::bold() << err.location << ErrorHelpers::error_str() << ErrorHelpers::reset_font() << err.description << std::endl;
    102103        }
     104}
     105
     106void SemanticError( CodeLocation location, const char * fmt, ... ) {
     107        char msg[2048];                                                                         // worst-case error-message buffer
     108        va_list args;
     109        va_start( args, fmt );
     110        vsnprintf( msg, sizeof(msg), fmt, args );                       // always null terminated, but may be truncated
     111        va_end( args );
     112
     113        SemanticErrorThrow = true;
     114        throw SemanticErrorException( location, msg );          // convert msg to string
    103115}
    104116
  • src/Common/SemanticError.h

    rc40157e rb1f2007  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 25 12:01:31 2023
    13 // Update Count     : 37
     12// Last Modified On : Mon Dec 11 21:54:22 2023
     13// Update Count     : 54
    1414//
    1515
     
    1818#include "ErrorObjects.h"
    1919#include "AST/Node.hpp"
     20#include "AST/ParseNode.hpp"
    2021#include <cstring>
    2122
     
    2526extern bool SemanticErrorThrow;
    2627
     28__attribute__((noreturn, format(printf, 2, 3))) void SemanticError( CodeLocation location, const char fmt[], ... );
     29
    2730__attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
    2831
    29 template< typename T >
    30 __attribute__((noreturn)) static inline void SemanticError( const T * obj, const std::string & error ) {
     32__attribute__((noreturn)) static inline void SemanticError( const ast::ParseNode * obj, const std::string & error ) {
    3133        SemanticError( obj->location, toString( error, obj ) );
    3234}
    3335
    34 template< typename T >
    35 __attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const T * obj, const std::string & error ) {
     36__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const ast::Node * obj, const std::string & error ) {
    3637        SemanticError( location, toString( error, obj ) );
    3738}
     
    5455
    5556constexpr WarningData WarningFormats[] = {
    56         {"self-assign"              , Severity::Warn    , "self assignment of expression: %s"                          },
    57         {"reference-conversion"     , Severity::Warn    , "rvalue to reference conversion of rvalue: %s"               },
    58         {"qualifiers-zero_t-one_t"  , Severity::Warn    , "questionable use of type qualifier(s) with %s"              },
    59         {"aggregate-forward-decl"   , Severity::Warn    , "forward declaration of nested aggregate: %s"                },
    60         {"superfluous-decl"         , Severity::Warn    , "declaration does not allocate storage: %s"                  },
    61         {"superfluous-else"         , Severity::Warn    , "else clause never executed for empty loop conditional"      },
    62         {"gcc-attributes"           , Severity::Warn    , "invalid attribute: %s"                                      },
    63         {"c++-like-copy"            , Severity::Warn    , "Constructor from reference is not a valid copy constructor" },
    64         {"depreciated-trait-syntax" , Severity::Warn    , "trait type-parameters are now specified using the forall clause" },
     57        {"self-assign"              , Severity::Warn, "self assignment of expression: %s"                          },
     58        {"reference-conversion"     , Severity::Warn, "rvalue to reference conversion of rvalue: %s"               },
     59        {"qualifiers-zero_t-one_t"  , Severity::Warn, "questionable use of type qualifier(s) with %s"              },
     60        {"aggregate-forward-decl"   , Severity::Warn, "forward declaration of nested aggregate: %s"                },
     61        {"superfluous-decl"         , Severity::Warn, "declaration does not allocate storage: %s"                  },
     62        {"superfluous-else"         , Severity::Warn, "else clause never executed for empty loop conditional"      },
     63        {"gcc-attributes"           , Severity::Warn, "invalid attribute: %s"                                      },
     64        {"c++-like-copy"            , Severity::Warn, "Constructor from reference is not a valid copy constructor" },
     65        {"depreciated-trait-syntax" , Severity::Warn, "trait type-parameters are now specified using the forall clause" },
    6566};
    6667
     
    7576        CppCopy,
    7677        DeprecTraitSyntax,
    77         NUMBER_OF_WARNINGS, // This MUST be the last warning
     78        NUMBER_OF_WARNINGS, // MUST be the last warning
    7879};
    7980
  • src/ControlStruct/FixLabels.cpp

    rc40157e rb1f2007  
    1010// Created On       : Mon Nov  1 09:39:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:19:17 2022
    13 // Update Count     : 9
     12// Last Modified On : Sun Nov 26 15:06:51 2023
     13// Update Count     : 10
    1414//
    1515
     
    4747        for ( auto kvp : labelTable ) {
    4848                if ( nullptr == kvp.second ) {
    49                         SemanticError( kvp.first.location,
    50                                                    "Use of undefined label: " + kvp.first.name );
     49                        SemanticError( kvp.first.location, "Use of undefined label %s.", kvp.first.name.c_str() );
    5150                }
    5251        }
  • src/ControlStruct/MultiLevelExit.cpp

    rc40157e rb1f2007  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Nov  1 13:48:00 2021
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Sep  8 17:04:00 2023
    13 // Update Count     : 36
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 11 13:44:45 2023
     13// Update Count     : 38
    1414//
    1515
     
    521521                assert(0);
    522522        }
    523         SemanticError( stmt->location, toString( "'return' may not appear in a ", context ) );
     523        SemanticError( stmt->location, "'return' may not appear in a %s", context );
    524524}
    525525
  • 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                }
  • src/ResolvExpr/CurrentObject.cc

    rc40157e rb1f2007  
    99// Author           : Rob Schluntz
    1010// Created On       : Tue Jun 13 15:28:32 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Apr 10  9:40:00 2023
    13 // Update Count     : 18
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Dec  9 17:49:51 2023
     13// Update Count     : 20
    1414//
    1515
     
    181181                auto res = eval( expr );
    182182                if ( !res.hasKnownValue ) {
    183                         SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) );
     183                        SemanticError( location, "Array designator must be a constant expression %s", toString( expr ).c_str() );
    184184                }
    185185                return res.knownValue;
  • src/Validate/FixQualifiedTypes.cpp

    rc40157e rb1f2007  
    99// Author           : Andrew Beach
    1010// Created On       : Thr Apr 21 11:13:00 2022
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Sep 20 16:15:00 2022
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 13 09:00:25 2023
     13// Update Count     : 6
    1414//
    1515
     
    4141                                auto td = symtab.globalLookupType( inst->name );
    4242                                if ( !td ) {
    43                                         SemanticError( *location, toString("Use of undefined global type ", inst->name) );
     43                                        SemanticError( *location, "Use of undefined global type %s.", inst->name.c_str() );
    4444                                }
    4545                                auto base = td->base;
     
    5050                        } else {
    5151                                // .T => T is not a type name.
    52                                 assertf( false, "unhandled global qualified child type: %s", toCString(child) );
     52                                assertf( false, "unhandled global qualified child type: %s", toCString( child ) );
    5353                        }
    5454                } else {
     
    6363                                instp = inst;
    6464                        } else {
    65                                 SemanticError( *location, toString("Qualified type requires an aggregate on the left, but has: ", parent) );
     65                                SemanticError( *location, "Qualified type requires an aggregate on the left, but has %s.", toCString( parent ) );
    6666                        }
    6767                        // TODO: Need to handle forward declarations.
     
    8181                                } else {
    8282                                        // S.T - S is not an aggregate => error.
    83                                         assertf( false, "unhandled qualified child type: %s", toCString(type) );
     83                                        assertf( false, "unhandled qualified child type %s.", toCString( type ) );
    8484                                }
    8585                        }
    8686                        // failed to find a satisfying definition of type
    87                         SemanticError( *location, toString("Undefined type in qualified type: ", type) );
     87                        SemanticError( *location, "Undefined type in qualified type %s", toCString( type ) );
    8888                }
    8989        }
  • src/Validate/ForallPointerDecay.cpp

    rc40157e rb1f2007  
    99// Author           : Andrew Beach
    1010// Created On       : Tue Dec  7 16:15:00 2021
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Sat Apr 23 13:10:00 2022
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Nov 26 18:49:57 2023
     13// Update Count     : 2
    1414//
    1515
     
    213213                auto type = obj->type->stripDeclarator();
    214214                if ( dynamic_cast< const ast::FunctionType * >( type ) ) return;
    215                 SemanticError( obj->location,
    216                         toCString( "operator ", obj->name.c_str(),
    217                         " is not a function or function pointer." ) );
     215                SemanticError( obj->location, "operator %s is not a function or function pointer.", obj->name.c_str() );
    218216        }
    219217};
  • src/Validate/ReplaceTypedef.cpp

    rc40157e rb1f2007  
    99// Author           : Andrew Beach
    1010// Created On       : Tue Jun 29 14:59:00 2022
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Sep 20 17:00:00 2022
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Nov 27 08:55:06 2023
     13// Update Count     : 3
    1414//
    1515
     
    111111                        if ( !rtt ) {
    112112                                assert( location );
    113                                 SemanticError( *location, "Cannot apply type parameters to base type of " + type->name );
     113                                SemanticError( *location, "Cannot apply type parameters to base type of %s.", type->name.c_str() );
    114114                        }
    115115                        rtt->params.clear();
     
    125125                if ( base == typedeclNames.end() ) {
    126126                        assert( location );
    127                         SemanticError( *location, toString( "Use of undefined type ", type->name ) );
     127                        SemanticError( *location, "Use of undefined type %s.", type->name.c_str() );
    128128                }
    129129                return ast::mutate_field( type, &ast::TypeInstType::base, base->second );
  • src/Virtual/ExpandCasts.cc

    rc40157e rb1f2007  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jul 24 13:59:00 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Aug 11 12:06:00 2022
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Nov 27 09:28:20 2023
     13// Update Count     : 10
    1414//
    1515
     
    160160
    161161        // Helper function for throwing semantic errors.
    162         auto throwError = [&fieldName, &errorLocation, &oldDecl](
    163                         std::string const & message ) {
    164                 std::string const & context = "While following head pointer of " +
    165                         oldDecl->name + " named '" + fieldName + "': ";
    166                 SemanticError( errorLocation, context + message );
     162        auto throwError = [&fieldName, &errorLocation, &oldDecl]( std::string const & message ) {
     163                SemanticError( errorLocation, "While following head pointer of %s named \"%s\": %s",
     164                                           oldDecl->name.c_str(), fieldName.c_str(), message.c_str() );
    167165        };
    168166
Note: See TracChangeset for help on using the changeset viewer.