Changeset 60a8062


Ignore:
Timestamp:
Feb 18, 2020, 8:48:49 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
6988dc6
Parents:
5ccee64
Message:

rewrite most of OperatorTable? and change caller modules to use new interface

Location:
src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:13:28 2019
    13 // Update Count     : 508
     12// Last Modified On : Sun Feb 16 08:32:48 2020
     13// Update Count     : 532
    1414//
    1515#include "CodeGenerator.h"
     
    3939        int CodeGenerator::tabsize = 4;
    4040
    41         // the kinds of statements that would ideally be followed by whitespace
     41        // The kinds of statements that would ideally be followed by whitespace.
    4242        bool wantSpacing( Statement * stmt) {
    4343                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
     
    7878        }
    7979
    80         /* Using updateLocation at the beginning of a node and endl
    81          * within a node should become the method of formating.
    82          */
     80        // Using updateLocation at the beginning of a node and endl within a node should become the method of formating.
    8381        void CodeGenerator::updateLocation( CodeLocation const & to ) {
    8482                // skip if linemarks shouldn't appear or if codelocation is unset
     
    9593                } else {
    9694                        output << "\n# " << to.first_line << " \"" << to.filename
    97                                << "\"\n" << indent;
     95                                   << "\"\n" << indent;
    9896                        currentLocation = to;
    9997                }
     
    131129
    132130        void CodeGenerator::genAttributes( list< Attribute * > & attributes ) {
    133           if ( attributes.empty() ) return;
     131                if ( attributes.empty() ) return;
    134132                output << "__attribute__ ((";
    135133                for ( list< Attribute * >::iterator attr( attributes.begin() );; ) {
     
    140138                                output << ")";
    141139                        } // if
    142                   if ( ++attr == attributes.end() ) break;
     140                        if ( ++attr == attributes.end() ) break;
    143141                        output << ",";                                                          // separator
    144142                } // for
     
    165163                previsit( (BaseSyntaxNode *)node );
    166164                GuardAction( [this, node](){
    167                         if ( options.printExprTypes && node->result ) {
    168                                 output << " /* " << genType( node->result, "", options ) << " */ ";
    169                         }
    170                 } );
     165                                if ( options.printExprTypes && node->result ) {
     166                                        output << " /* " << genType( node->result, "", options ) << " */ ";
     167                                }
     168                        } );
    171169        }
    172170
     
    399397                extension( applicationExpr );
    400398                if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
    401                         OperatorInfo opInfo;
    402                         if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
     399                        const OperatorInfo * opInfo;
     400                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && ( opInfo = operatorLookup( varExpr->get_var()->get_name() ) ) ) {
    403401                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    404                                 switch ( opInfo.type ) {
     402                                switch ( opInfo->type ) {
    405403                                  case OT_INDEX:
    406404                                        assert( applicationExpr->get_args().size() == 2 );
     
    423421                                                output << "(";
    424422                                                (*arg++)->accept( *visitor );
    425                                                 output << ") /* " << opInfo.inputName << " */";
     423                                                output << ") /* " << opInfo->inputName << " */";
    426424                                        } else if ( applicationExpr->get_args().size() == 2 ) {
    427425                                                // intrinsic two parameter constructors are essentially bitwise assignment
    428426                                                output << "(";
    429427                                                (*arg++)->accept( *visitor );
    430                                                 output << opInfo.symbol;
     428                                                output << opInfo->symbol;
    431429                                                (*arg)->accept( *visitor );
    432                                                 output << ") /* " << opInfo.inputName << " */";
     430                                                output << ") /* " << opInfo->inputName << " */";
    433431                                        } else {
    434432                                                // no constructors with 0 or more than 2 parameters
     
    441439                                        assert( applicationExpr->get_args().size() == 1 );
    442440                                        output << "(";
    443                                         output << opInfo.symbol;
     441                                        output << opInfo->symbol;
    444442                                        (*arg)->accept( *visitor );
    445443                                        output << ")";
     
    450448                                        assert( applicationExpr->get_args().size() == 1 );
    451449                                        (*arg)->accept( *visitor );
    452                                         output << opInfo.symbol;
     450                                        output << opInfo->symbol;
    453451                                        break;
    454452
     
    459457                                        output << "(";
    460458                                        (*arg++)->accept( *visitor );
    461                                         output << opInfo.symbol;
     459                                        output << opInfo->symbol;
    462460                                        (*arg)->accept( *visitor );
    463461                                        output << ")";
     
    486484                extension( untypedExpr );
    487485                if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) {
    488                         OperatorInfo opInfo;
    489                         if ( operatorLookup( nameExpr->name, opInfo ) ) {
     486                        const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     487                        if ( opInfo ) {
    490488                                std::list< Expression* >::iterator arg = untypedExpr->args.begin();
    491                                 switch ( opInfo.type ) {
     489                                switch ( opInfo->type ) {
    492490                                  case OT_INDEX:
    493491                                        assert( untypedExpr->args.size() == 2 );
     
    508506                                                output << "(";
    509507                                                (*arg++)->accept( *visitor );
    510                                                 output << ") /* " << opInfo.inputName << " */";
     508                                                output << ") /* " << opInfo->inputName << " */";
    511509                                        } else if ( untypedExpr->get_args().size() == 2 ) {
    512510                                                // intrinsic two parameter constructors are essentially bitwise assignment
    513511                                                output << "(";
    514512                                                (*arg++)->accept( *visitor );
    515                                                 output << opInfo.symbol;
     513                                                output << opInfo->symbol;
    516514                                                (*arg)->accept( *visitor );
    517                                                 output << ") /* " << opInfo.inputName << " */";
     515                                                output << ") /* " << opInfo->inputName << " */";
    518516                                        } else {
    519517                                                // no constructors with 0 or more than 2 parameters
     
    521519                                                output << "(";
    522520                                                (*arg++)->accept( *visitor );
    523                                                 output << opInfo.symbol << "{ ";
     521                                                output << opInfo->symbol << "{ ";
    524522                                                genCommaList( arg, untypedExpr->args.end() );
    525                                                 output << "}) /* " << opInfo.inputName << " */";
     523                                                output << "}) /* " << opInfo->inputName << " */";
    526524                                        } // if
    527525                                        break;
     
    532530                                        assert( untypedExpr->args.size() == 1 );
    533531                                        output << "(";
    534                                         output << opInfo.symbol;
     532                                        output << opInfo->symbol;
    535533                                        (*arg)->accept( *visitor );
    536534                                        output << ")";
     
    541539                                        assert( untypedExpr->args.size() == 1 );
    542540                                        (*arg)->accept( *visitor );
    543                                         output << opInfo.symbol;
     541                                        output << opInfo->symbol;
    544542                                        break;
    545543
     
    549547                                        output << "(";
    550548                                        (*arg++)->accept( *visitor );
    551                                         output << opInfo.symbol;
     549                                        output << opInfo->symbol;
    552550                                        (*arg)->accept( *visitor );
    553551                                        output << ")";
     
    581579        void CodeGenerator::postvisit( NameExpr * nameExpr ) {
    582580                extension( nameExpr );
    583                 OperatorInfo opInfo;
    584                 if ( operatorLookup( nameExpr->name, opInfo ) ) {
    585                         if ( opInfo.type == OT_CONSTANT ) {
    586                                 output << opInfo.symbol;
     581                const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     582                if ( opInfo ) {
     583                        if ( opInfo->type == OT_CONSTANT ) {
     584                                output << opInfo->symbol;
    587585                        } else {
    588                                 output << opInfo.outputName;
     586                                output << opInfo->outputName;
    589587                        }
    590588                } else {
     
    654652        void CodeGenerator::postvisit( VariableExpr * variableExpr ) {
    655653                extension( variableExpr );
    656                 OperatorInfo opInfo;
    657                 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
    658                         output << opInfo.symbol;
     654                const OperatorInfo * opInfo;
     655                if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && (opInfo = operatorLookup( variableExpr->get_var()->get_name() )) && opInfo->type == OT_CONSTANT ) {
     656                        output << opInfo->symbol;
    659657                } else {
    660658                        output << mangleName( variableExpr->get_var() );
     
    10111009                  case BranchStmt::FallThroughDefault:
    10121010                        assertf( ! options.genC, "fallthru should not reach code generation." );
    1013                   output << "fallthru";
     1011                        output << "fallthru";
    10141012                        break;
    10151013                } // switch
     
    10351033
    10361034                output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ?
    1037                            "throw" : "throwResume");
     1035                                   "throw" : "throwResume");
    10381036                if (throwStmt->get_expr()) {
    10391037                        output << " ";
     
    10501048
    10511049                output << ((stmt->get_kind() == CatchStmt::Terminate) ?
    1052                 "catch" : "catchResume");
     1050                                   "catch" : "catchResume");
    10531051                output << "( ";
    10541052                stmt->decl->accept( *visitor );
     
    11871185
    11881186        std::string genName( DeclarationWithType * decl ) {
    1189                 CodeGen::OperatorInfo opInfo;
    1190                 if ( operatorLookup( decl->get_name(), opInfo ) ) {
    1191                         return opInfo.outputName;
     1187                const OperatorInfo * opInfo = operatorLookup( decl->get_name() );
     1188                if ( opInfo ) {
     1189                        return opInfo->outputName;
    11921190                } else {
    11931191                        return decl->get_name();
  • src/CodeGen/CodeGenerator.h

    r5ccee64 r60a8062  
    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 : Tue Apr 30 12:01:00 2019
    13 // Update Count     : 57
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Feb 16 03:58:31 2020
     13// Update Count     : 62
    1414//
    1515
     
    2929namespace CodeGen {
    3030        struct CodeGenerator : public WithShortCircuiting, public WithGuards, public WithVisitorRef<CodeGenerator> {
    31           static int tabsize;
     31                static int tabsize;
    3232
    3333                CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false );
     
    104104                void postvisit( AsmStmt * );
    105105                void postvisit( DirectiveStmt * );
    106                 void postvisit( AsmDecl * );                            // special: statement in declaration context
     106                void postvisit( AsmDecl * );                                    // special: statement in declaration context
    107107                void postvisit( IfStmt * );
    108108                void postvisit( SwitchStmt * );
     
    147147                LabelPrinter printLabels;
    148148                Options options;
    149         public:
     149          public:
    150150                LineEnder endl;
    151         private:
     151          private:
    152152
    153153                CodeLocation currentLocation;
     
    162162        template< class Iterator >
    163163        void CodeGenerator::genCommaList( Iterator begin, Iterator end ) {
    164           if ( begin == end ) return;
     164                if ( begin == end ) return;
    165165                for ( ;; ) {
    166166                        (*begin++)->accept( *visitor );
    167                   if ( begin == end ) break;
     167                        if ( begin == end ) break;
    168168                        output << ", ";                                                         // separator
    169169                } // for
  • src/CodeGen/FixMain.h

    r5ccee64 r60a8062  
    1010// Created On       : Thr Jan 12 14:11:09 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:12:21 2019
    13 // Update Count     : 3
     12// Last Modified On : Sun Feb 16 03:24:32 2020
     13// Update Count     : 5
    1414//
    1515
     
    4242                static std::unique_ptr<FunctionDecl> main_signature;
    4343        };
    44 };
     44} // namespace CodeGen
  • src/CodeGen/GenType.h

    r5ccee64 r60a8062  
    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 : Tue Apr 30 11:47:00 2019
    13 // Update Count     : 3
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Feb 16 04:11:40 2020
     13// Update Count     : 5
    1414//
    1515
     
    2525        std::string genType( Type *type, const std::string &baseString, const Options &options );
    2626        std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false );
    27   std::string genPrettyType( Type * type, const std::string & baseString );
     27        std::string genPrettyType( Type * type, const std::string & baseString );
    2828} // namespace CodeGen
    2929
  • src/CodeGen/Generate.cc

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:38:56 2019
    13 // Update Count     : 8
     12// Last Modified On : Sun Feb 16 03:01:51 2020
     13// Update Count     : 9
    1414//
    1515#include "Generate.h"
     
    6464        void generate( BaseSyntaxNode * node, std::ostream & os ) {
    6565                if ( Type * type = dynamic_cast< Type * >( node ) ) {
    66                         os << CodeGen::genPrettyType( type, "" );
     66                        os << genPrettyType( type, "" );
    6767                } else {
    6868                        PassVisitor<CodeGenerator> cgv( os, true, false, false, false );
  • src/CodeGen/OperatorTable.cc

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb 10 18:12:12 2020
    13 // Update Count     : 17
     12// Last Modified On : Tue Feb 18 15:55:01 2020
     13// Update Count     : 55
    1414//
    1515
     
    1717#include <map>        // for map, _Rb_tree_const_iterator, map<>::const_iterator
    1818#include <utility>    // for pair
     19using namespace std;
    1920
    2021#include "OperatorTable.h"
     
    2223
    2324namespace CodeGen {
    24         namespace {
    25                 const OperatorInfo tableValues[] = {
    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    },
    68                 };
     25        const OperatorInfo CodeGen::tableValues[] = {
     26                // inputName symbol   outputName                     friendlyName                  type
     27                {       "?[?]",   "",     "_operator_index",             "Index",                      OT_INDEX          },
     28                {       "?{}",    "=",    "_constructor",                "Constructor",                OT_CTOR           },
     29                {       "^?{}",   "",     "_destructor",                 "Destructor",                 OT_DTOR           },
     30                {       "?()",    "",     "_operator_call",              "Call Operator",              OT_CALL           },
     31                {       "?++",    "++",   "_operator_postincr",          "Postfix Increment",          OT_POSTFIXASSIGN  },
     32                {       "?--",    "--",   "_operator_postdecr",          "Postfix Decrement",          OT_POSTFIXASSIGN  },
     33                {       "*?",     "*",    "_operator_deref",             "Dereference",                OT_PREFIX         },
     34                {       "+?",     "+",    "_operator_unaryplus",         "Plus",                       OT_PREFIX         },
     35                {       "-?",     "-",    "_operator_unaryminus",        "Minus",                      OT_PREFIX         },
     36                {       "~?",     "~",    "_operator_bitnot",            "Bitwise Not",                OT_PREFIX         },
     37                {       "!?",     "!",    "_operator_lognot",            "Logical Not",                OT_PREFIX         },
     38                {       "++?",    "++",   "_operator_preincr",           "Prefix Increment",           OT_PREFIXASSIGN   },
     39                {       "--?",    "--",   "_operator_predecr",           "Prefix Decrement",           OT_PREFIXASSIGN   },
     40                {       "?\\?",   "\\",   "_operator_exponential",       "Exponentiation",             OT_INFIX          },
     41                {       "?*?",    "*",    "_operator_multiply",          "Multiplication",             OT_INFIX          },
     42                {       "?/?",    "/",    "_operator_divide",            "Division",                   OT_INFIX          },
     43                {       "?%?",    "%",    "_operator_modulus",           "Modulo",                     OT_INFIX          },
     44                {       "?+?",    "+",    "_operator_add",               "Addition",                   OT_INFIX          },
     45                {       "?-?",    "-",    "_operator_subtract",          "Substraction",               OT_INFIX          },
     46                {       "?<<?",   "<<",   "_operator_shiftleft",         "Shift Left",                 OT_INFIX          },
     47                {       "?>>?",   ">>",   "_operator_shiftright",        "Shift Right",                OT_INFIX          },
     48                {       "?<?",    "<",    "_operator_less",              "Less-than",                  OT_INFIX          },
     49                {       "?>?",    ">",    "_operator_greater",           "Greater-than",               OT_INFIX          },
     50                {       "?<=?",   "<=",   "_operator_lessequal",         "Less-than-or-Equal",         OT_INFIX          },
     51                {       "?>=?",   ">=",   "_operator_greaterequal",      "Greater-than-or-Equal",      OT_INFIX          },
     52                {       "?==?",   "==",   "_operator_equal",             "Equality",                   OT_INFIX          },
     53                {       "?!=?",   "!=",   "_operator_notequal",          "Not-Equal",                  OT_INFIX          },
     54                {       "?&?",    "&",    "_operator_bitand",            "Bitwise And",                OT_INFIX          },
     55                {       "?^?",    "^",    "_operator_bitxor",            "Bitwise Xor",                OT_INFIX          },
     56                {       "?|?",    "|",    "_operator_bitor",             "Bitwise Or",                 OT_INFIX          },
     57                {       "?=?",    "=",    "_operator_assign",            "Assignment",                 OT_INFIXASSIGN    },
     58                {       "?\\=?",  "\\=",  "_operator_expassign",         "Exponentiation Assignment",  OT_INFIXASSIGN    },
     59                {       "?*=?",   "*=",   "_operator_multassign",        "Multiplication Assignment",  OT_INFIXASSIGN    },
     60                {       "?/=?",   "/=",   "_operator_divassign",         "Division Assignment",        OT_INFIXASSIGN    },
     61                {       "?%=?",   "%=",   "_operator_modassign",         "Modulo Assignment",          OT_INFIXASSIGN    },
     62                {       "?+=?",   "+=",   "_operator_addassign",         "Addition Assignment",        OT_INFIXASSIGN    },
     63                {       "?-=?",   "-=",   "_operator_subassign",         "Substrction Assignment",     OT_INFIXASSIGN    },
     64                {       "?<<=?",  "<<=",  "_operator_shiftleftassign",   "Shift Left Assignment",      OT_INFIXASSIGN    },
     65                {       "?>>=?",  ">>=",  "_operator_shiftrightassign",  "Shift Right Assignment",     OT_INFIXASSIGN    },
     66                {       "?&=?",   "&=",   "_operator_bitandassign",      "Bitwise And Assignment",     OT_INFIXASSIGN    },
     67                {       "?^=?",   "^=",   "_operator_bitxorassign",      "Bitwise Xor Assignment",     OT_INFIXASSIGN    },
     68                {       "?|=?",   "|=",   "_operator_bitorassign",       "Bitwise Or Assignment",      OT_INFIXASSIGN    },
     69        }; // tableValues
    6970
    70                 const int numOps = sizeof( tableValues ) / sizeof( OperatorInfo );
     71        std::map< std::string, OperatorInfo > CodeGen::table;
    7172
    72                 std::map< std::string, OperatorInfo > table;
    73 
    74                 void initialize() {
    75                         for ( int i = 0; i < numOps; ++i ) {
    76                                 table[ tableValues[i].inputName ] = tableValues[i];
    77                         } // for
    78                 }
    79         } // namespace
    80 
    81         bool operatorLookup( const std::string & funcName, OperatorInfo & info ) {
    82                 static bool init = false;
    83                 if ( ! init ) {
    84                         initialize();
    85                 } // if
    86 
    87                 std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName );
    88                 if ( i == table.end() ) {
    89                         if ( isPrefix( funcName, "?`" ) ) {                     // user-defined postfix operator ?
    90                                 info.inputName = funcName;
    91                                 info.symbol = funcName.substr(2);
    92                                 info.outputName = toString( "__postfix_call_", info.symbol );
    93                                 info.type = OT_POSTFIX;
    94                                 return true;
    95                         }
    96                         return false;
    97                 } else {
    98                         info = i->second;
    99                         return true;
    100                 } // if
     73        CodeGen::CodeGen() {
     74                enum { numOps = sizeof( tableValues ) / sizeof( OperatorInfo ) };
     75                for ( int i = 0; i < numOps; i += 1 ) {
     76                        table[ tableValues[i].inputName ] = tableValues[i];
     77                } // for
    10178        }
    10279
    103         bool isOperator( const std::string & funcName ) {
    104                 OperatorInfo info;
    105                 return operatorLookup( funcName, info );
     80        const OperatorInfo * operatorLookup( const string & funcName ) {
     81                if ( funcName.find_first_of( "?^*+-!", 0, 1 ) == string::npos ) return nullptr; // prefilter
     82                const OperatorInfo * ret = &CodeGen::table.find( funcName )->second; // must be in the table
     83                assert( ret );
     84                return ret;
    10685        }
    10786
    108         std::string operatorFriendlyName( const std::string & funcName ) {
    109                 OperatorInfo info;
    110                 if( operatorLookup( funcName, info ) ) {
    111                         return info.friendlyName;
    112                 }
     87        bool isOperator( const string & funcName ) {
     88                return operatorLookup( funcName ) != nullptr;
     89        }
     90
     91        string operatorFriendlyName( const string & funcName ) {
     92                const OperatorInfo * info = operatorLookup( funcName );
     93                if ( info ) return info->friendlyName;
    11394                return "";
    11495        }
    11596
    116         /// determines if a given function name is one of the operator types between [begin, end)
    117         template<typename Iterator>
    118         bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) {
    119                 OperatorInfo info;
    120                 if ( operatorLookup( funcName, info ) ) {
    121                         return std::find( begin, end, info.type ) != end;
    122                 }
     97        bool isConstructor( const string & funcName ) {
     98                const OperatorInfo * info = operatorLookup( funcName );
     99                if ( info ) return info->type == OT_CTOR;
    123100                return false;
    124101        }
    125102
    126         bool isConstructor( const std::string & funcName ) {
    127                 static OperatorType types[] = { OT_CTOR };
    128                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     103        bool isDestructor( const string & funcName ) {
     104                const OperatorInfo * info = operatorLookup( funcName );
     105                if ( info ) return info->type == OT_DTOR;
     106                return false;
    129107        }
    130108
    131         bool isDestructor( const std::string & funcName ) {
    132                 static OperatorType types[] = { OT_DTOR };
    133                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     109        bool isCtorDtor( const string & funcName ) {
     110                const OperatorInfo * info = operatorLookup( funcName );
     111                if ( info ) return info->type <= OT_CONSTRUCTOR;
     112                return false;
    134113        }
    135114
    136         bool isAssignment( const std::string & funcName ) {
    137                 static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN };
    138                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     115        bool isAssignment( const string & funcName ) {
     116                const OperatorInfo * info = operatorLookup( funcName );
     117                if ( info ) return info->type > OT_CONSTRUCTOR && info->type <= OT_ASSIGNMENT;
     118                return false;
    139119        }
    140120
    141         bool isCtorDtor( const std::string & funcName ) {
    142                 static OperatorType types[] = { OT_CTOR, OT_DTOR };
    143                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     121        bool isCtorDtorAssign( const string & funcName ) {
     122                const OperatorInfo * info = operatorLookup( funcName );
     123                if ( info ) return info->type <= OT_ASSIGNMENT;
     124                return false;
    144125        }
    145126
    146         bool isCtorDtorAssign( const std::string & funcName ) {
    147                 static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN };
    148                 return isOperatorType( funcName, std::begin(types), std::end(types) );
    149         }
     127        CodeGen codegen;                                                                        // initialize singleton package
    150128} // namespace CodeGen
    151129
    152130// Local Variables: //
    153131// tab-width: 4 //
    154 // mode: c++ //
    155 // compile-command: "make install" //
    156132// End: //
  • src/CodeGen/OperatorTable.h

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:17:11 2017
    13 // Update Count     : 6
     12// Last Modified On : Sun Feb 16 08:13:34 2020
     13// Update Count     : 26
    1414//
    1515
     
    1717
    1818#include <string>
     19#include <map>
    1920
    2021namespace CodeGen {
    2122        enum OperatorType {
    22                 OT_INDEX,
    2323                OT_CTOR,
    2424                OT_DTOR,
    25                 OT_CALL,
    26                 OT_PREFIX,
    27                 OT_POSTFIX,
    28                 OT_INFIX,
     25                OT_CONSTRUCTOR = OT_DTOR,
    2926                OT_PREFIXASSIGN,
    3027                OT_POSTFIXASSIGN,
    3128                OT_INFIXASSIGN,
     29                OT_ASSIGNMENT = OT_INFIXASSIGN,
     30                OT_CALL,
     31                OT_PREFIX,
     32                OT_INFIX,
     33                OT_POSTFIX,
     34                OT_INDEX,
    3235                OT_LABELADDRESS,
    3336                OT_CONSTANT
     
    4245        };
    4346
     47        class CodeGen {
     48                friend const OperatorInfo * operatorLookup( const std::string & funcName );
     49
     50                static const OperatorInfo tableValues[];
     51                static std::map< std::string, OperatorInfo > table;
     52          public:
     53                CodeGen();
     54        }; // CodeGen
     55
    4456        bool isOperator( const std::string & funcName );
    45         bool operatorLookup( const std::string & funcName, OperatorInfo & info );
     57        const OperatorInfo * operatorLookup( const std::string & funcName );
    4658        std::string operatorFriendlyName( const std::string & funcName );
    4759
  • src/CodeGen/Options.h

    r5ccee64 r60a8062  
    99// Author           : Andrew Beach
    1010// Created On       : Tue Apr 30 11:36:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May  2 10:45:00 2019
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Feb 15 18:37:06 2020
     13// Update Count     : 3
    1414//
    1515
    1616#pragma once
    1717
    18 namespace CodeGen {
    19         struct Options {
    20                 // External Options: Same thoughout a pass.
    21                 bool pretty;
    22                 bool genC;
    23                 bool lineMarks;
    24                 bool printExprTypes;
     18struct Options {
     19        // External Options: Same thoughout a pass.
     20        bool pretty;
     21        bool genC;
     22        bool lineMarks;
     23        bool printExprTypes;
    2524
    26                 // Internal Options: Changed on some recurisive calls.
    27                 bool anonymousUnused = false;
     25        // Internal Options: Changed on some recurisive calls.
     26        bool anonymousUnused = false;
    2827
    29                 Options(bool pretty, bool genC, bool lineMarks, bool printExprTypes) :
    30                         pretty(pretty), genC(genC), lineMarks(lineMarks), printExprTypes(printExprTypes)
     28        Options(bool pretty, bool genC, bool lineMarks, bool printExprTypes) :
     29                pretty(pretty), genC(genC), lineMarks(lineMarks), printExprTypes(printExprTypes)
    3130                {}
    32         };
    33 } // namespace CodeGen
     31};
    3432
    3533// Local Variables: //
  • src/CodeTools/ResolvProtoDump.cc

    r5ccee64 r60a8062  
    99// Author           : Aaron Moss
    1010// Created On       : Tue Sep 11 09:04:00 2018
    11 // Last Modified By : Aaron Moss
    12 // Last Modified On : Tue Sep 11 09:04:00 2018
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Feb 15 13:50:11 2020
     13// Update Count     : 3
    1414//
    1515
     
    182182
    183183                        // replace operator names
    184                         CodeGen::OperatorInfo info;
    185                         if ( CodeGen::operatorLookup( name, info ) ) {
     184                        const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( name );
     185                        if ( opInfo ) {
    186186                                ss << new_prefix(pre, "");
    187                                 op_name( info.outputName, ss );
     187                                op_name( opInfo->outputName, ss );
    188188                                return;
    189189                        }
  • src/ControlStruct/Mutate.cc

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:39:08 2016
    13 // Update Count     : 9
     12// Last Modified On : Sun Feb 16 03:22:07 2020
     13// Update Count     : 10
    1414//
    1515
     
    3737                mutateAll( translationUnit, formut );
    3838        }
    39 } // namespace CodeGen
     39} // namespace ControlStruct
    4040
    4141// Local Variables: //
  • src/InitTweak/FixInit.cc

    r5ccee64 r60a8062  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:41:27 2019
    13 // Update Count     : 77
     12// Last Modified On : Sun Feb 16 04:17:07 2020
     13// Update Count     : 82
    1414//
    1515#include "FixInit.h"
     
    745745                }
    746746
    747                 // to prevent warnings (‘_unq0’ may be used uninitialized in this function),
     747                // to prevent warnings ('_unq0' may be used uninitialized in this function),
    748748                // insert an appropriate zero initializer for UniqueExpr temporaries.
    749749                Initializer * makeInit( Type * t ) {
  • src/InitTweak/FixInit.h

    r5ccee64 r60a8062  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:31:06 2017
    13 // Update Count     : 6
     12// Last Modified On : Sun Feb 16 07:54:50 2020
     13// Update Count     : 8
    1414//
    1515
     
    2222
    2323namespace InitTweak {
    24   /// replace constructor initializers with expression statements
    25   /// and unwrap basic C-style initializers
     24        /// replace constructor initializers with expression statements and unwrap basic C-style initializers
    2625        void fix( std::list< Declaration * > & translationUnit, bool inLibrary );
    2726} // namespace
  • src/MakeLibCfa.cc

    r5ccee64 r60a8062  
    1010// Created On       : Sat May 16 10:33:33 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:41:40 2019
    13 // Update Count     : 42
     12// Last Modified On : Sun Feb 16 03:49:49 2020
     13// Update Count     : 45
    1414//
    1515
     
    9696
    9797                        FunctionDecl *funcDecl = origFuncDecl->clone();
    98                         CodeGen::OperatorInfo opInfo;
    99                         bool lookResult = CodeGen::operatorLookup( funcDecl->get_name(), opInfo );
    100                         assert( lookResult );
     98                        const CodeGen::OperatorInfo * opInfo;
     99                        opInfo = CodeGen::operatorLookup( funcDecl->get_name() );
     100                        assert( opInfo );
    101101                        assert( ! funcDecl->get_statements() );
    102102                        // build a recursive call - this is okay, as the call will actually be codegen'd using operator syntax
     
    120120
    121121                        Statement * stmt = nullptr;
    122                         switch ( opInfo.type ) {
     122                        switch ( opInfo->type ) {
    123123                          case CodeGen::OT_INDEX:
    124124                          case CodeGen::OT_CALL:
  • src/Parser/ParserTypes.h

    r5ccee64 r60a8062  
    1010// Created On       : Sat Sep 22 08:58:10 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:33:28 2017
    13 // Update Count     : 350
     12// Last Modified On : Sat Feb 15 11:04:40 2020
     13// Update Count     : 351
    1414//
    1515
     
    2727// current location in the input
    2828extern int yylineno;
    29 extern char *yyfilename;
     29extern char * yyfilename;
    3030
    3131struct Location {
    32     char *file;
     32    char * file;
    3333    int line;
    3434}; // Location
    3535
    3636struct Token {
    37     std::string *str;                                                                   // must be pointer as used in union
     37    std::string * str;                                                                  // must be pointer as used in union
    3838    Location loc;
    3939
  • src/Parser/TypedefTable.cc

    r5ccee64 r60a8062  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 25 15:32:35 2018
    13 // Update Count     : 258
     12// Last Modified On : Sat Feb 15 08:06:36 2020
     13// Update Count     : 259
    1414//
    1515
     
    4747} // TypedefTable::~TypedefTable
    4848
    49 bool TypedefTable::exists( const string & identifier ) {
     49bool TypedefTable::exists( const string & identifier ) const {
    5050        return kindTable.find( identifier ) != kindTable.end();
    5151} // TypedefTable::exists
    5252
    53 bool TypedefTable::existsCurr( const string & identifier ) {
     53bool TypedefTable::existsCurr( const string & identifier ) const {
    5454        return kindTable.findAt( kindTable.currentScope() - 1, identifier ) != kindTable.end();
    5555} // TypedefTable::exists
  • src/Parser/TypedefTable.h

    r5ccee64 r60a8062  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 25 15:33:55 2018
    13 // Update Count     : 114
     12// Last Modified On : Sat Feb 15 08:06:37 2020
     13// Update Count     : 117
    1414//
    1515
     
    3030        ~TypedefTable();
    3131
    32         bool exists( const std::string & identifier );
    33         bool existsCurr( const std::string & identifier );
     32        bool exists( const std::string & identifier ) const;
     33        bool existsCurr( const std::string & identifier ) const;
    3434        int isKind( const std::string & identifier ) const;
    3535        void makeTypedef( const std::string & name, int kind = TYPEDEFname );
  • src/Parser/lex.ll

    r5ccee64 r60a8062  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Fri Feb  7 19:02:43 2020
    13  * Update Count     : 725
     12 * Last Modified On : Sat Feb 15 11:05:50 2020
     13 * Update Count     : 737
    1414 */
    1515
     
    4242#include "ParseNode.h"
    4343#include "TypedefTable.h"
     44
     45string * build_postfix_name( string * name );
    4446
    4547char *yyfilename;
     
    432434"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    433435"^?{}"                  { IDENTIFIER_RETURN(); }
    434 "?`"{identifier} { IDENTIFIER_RETURN(); }                               // postfix operator
     436"?`"{identifier} {                                                                              // postfix operator
     437        yylval.tok.str = new string( &yytext[2] );                      // remove ?`
     438        yylval.tok.str = build_postfix_name( yylval.tok.str ); // add prefix
     439        RETURN_LOCN( typedefTable.isKind( *yylval.tok.str ) );
     440}
    435441"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    436442        /*
  • src/Parser/parser.yy

    r5ccee64 r60a8062  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb  1 10:04:40 2020
    13 // Update Count     : 4440
     12// Last Modified On : Sun Feb 16 08:22:14 2020
     13// Update Count     : 4461
    1414//
    1515
     
    166166} // rebindForall
    167167
    168 NameExpr * build_postfix_name( const string * name ) {
    169         NameExpr * new_name = build_varref( new string( "?`" + *name ) );
    170         delete name;
    171         return new_name;
     168string * build_postfix_name( string * name ) {
     169        *name = string("__postfix_func_") + *name;
     170        return name;
    172171} // build_postfix_name
    173172
     
    633632                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    634633        | postfix_expression '`' identifier                                     // CFA, postfix call
    635                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
     634                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
    636635        | constant '`' identifier                                                       // CFA, postfix call
    637                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
     636                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
    638637        | string_literal '`' identifier                                         // CFA, postfix call
    639                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }
     638                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
    640639        | postfix_expression '.' identifier
    641640                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
  • src/SymTab/Mangler.cc

    r5ccee64 r60a8062  
    1010// Created On       : Sun May 17 21:40:29 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:43:49 2019
    13 // Update Count     : 28
     12// Last Modified On : Sat Feb 15 13:55:12 2020
     13// Update Count     : 33
    1414//
    1515#include "Mangler.h"
     
    128128                                } // if
    129129                                mangleName << Encoding::manglePrefix;
    130                                 CodeGen::OperatorInfo opInfo;
    131                                 if ( operatorLookup( declaration->get_name(), opInfo ) ) {
    132                                         mangleName << opInfo.outputName.size() << opInfo.outputName;
     130                                const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( declaration->get_name() );
     131                                if ( opInfo ) {
     132                                        mangleName << opInfo->outputName.size() << opInfo->outputName;
    133133                                } else {
    134134                                        mangleName << declaration->name.size() << declaration->name;
     
    471471                        } // if
    472472                        mangleName << Encoding::manglePrefix;
    473                         CodeGen::OperatorInfo opInfo;
    474                         if ( operatorLookup( decl->name, opInfo ) ) {
    475                                 mangleName << opInfo.outputName.size() << opInfo.outputName;
     473                        const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( decl->name );
     474                        if ( opInfo ) {
     475                                mangleName << opInfo->outputName.size() << opInfo->outputName;
    476476                        } else {
    477477                                mangleName << decl->name.size() << decl->name;
  • src/SynTree/Attribute.h

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:14 2017
    13 // Update Count     : 39
     12// Last Modified On : Thu Feb 13 21:34:08 2020
     13// Update Count     : 40
    1414//
    1515
     
    3838        virtual ~Attribute();
    3939
    40         std::string get_name() const { return name; }
     40        const std::string & get_name() const { return name; }
    4141        void set_name( const std::string & newValue ) { name = newValue; }
    4242        std::list< Expression * > & get_parameters() { return parameters; }
Note: See TracChangeset for help on using the changeset viewer.