Changeset b1f2007 for src/Common


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

first attempt at simplifying SemanticError? and its usage

Location:
src/Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.