Changeset e612146c


Ignore:
Timestamp:
Sep 3, 2017, 11:30:57 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
3f8dd01
Parents:
f43df73
Message:

third attempt at user-defined literals

Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rf43df73 re612146c  
    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 : Fri Aug 18 15:34:00 2017
    13 // Update Count     : 488
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 20:42:52 2017
     13// Update Count     : 490
    1414//
    1515#include "CodeGenerator.h"
     
    5959
    6060        void CodeGenerator::asmName( DeclarationWithType * decl ) {
    61                 if ( ConstantExpr * asmName = decl->get_asmName() ) {
     61                if ( ConstantExpr * asmName = dynamic_cast<ConstantExpr *>(decl->get_asmName()) ) {
    6262                        output << " asm ( " << asmName->get_constant()->get_value() << " )";
    6363                } // if
  • src/Parser/ExpressionNode.cc

    rf43df73 re612146c  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  1 22:57:24 2017
    13 // Update Count     : 625
     12// Last Modified On : Sun Sep  3 22:21:21 2017
     13// Update Count     : 639
    1414//
    1515
     
    218218} // build_constantChar
    219219
    220 ConstantExpr * build_constantStr( string & str ) {
     220Expression * build_constantStr( string & str ) {
    221221        string units;                                                                           // units
    222222        sepString( str, units, '"' );                                           // separate constant from units
    223223
    224         ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
     224        BasicType::Kind strtype = BasicType::Char;                      // default string type
     225        switch ( str[0] ) {                                                                     // str has >= 2 characters, i.e, null string ""
     226          case 'u':
     227                if ( str[1] == '8' ) break;                                             // utf-8 characters
     228                strtype = BasicType::ShortUnsignedInt;
     229                break;
     230          case 'U':
     231                strtype = BasicType::UnsignedInt;
     232                break;
     233          case 'L':
     234                strtype = BasicType::SignedInt;
     235                break;
     236        } // switch
     237        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ),
    225238                                                                        new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    226239                                                                        false, false );
    227         ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
    228 // ROB: type mismatch
    229         // if ( units.length() != 0 ) {
    230         //      ret = new UntypedExpr( new NameExpr( units ), { ret } );
    231         // } // if
     240        Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
     241        if ( units.length() != 0 ) {
     242                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     243        } // if
    232244
    233245        delete &str;                                                                            // created by lex
     
    410422} // build_range
    411423
    412 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) {
     424Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) {
    413425        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    414426} // build_asmexpr
  • src/Parser/ParseNode.h

    rf43df73 re612146c  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 31 17:42:49 2017
    13 // Update Count     : 797
     12// Last Modified On : Sun Sep  3 19:24:34 2017
     13// Update Count     : 799
    1414//
    1515
     
    165165Expression * build_constantFloat( std::string &str );
    166166Expression * build_constantChar( std::string &str );
    167 ConstantExpr * build_constantStr( std::string &str );
     167Expression * build_constantStr( std::string &str );
    168168Expression * build_field_name_FLOATINGconstant( const std::string & str );
    169169Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts );
     
    197197Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
    198198Expression * build_range( ExpressionNode * low, ExpressionNode * high );
    199 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand );
     199Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand );
    200200Expression * build_valexpr( StatementNode * s );
    201201Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
     
    330330        bool hasEllipsis;
    331331        LinkageSpec::Spec linkage;
    332         ConstantExpr *asmName;
     332        Expression *asmName;
    333333        std::list< Attribute * > attributes;
    334334        InitializerNode * initializer;
     
    413413Statement * build_finally( StatementNode * stmt );
    414414Statement * build_compound( StatementNode * first );
    415 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
     415Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    416416WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when );
    417417WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing );
  • src/Parser/StatementNode.cc

    rf43df73 re612146c  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:01:31 2017
    13 // Update Count     : 345
     12// Last Modified On : Fri Sep  1 23:25:23 2017
     13// Update Count     : 346
    1414//
    1515
     
    300300}
    301301
    302 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {
     302Statement *build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {
    303303        std::list< Expression * > out, in;
    304304        std::list< ConstantExpr * > clob;
  • src/Parser/TypeData.cc

    rf43df73 re612146c  
    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 : Mon Aug 14 10:41:00 2017
    13 // Update Count     : 568
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Sep  1 23:13:38 2017
     13// Update Count     : 569
    1414//
    1515
     
    814814} // buildTypeof
    815815
    816 Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
     816Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, Expression *asmName, Initializer * init, std::list< Attribute * > attributes ) {
    817817        if ( td->kind == TypeData::Function ) {
    818818                if ( td->function.idList ) {                                    // KR function ?
  • src/Parser/TypeData.h

    rf43df73 re612146c  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:18:36 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Aug 14 10:38:00 2017
    13 // Update Count     : 189
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Sep  1 23:33:45 2017
     13// Update Count     : 190
    1414//
    1515
     
    118118TupleType * buildTuple( const TypeData * );
    119119TypeofType * buildTypeof( const TypeData * );
    120 Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
     120Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, Expression * asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
    121121FunctionType * buildFunction( const TypeData * );
    122122void buildKRFunction( const TypeData::Function_t & function );
  • src/Parser/parser.yy

    rf43df73 re612146c  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 30 07:04:19 2017
    13 // Update Count     : 2740
     12// Last Modified On : Sun Sep  3 20:43:19 2017
     13// Update Count     : 2742
    1414//
    1515
     
    100100        StatementNode * sn;
    101101        WaitForStmt * wfs;
    102         ConstantExpr * constant;
     102        Expression * constant;
    103103        IfCtl * ifctl;
    104104        ForCtl * fctl;
  • src/SynTree/Declaration.h

    rf43df73 re612146c  
    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 : Mon Aug 14 10:15:00 2017
    13 // Update Count     : 128
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 19:24:06 2017
     13// Update Count     : 131
    1414//
    1515
     
    8282        int scopeLevel = 0;
    8383
    84         ConstantExpr *asmName;
     84        Expression *asmName;
    8585        std::list< Attribute * > attributes;
    8686
     
    9797        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
    9898
    99         ConstantExpr *get_asmName() const { return asmName; }
    100         DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
     99        Expression *get_asmName() const { return asmName; }
     100        DeclarationWithType * set_asmName( Expression *newValue ) { asmName = newValue; return this; }
    101101
    102102        std::list< Attribute * >& get_attributes() { return attributes; }
  • src/SynTree/Expression.h

    rf43df73 re612146c  
    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 : Fri Aug  8 11:54:00 2017
    13 // Update Count     : 44
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 19:23:46 2017
     13// Update Count     : 48
    1414//
     15
    1516#pragma once
    1617
     
    539540  public:
    540541        Expression * inout;
    541         ConstantExpr * constraint;
     542        Expression * constraint;
    542543        Expression * operand;
    543544
    544         AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
     545        AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    545546        AsmExpr( const AsmExpr & other );
    546547        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
     
    549550        void set_inout( Expression * newValue ) { inout = newValue; }
    550551
    551         ConstantExpr * get_constraint() const { return constraint; }
    552         void set_constraint( ConstantExpr * newValue ) { constraint = newValue; }
     552        Expression * get_constraint() const { return constraint; }
     553        void set_constraint( Expression * newValue ) { constraint = newValue; }
    553554
    554555        Expression * get_operand() const { return operand; }
  • src/SynTree/Statement.cc

    rf43df73 re612146c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:17:20 2017
    13 // Update Count     : 67
     12// Last Modified On : Sun Sep  3 20:46:44 2017
     13// Update Count     : 68
    1414//
    1515
     
    5252
    5353
    54 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
     54AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    5555
    5656AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
  • src/SynTree/Statement.h

    rf43df73 re612146c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:37:53 2017
    13 // Update Count     : 72
     12// Last Modified On : Sun Sep  3 20:46:46 2017
     13// Update Count     : 77
    1414//
    1515
     
    9898  public:
    9999        bool voltile;
    100         ConstantExpr *instruction;
     100        Expression *instruction;
    101101        std::list<Expression *> output, input;
    102102        std::list<ConstantExpr *> clobber;
    103103        std::list<Label> gotolabels;
    104104
    105         AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
     105        AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    106106        AsmStmt( const AsmStmt &other );
    107107        virtual ~AsmStmt();
     
    109109        bool get_voltile() { return voltile; }
    110110        void set_voltile( bool newValue ) { voltile = newValue; }
    111         ConstantExpr *get_instruction() { return instruction; }
    112         void set_instruction( ConstantExpr *newValue ) { instruction = newValue; }
    113         std::list<Expression *> &get_output() { return output; }
    114         void set_output( const std::list<Expression *> &newValue ) { output = newValue; }
    115         std::list<Expression *> &get_input() { return input; }
     111        Expression * get_instruction() { return instruction; }
     112        void set_instruction( Expression * newValue ) { instruction = newValue; }
     113        std::list<Expression *> & get_output() { return output; }
     114        void set_output( const std::list<Expression *> & newValue ) { output = newValue; }
     115        std::list<Expression *> & get_input() { return input; }
    116116        void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
    117         std::list<ConstantExpr *> &get_clobber() { return clobber; }
     117        std::list<ConstantExpr *> & get_clobber() { return clobber; }
    118118        void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
    119         std::list<Label> &get_gotolabels() { return gotolabels; }
     119        std::list<Label> & get_gotolabels() { return gotolabels; }
    120120        void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
    121121
    122         virtual AsmStmt *clone() const { return new AsmStmt( *this ); }
    123         virtual void accept( Visitor &v ) { v.visit( this ); }
    124         virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    125         virtual void print( std::ostream &os, int indent = 0 ) const;
     122        virtual AsmStmt * clone() const { return new AsmStmt( *this ); }
     123        virtual void accept( Visitor & v ) { v.visit( this ); }
     124        virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     125        virtual void print( std::ostream & os, int indent = 0 ) const;
    126126};
    127127
Note: See TracChangeset for help on using the changeset viewer.