Changeset 98538288


Ignore:
Timestamp:
Feb 11, 2020, 2:59:04 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
cb8a18c
Parents:
686cb63
Message:

Moved VerifyCtorDtorAssign? up and changed return type check to support the change.
fixes #158?

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/OperatorTable.cc

    r686cb63 r98538288  
    2424        namespace {
    2525                const OperatorInfo tableValues[] = {
    26                         {       "?[?]",         "",             "_operator_index",                              OT_INDEX                        },
    27                         {       "?{}",          "=",    "_constructor",                                 OT_CTOR                         },
    28                         {       "^?{}",         "",             "_destructor",                                  OT_DTOR                         },
    29                         {       "?()",          "",             "_operator_call",                               OT_CALL                         },
    30                         {       "?++",          "++",   "_operator_postincr",                   OT_POSTFIXASSIGN        },
    31                         {       "?--",          "--",   "_operator_postdecr",                   OT_POSTFIXASSIGN        },
    32                         {       "*?",           "*",    "_operator_deref",                              OT_PREFIX                       },
    33                         {       "+?",           "+",    "_operator_unaryplus",                  OT_PREFIX                       },
    34                         {       "-?",           "-",    "_operator_unaryminus",                 OT_PREFIX                       },
    35                         {       "~?",           "~",    "_operator_bitnot",                             OT_PREFIX                       },
    36                         {       "!?",           "!",    "_operator_lognot",                             OT_PREFIX                       },
    37                         {       "++?",          "++",   "_operator_preincr",                    OT_PREFIXASSIGN         },
    38                         {       "--?",          "--",   "_operator_predecr",                    OT_PREFIXASSIGN         },
    39                         {       "?\\?",         "\\",   "_operator_exponential",                OT_INFIX                        },
    40                         {       "?*?",          "*",    "_operator_multiply",                   OT_INFIX                        },
    41                         {       "?/?",          "/",    "_operator_divide",                             OT_INFIX                        },
    42                         {       "?%?",          "%",    "_operator_modulus",                    OT_INFIX                        },
    43                         {       "?+?",          "+",    "_operator_add",                                OT_INFIX                        },
    44                         {       "?-?",          "-",    "_operator_subtract",                   OT_INFIX                        },
    45                         {       "?<<?",         "<<",   "_operator_shiftleft",                  OT_INFIX                        },
    46                         {       "?>>?",         ">>",   "_operator_shiftright",                 OT_INFIX                        },
    47                         {       "?<?",          "<",    "_operator_less",                               OT_INFIX                        },
    48                         {       "?>?",          ">",    "_operator_greater",                    OT_INFIX                        },
    49                         {       "?<=?",         "<=",   "_operator_lessequal",                  OT_INFIX                        },
    50                         {       "?>=?",         ">=",   "_operator_greaterequal",               OT_INFIX                        },
    51                         {       "?==?",         "==",   "_operator_equal",                              OT_INFIX                        },
    52                         {       "?!=?",         "!=",   "_operator_notequal",                   OT_INFIX                        },
    53                         {       "?&?",          "&",    "_operator_bitand",                             OT_INFIX                        },
    54                         {       "?^?",          "^",    "_operator_bitxor",                             OT_INFIX                        },
    55                         {       "?|?",          "|",    "_operator_bitor",                              OT_INFIX                        },
    56                         {       "?=?",          "=",    "_operator_assign",                             OT_INFIXASSIGN          },
    57                         {       "?\\=?",        "\\=",  "_operator_expassign",                  OT_INFIXASSIGN          },
    58                         {       "?*=?",         "*=",   "_operator_multassign",                 OT_INFIXASSIGN          },
    59                         {       "?/=?",         "/=",   "_operator_divassign",                  OT_INFIXASSIGN          },
    60                         {       "?%=?",         "%=",   "_operator_modassign",                  OT_INFIXASSIGN          },
    61                         {       "?+=?",         "+=",   "_operator_addassign",                  OT_INFIXASSIGN          },
    62                         {       "?-=?",         "-=",   "_operator_subassign",                  OT_INFIXASSIGN          },
    63                         {       "?<<=?",        "<<=",  "_operator_shiftleftassign",    OT_INFIXASSIGN          },
    64                         {       "?>>=?",        ">>=",  "_operator_shiftrightassign",   OT_INFIXASSIGN          },
    65                         {       "?&=?",         "&=",   "_operator_bitandassign",               OT_INFIXASSIGN          },
    66                         {       "?^=?",         "^=",   "_operator_bitxorassign",               OT_INFIXASSIGN          },
    67                         {       "?|=?",         "|=",   "_operator_bitorassign",                OT_INFIXASSIGN          },
     26                        {       "?[?]",   "",     "_operator_index",             "Index",                      OT_INDEX          },
     27                        {       "?{}",    "=",    "_constructor",                "Constructor",                OT_CTOR           },
     28                        {       "^?{}",   "",     "_destructor",                 "Destructor",                 OT_DTOR           },
     29                        {       "?()",    "",     "_operator_call",              "Call Operator",              OT_CALL           },
     30                        {       "?++",    "++",   "_operator_postincr",          "Postfix Increment",          OT_POSTFIXASSIGN  },
     31                        {       "?--",    "--",   "_operator_postdecr",          "Postfix Decrement",          OT_POSTFIXASSIGN  },
     32                        {       "*?",     "*",    "_operator_deref",             "Dereference",                OT_PREFIX         },
     33                        {       "+?",     "+",    "_operator_unaryplus",         "Plus",                       OT_PREFIX         },
     34                        {       "-?",     "-",    "_operator_unaryminus",        "Minus",                      OT_PREFIX         },
     35                        {       "~?",     "~",    "_operator_bitnot",            "Bitwise Not",                OT_PREFIX         },
     36                        {       "!?",     "!",    "_operator_lognot",            "Logical Not",                OT_PREFIX         },
     37                        {       "++?",    "++",   "_operator_preincr",           "Prefix Increment",           OT_PREFIXASSIGN   },
     38                        {       "--?",    "--",   "_operator_predecr",           "Prefix Decrement",           OT_PREFIXASSIGN   },
     39                        {       "?\\?",   "\\",   "_operator_exponential",       "Exponentiation",             OT_INFIX          },
     40                        {       "?*?",    "*",    "_operator_multiply",          "Multiplication",             OT_INFIX          },
     41                        {       "?/?",    "/",    "_operator_divide",            "Division",                   OT_INFIX          },
     42                        {       "?%?",    "%",    "_operator_modulus",           "Modulo",                     OT_INFIX          },
     43                        {       "?+?",    "+",    "_operator_add",               "Addition",                   OT_INFIX          },
     44                        {       "?-?",    "-",    "_operator_subtract",          "Substraction",               OT_INFIX          },
     45                        {       "?<<?",   "<<",   "_operator_shiftleft",         "Shift Left",                 OT_INFIX          },
     46                        {       "?>>?",   ">>",   "_operator_shiftright",        "Shift Right",                OT_INFIX          },
     47                        {       "?<?",    "<",    "_operator_less",              "Less-than",                  OT_INFIX          },
     48                        {       "?>?",    ">",    "_operator_greater",           "Greater-than",               OT_INFIX          },
     49                        {       "?<=?",   "<=",   "_operator_lessequal",         "Less-than-or-Equal",         OT_INFIX          },
     50                        {       "?>=?",   ">=",   "_operator_greaterequal",      "Greater-than-or-Equal",      OT_INFIX          },
     51                        {       "?==?",   "==",   "_operator_equal",             "Equality",                   OT_INFIX          },
     52                        {       "?!=?",   "!=",   "_operator_notequal",          "Not-Equal",                  OT_INFIX          },
     53                        {       "?&?",    "&",    "_operator_bitand",            "Bitwise And",                OT_INFIX          },
     54                        {       "?^?",    "^",    "_operator_bitxor",            "Bitwise Xor",                OT_INFIX          },
     55                        {       "?|?",    "|",    "_operator_bitor",             "Bitwise Or",                 OT_INFIX          },
     56                        {       "?=?",    "=",    "_operator_assign",            "Assignment",                 OT_INFIXASSIGN    },
     57                        {       "?\\=?",  "\\=",  "_operator_expassign",         "Exponentiation Assignment",  OT_INFIXASSIGN    },
     58                        {       "?*=?",   "*=",   "_operator_multassign",        "Multiplication Assignment",  OT_INFIXASSIGN    },
     59                        {       "?/=?",   "/=",   "_operator_divassign",         "Division Assignment",        OT_INFIXASSIGN    },
     60                        {       "?%=?",   "%=",   "_operator_modassign",         "Modulo Assignment",          OT_INFIXASSIGN    },
     61                        {       "?+=?",   "+=",   "_operator_addassign",         "Addition Assignment",        OT_INFIXASSIGN    },
     62                        {       "?-=?",   "-=",   "_operator_subassign",         "Substrction Assignment",     OT_INFIXASSIGN    },
     63                        {       "?<<=?",  "<<=",  "_operator_shiftleftassign",   "Shift Left Assignment",      OT_INFIXASSIGN    },
     64                        {       "?>>=?",  ">>=",  "_operator_shiftrightassign",  "Shift Right Assignment",     OT_INFIXASSIGN    },
     65                        {       "?&=?",   "&=",   "_operator_bitandassign",      "Bitwise And Assignment",     OT_INFIXASSIGN    },
     66                        {       "?^=?",   "^=",   "_operator_bitxorassign",      "Bitwise Xor Assignment",     OT_INFIXASSIGN    },
     67                        {       "?|=?",   "|=",   "_operator_bitorassign",       "Bitwise Or Assignment",      OT_INFIXASSIGN    },
    6868                };
    6969
     
    105105                OperatorInfo info;
    106106                return operatorLookup( funcName, info );
     107        }
     108
     109        std::string operatorFriendlyName( const std::string & funcName ) {
     110                OperatorInfo info;
     111                if( operatorLookup( funcName, info ) ) {
     112                        return info.friendlyName;
     113                }
     114                return "";
    107115        }
    108116
  • src/CodeGen/OperatorTable.h

    r686cb63 r98538288  
    3838                std::string symbol;
    3939                std::string outputName;
     40                std::string friendlyName;
    4041                OperatorType type;
    4142        };
     
    4344        bool isOperator( const std::string & funcName );
    4445        bool operatorLookup( const std::string & funcName, OperatorInfo & info );
     46        std::string operatorFriendlyName( const std::string & funcName );
    4547
    4648        bool isConstructor( const std::string & );
  • src/Common/SemanticError.h

    r686cb63 r98538288  
    4949struct WarningData {
    5050        const char * const name;
     51        const Severity default_severity;
    5152        const char * const message;
    52         const Severity default_severity;
    5353};
    5454
    5555constexpr WarningData WarningFormats[] = {
    56         {"self-assign"            , "self assignment of expression: %s"            , Severity::Warn},
    57         {"reference-conversion"   , "rvalue to reference conversion of rvalue: %s" , Severity::Warn},
    58         {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
    59         {"aggregate-forward-decl" , "forward declaration of nested aggregate: %s"  , Severity::Warn},
    60         {"superfluous-decl"       , "declaration does not allocate storage: %s"    , Severity::Warn},
    61         {"gcc-attributes"         , "invalid attribute: %s"                        , Severity::Warn},
     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        {"gcc-attributes"         , Severity::Warn    , "invalid attribute: %s"                                      },
     62        {"c++-like-copy"          , Severity::Warn    , "Constructor from reference is not a valid copy constructor" },
    6263};
    6364
     
    6970        SuperfluousDecl,
    7071        GccAttributes,
     72        CppCopy,
    7173        NUMBER_OF_WARNINGS, // This MUST be the last warning
    7274};
  • src/SymTab/Validate.cc

    r686cb63 r98538288  
    311311                        Stats::Heap::newPass("validate-A");
    312312                        Stats::Time::BlockGuard guard("validate-A");
     313                        VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    313314                        acceptAll( translationUnit, hoistDecls );
    314315                        ReplaceTypedef::replaceTypedef( translationUnit );
     
    336337                        Stats::Time::BlockGuard guard("validate-C");
    337338                        acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old
    338                         VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    339339                        ReturnChecker::checkFunctionReturns( translationUnit );
    340340                        InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
     
    11821182                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    11831183                        if ( params.size() == 0 ) {
    1184                                 SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
     1184                                SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." );
    11851185                        }
    11861186                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    11871187                        if ( ! refType ) {
    1188                                 SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
     1188                                SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." );
    11891189                        }
    11901190                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    1191                                 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
     1191                                if(!returnVals.front()->get_type()->isVoid()) {
     1192                                        SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." );
     1193                                }
    11921194                        }
    11931195                }
Note: See TracChangeset for help on using the changeset viewer.