Changeset 1f690b3 for src


Ignore:
Timestamp:
Oct 11, 2018, 2:48:06 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
90cfc16, 9507ce3
Parents:
2b3d6ff (diff), 7b61ce8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/ResolvProtoDump.cc

    r2b3d6ff r1f690b3  
    204204                /// ensures type inst names are uppercase
    205205                static void ti_name( const std::string& name, std::stringstream& ss ) {
     206                        // replace built-in wide character types with named types
     207                        if ( name == "char16_t" || name == "char32_t" || name == "wchar_t" ) {
     208                                ss << "#" << name;
     209                                return;
     210                        }
     211
     212                        // strip leading underscore
    206213                        unsigned i = 0;
    207214                        while ( i < name.size() && name[i] == '_' ) { ++i; }
     
    210217                                return;
    211218                        }
    212                         ss << (char)std::toupper( static_cast<unsigned char>(name[i]) )
    213                            << (name.c_str() + i + 1);
     219
     220                        std::string stripped = name.substr(i);
     221                        // strip trailing "_generic_" from autogen names (avoids some user-generation issues)
     222                        char generic[] = "_generic_"; size_t n_generic = sizeof(generic) - 1;
     223                        if ( stripped.size() >= n_generic
     224                                        && stripped.substr( stripped.size() - n_generic ) == generic ) {
     225                                stripped.resize( stripped.size() - n_generic );
     226                        }
     227
     228                        // uppercase first character
     229                        ss << (char)std::toupper( static_cast<unsigned char>(stripped[0]) )
     230                           << (stripped.c_str() + 1);
    214231                }
    215232
     
    304321                        }
    305322
    306                         // TODO support VarArgsType
     323                        // TODO support variable args for functions
     324                        void previsit( VarArgsType* ) {
     325                                // only include varargs for top level (argument type)
     326                                if ( depth == 0 ) { ss << "#$varargs"; }
     327                        }
    307328
    308329                        // replace 0 and 1 with int
     
    397418                        }
    398419
     420                        /// Handle already-resolved variables as type constants
     421                        void previsit( VariableExpr* expr ) {
     422                                PassVisitor<TypePrinter> tyPrinter{ closed, ss };
     423                                expr->var->get_type()->accept( tyPrinter );
     424                                visit_children = false;
     425                        }
     426
    399427                        /// Calls handled as calls
    400428                        void previsit( UntypedExpr* expr ) {
     
    426454                        }
    427455
    428                         /// Already-resolved calls skipped
    429                         void previsit( ApplicationExpr* ) {
     456                        /// Already-resolved calls reduced to their type constant
     457                        void previsit( ApplicationExpr* expr ) {
     458                                PassVisitor<TypePrinter> tyPrinter{ closed, ss };
     459                                expr->result->accept( tyPrinter );
    430460                                visit_children = false;
    431461                        }
     
    532562                                for ( Initializer* it : li->initializers ) {
    533563                                        build( it, ss );
    534                                         ss << ' ';
    535564                                }
    536565                        }
     
    539568                /// Adds an object initializer to the list of expressions
    540569                void build( const std::string& name, Initializer* init, std::stringstream& ss ) {
    541                         ss << "$constructor( ";
     570                        ss << "$constructor( &";
    542571                        rp_name( name, ss );
    543                         ss << "() ";
     572                        ss << ' ';
    544573                        build( init, ss );
    545574                        ss << ')';
     
    676705                }
    677706
     707                void previsit( AsmStmt* ) {
     708                        // skip asm statements
     709                        visit_children = false;
     710                }
     711
    678712                void previsit( Expression* expr ) {
    679713                        std::stringstream ss;
     
    686720                /// Print non-prelude global declarations for resolv proto
    687721                void printGlobals() const {
    688                         std::cout << "#ptr<T> $addr T" << std::endl;  // &?
     722                        std::cout << "#$ptr<T> $addr T" << std::endl;  // &?
    689723                        int i = (int)BasicType::SignedInt;
    690724                        std::cout << i << " $and " << i << ' ' << i << std::endl;  // ?&&?
  • src/SynTree/Constant.cc

    r2b3d6ff r1f690b3  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jul 14 14:50:00 2017
    13 // Update Count     : 29
     12// Last Modified On : Fri Spt 28 14:49:00 2018
     13// Update Count     : 30
    1414//
    1515
     
    1919
    2020#include "Constant.h"
     21#include "Expression.h" // for ConstantExpr
    2122#include "Type.h"    // for BasicType, Type, Type::Qualifiers, PointerType
    2223
     
    4849Constant Constant::from_double( double d ) {
    4950        return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d );
     51}
     52
     53Constant Constant::from_string( std::string const & str ) {
     54        return Constant(
     55                new ArrayType(
     56                        noQualifiers,
     57                        new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
     58                        new ConstantExpr( Constant::from_int( str.size() + 1 /* \0 */ )),
     59                        false, false ),
     60                std::string("\"") + str + "\"", (unsigned long long int)0 );
    5061}
    5162
  • src/SynTree/Constant.h

    r2b3d6ff r1f690b3  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:46 2017
    13 // Update Count     : 17
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Spt 28 14:48:00 2018
     13// Update Count     : 18
    1414//
    1515
     
    5151        /// generates a floating point constant of the given double
    5252        static Constant from_double( double d );
     53        /// generates an array of chars constant of the given string
     54        static Constant from_string( std::string const & s );
    5355
    5456        /// generates a null pointer value for the given type. void * if omitted.
Note: See TracChangeset for help on using the changeset viewer.