Changeset 4a60488 for src/SynTree


Ignore:
Timestamp:
Sep 27, 2019, 3:35:46 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
90ce35aa
Parents:
8e1467d (diff), 849720f (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:

Merged from master taking the lvalue changes to expression and everything before that.

Location:
src/SynTree
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AddressExpr.cc

    r8e1467d r4a60488  
    4242AddressExpr::AddressExpr( Expression *arg ) : Expression(), arg( arg ) {
    4343        if ( arg->result ) {
    44                 if ( arg->result->get_lvalue() ) {
     44                if ( arg->get_lvalue() ) {
    4545                        // lvalue, retains all layers of reference and gains a pointer inside the references
    4646                        set_result( addrType( arg->result ) );
  • src/SynTree/ApplicationExpr.cc

    r8e1467d r4a60488  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Apr 26 12:41:06 2016
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Aug 12 14:28:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    2525#include "Declaration.h"         // for Declaration
    2626#include "Expression.h"          // for ParamEntry, ApplicationExpr, Expression
     27#include "InitTweak/InitTweak.h" // for getFunction
    2728#include "ResolvExpr/typeops.h"  // for extractResultType
    2829#include "Type.h"                // for Type, PointerType, FunctionType
     
    7677}
    7778
     79bool ApplicationExpr::get_lvalue() const {
     80        // from src/GenPoly/Lvalue.cc: isIntrinsicReference
     81        static std::set<std::string> lvalueFunctions = { "*?", "?[?]" };
     82        if ( const DeclarationWithType * func = InitTweak::getFunction( this ) ) {
     83                return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name);
     84        }
     85        return false;
     86}
     87
    7888void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
    7989        os << "Application of" << std::endl << indent+1;
  • src/SynTree/BasicType.cc

    r8e1467d r4a60488  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 31 21:37:36 2019
    13 // Update Count     : 12
     12// Last Modified On : Sun Aug  4 21:07:44 2019
     13// Update Count     : 13
    1414//
    1515
     
    3131bool BasicType::isInteger() const {
    3232        return kind <= UnsignedInt128;
    33 #if 0
    34         switch ( kind ) {
    35           case Bool:
    36           case Char:
    37           case SignedChar:
    38           case UnsignedChar:
    39           case ShortSignedInt:
    40           case ShortUnsignedInt:
    41           case SignedInt:
    42           case UnsignedInt:
    43           case LongSignedInt:
    44           case LongUnsignedInt:
    45           case LongLongSignedInt:
    46           case LongLongUnsignedInt:
    47           case SignedInt128:
    48           case UnsignedInt128:
    49                 return true;
    50           case Float:
    51           case Double:
    52           case LongDouble:
    53           case FloatComplex:
    54           case DoubleComplex:
    55           case LongDoubleComplex:
    56           case FloatImaginary:
    57           case DoubleImaginary:
    58           case LongDoubleImaginary:
    59           case Float80:
    60           case Float128:
    61                 return false;
    62           case NUMBER_OF_BASIC_TYPES:
    63                 assert( false );
    64         } // switch
    65         assert( false );
    66         return false;
    67 #endif
    6833}
    6934
  • src/SynTree/CommaExpr.cc

    r8e1467d r4a60488  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon May 02 15:19:44 2016
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Arg 12 16:11:00 2016
     13// Update Count     : 2
    1414//
    1515
     
    3939}
    4040
     41bool CommaExpr::get_lvalue() const {
     42        // This is wrong by C, but the current implementation uses it.
     43        return arg2->get_lvalue();
     44}
     45
    4146void CommaExpr::print( std::ostream &os, Indenter indent ) const {
    4247        os << "Comma Expression:" << std::endl;
  • src/SynTree/Expression.cc

    r8e1467d r4a60488  
    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 : Tue Feb 19 18:10:55 2019
    13 // Update Count     : 60
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 15 13:43:00 2019
     13// Update Count     : 64
    1414//
    1515
     
    1919#include <iostream>                  // for ostream, operator<<, basic_ostream
    2020#include <list>                      // for list, _List_iterator, list<>::co...
     21#include <set>                       // for set
    2122
    2223#include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
     
    6364}
    6465
     66bool Expression::get_lvalue() const {
     67        return false;
     68}
     69
    6570void Expression::print( std::ostream & os, Indenter indent ) const {
    6671        printInferParams( inferParams, os, indent+1, 0 );
     
    134139}
    135140
     141bool VariableExpr::get_lvalue() const {
     142        // It isn't always an lvalue, but it is never an rvalue.
     143        return true;
     144}
     145
    136146VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) {
    137147        VariableExpr * funcExpr = new VariableExpr( func );
     
    252262}
    253263
    254 AttrExpr::AttrExpr( Expression * attr, Expression * expr_ ) :
    255                 Expression(), attr( attr ), expr(expr_), type(0), isType(false) {
    256 }
    257 
    258 AttrExpr::AttrExpr( Expression * attr, Type * type_ ) :
    259                 Expression(), attr( attr ), expr(0), type(type_), isType(true) {
    260 }
    261 
    262 AttrExpr::AttrExpr( const AttrExpr & other ) :
    263                 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
    264 }
    265 
    266 AttrExpr::~AttrExpr() {
    267         delete attr;
    268         delete expr;
    269         delete type;
    270 }
    271 
    272 void AttrExpr::print( std::ostream & os, Indenter indent) const {
    273         os << "Attr ";
    274         attr->print( os, indent+1);
    275         if ( isType || expr ) {
    276                 os << "applied to: ";
    277                 if (isType) type->print(os, indent+1);
    278                 else expr->print(os, indent+1);
    279         } // if
    280         Expression::print( os, indent );
    281 }
    282 
    283264CastExpr::CastExpr( Expression * arg, Type * toType, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) {
    284265        set_result(toType);
     
    294275CastExpr::~CastExpr() {
    295276        delete arg;
     277}
     278
     279bool CastExpr::get_lvalue() const {
     280        // This is actually wrong by C, but it works with our current set-up.
     281        return arg->get_lvalue();
    296282}
    297283
     
    376362}
    377363
     364bool UntypedMemberExpr::get_lvalue() const {
     365        return aggregate->get_lvalue();
     366}
     367
    378368void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const {
    379369        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
     
    405395        // don't delete the member declaration, since it points somewhere else in the tree
    406396        delete aggregate;
     397}
     398
     399bool MemberExpr::get_lvalue() const {
     400        // This is actually wrong by C, but it works with our current set-up.
     401        return true;
    407402}
    408403
     
    457452}
    458453
     454bool UntypedExpr::get_lvalue() const {
     455        // from src/GenPoly/Lvalue.cc: isIntrinsicReference
     456        static std::set<std::string> lvalueFunctions = { "*?", "?[?]" };
     457        std::string fname = InitTweak::getFunctionName( const_cast< UntypedExpr * >( this ) );
     458        return lvalueFunctions.count(fname);
     459}
    459460
    460461void UntypedExpr::print( std::ostream & os, Indenter indent ) const {
     
    515516        delete arg2;
    516517        delete arg3;
     518}
     519
     520bool ConditionalExpr::get_lvalue() const {
     521        return false;
    517522}
    518523
     
    573578}
    574579
     580bool ConstructorExpr::get_lvalue() const {
     581        return false;
     582}
     583
    575584void ConstructorExpr::print( std::ostream & os, Indenter indent ) const {
    576585        os <<  "Constructor Expression: " << std::endl << indent+1;
     
    590599CompoundLiteralExpr::~CompoundLiteralExpr() {
    591600        delete initializer;
     601}
     602
     603bool CompoundLiteralExpr::get_lvalue() const {
     604        return true;
    592605}
    593606
     
    641654                result = new VoidType( Type::Qualifiers() );
    642655        }
     656}
     657bool StmtExpr::get_lvalue() const {
     658        return false;
    643659}
    644660void StmtExpr::print( std::ostream & os, Indenter indent ) const {
  • src/SynTree/Expression.h

    r8e1467d r4a60488  
    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 : Mon Feb 18 18:29:51 2019
    13 // Update Count     : 49
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 15 13:46:00 2019
     13// Update Count     : 54
    1414//
    1515
     
    7171        const Type * get_result() const { return result; }
    7272        void set_result( Type * newValue ) { result = newValue; }
     73        virtual bool get_lvalue() const;
    7374
    7475        TypeSubstitution * get_env() const { return env; }
     
    9899        virtual ~ApplicationExpr();
    99100
     101        bool get_lvalue() const final;
     102
    100103        Expression * get_function() const { return function; }
    101104        void set_function( Expression * newValue ) { function = newValue; }
     
    120123        UntypedExpr( const UntypedExpr & other );
    121124        virtual ~UntypedExpr();
     125
     126        bool get_lvalue() const final;
    122127
    123128        Expression * get_function() const { return function; }
     
    208213        virtual ~CastExpr();
    209214
     215        bool get_lvalue() const final;
     216
    210217        Expression * get_arg() const { return arg; }
    211218        void set_arg( Expression * newValue ) { arg = newValue; }
     
    268275        virtual ~UntypedMemberExpr();
    269276
     277        bool get_lvalue() const final;
     278
    270279        Expression * get_member() const { return member; }
    271280        void set_member( Expression * newValue ) { member = newValue; }
     
    291300        virtual ~MemberExpr();
    292301
     302        bool get_lvalue() const final;
     303
    293304        DeclarationWithType * get_member() const { return member; }
    294305        void set_member( DeclarationWithType * newValue ) { member = newValue; }
     
    313324        VariableExpr( const VariableExpr & other );
    314325        virtual ~VariableExpr();
     326
     327        bool get_lvalue() const final;
    315328
    316329        DeclarationWithType * get_var() const { return var; }
     
    463476};
    464477
    465 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    466 class AttrExpr : public Expression {
    467   public:
    468         Expression * attr;
    469         Expression * expr;
    470         Type * type;
    471         bool isType;
    472 
    473         AttrExpr(Expression * attr, Expression * expr );
    474         AttrExpr( const AttrExpr & other );
    475         AttrExpr( Expression * attr, Type * type );
    476         virtual ~AttrExpr();
    477 
    478         Expression * get_attr() const { return attr; }
    479         void set_attr( Expression * newValue ) { attr = newValue; }
    480         Expression * get_expr() const { return expr; }
    481         void set_expr( Expression * newValue ) { expr = newValue; }
    482         Type * get_type() const { return type; }
    483         void set_type( Type * newValue ) { type = newValue; }
    484         bool get_isType() const { return isType; }
    485         void set_isType( bool newValue ) { isType = newValue; }
    486 
    487         virtual AttrExpr * clone() const override { return new AttrExpr( * this ); }
    488         virtual void accept( Visitor & v ) override { v.visit( this ); }
    489         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    490         virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    491         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    492 };
    493 
    494478/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
    495479class LogicalExpr : public Expression {
     
    528512        ConditionalExpr( const ConditionalExpr & other );
    529513        virtual ~ConditionalExpr();
     514
     515        bool get_lvalue() const final;
    530516
    531517        Expression * get_arg1() const { return arg1; }
     
    553539        virtual ~CommaExpr();
    554540
     541        bool get_lvalue() const final;
     542
    555543        Expression * get_arg1() const { return arg1; }
    556544        void set_arg1( Expression * newValue ) { arg1 = newValue; }
     
    639627        ~ConstructorExpr();
    640628
     629        bool get_lvalue() const final;
     630
    641631        Expression * get_callExpr() const { return callExpr; }
    642632        void set_callExpr( Expression * newValue ) { callExpr = newValue; }
     
    657647        CompoundLiteralExpr( const CompoundLiteralExpr & other );
    658648        virtual ~CompoundLiteralExpr();
     649
     650        bool get_lvalue() const final;
    659651
    660652        Initializer * get_initializer() const { return initializer; }
     
    715707        virtual ~TupleExpr();
    716708
     709        bool get_lvalue() const final;
     710
    717711        std::list<Expression*>& get_exprs() { return exprs; }
    718712
     
    733727        TupleIndexExpr( const TupleIndexExpr & other );
    734728        virtual ~TupleIndexExpr();
     729
     730        bool get_lvalue() const final;
    735731
    736732        Expression * get_tuple() const { return tuple; }
     
    782778        StmtExpr( const StmtExpr & other );
    783779        virtual ~StmtExpr();
     780
     781        bool get_lvalue() const final;
    784782
    785783        CompoundStmt * get_statements() const { return statements; }
  • src/SynTree/Mutator.h

    r8e1467d r4a60488  
    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 Jul 24 16:31:00 2017
    13 // Update Count     : 16
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 25 22:37:46 2019
     13// Update Count     : 17
    1414//
    1515#pragma once
     
    7474        virtual Expression * mutate( OffsetofExpr * offsetofExpr ) = 0;
    7575        virtual Expression * mutate( OffsetPackExpr * offsetPackExpr ) = 0;
    76         virtual Expression * mutate( AttrExpr * attrExpr ) = 0;
    7776        virtual Expression * mutate( LogicalExpr * logicalExpr ) = 0;
    7877        virtual Expression * mutate( ConditionalExpr * conditionalExpr ) = 0;
  • src/SynTree/SynTree.h

    r8e1467d r4a60488  
    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 Jul 24 16:54:00 2017
    13 // Update Count     : 11
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 25 22:37:45 2019
     13// Update Count     : 12
    1414//
    1515
     
    7979class OffsetofExpr;
    8080class OffsetPackExpr;
    81 class AttrExpr;
    8281class LogicalExpr;
    8382class ConditionalExpr;
  • src/SynTree/TupleExpr.cc

    r8e1467d r4a60488  
    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 : Fri Mar 17 09:42:29 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug 14 14:34:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    5757}
    5858
     59bool TupleExpr::get_lvalue() const {
     60        return false;
     61}
     62
    5963void TupleExpr::print( std::ostream &os, Indenter indent ) const {
    6064        os << "Tuple:" << std::endl;
     
    7680TupleIndexExpr::~TupleIndexExpr() {
    7781        delete tuple;
     82}
     83
     84bool TupleIndexExpr::get_lvalue() const {
     85        return tuple->get_lvalue();
    7886}
    7987
  • src/SynTree/Type.cc

    r8e1467d r4a60488  
    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 Jul 12 15:48:00 2019
    13 // Update Count     : 44
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Aug  4 21:05:07 2019
     13// Update Count     : 45
    1414//
    1515#include "Type.h"
     
    2424using namespace std;
    2525
    26 const char *BasicType::typeNames[] = {
    27 #if 0
    28         "_Bool",
    29         "char",
    30         "signed char",
    31         "unsigned char",
    32         "signed short int",
    33         "unsigned short int",
    34         "signed int",
    35         "unsigned int",
    36         "signed long int",
    37         "unsigned long int",
    38         "signed long long int",
    39         "unsigned long long int",
    40         "float",
    41         "double",
    42         "long double",
    43         "float _Complex",
    44         "double _Complex",
    45         "long double _Complex",
    46         "float _Imaginary",
    47         "double _Imaginary",
    48         "long double _Imaginary",
    49         "__int128",
    50         "unsigned __int128",
    51         "__float80",
    52         "__float128",
    53         "_Float16",
    54         "_Float32",
    55         "_Float32x",
    56         "_Float64",
    57         "_Float64x",
    58         "_Float128",
    59         "_Float128x",
    60         "_Float16 _Complex",
    61         "_Float32 _Complex",
    62         "_Float32x _Complex",
    63         "_Float64 _Complex",
    64         "_Float64x _Complex",
    65         "_Float128 _Complex",
    66         "_Float128x _Complex",
    67 #endif
     26const char * BasicType::typeNames[] = {
    6827        "_Bool",
    6928        "char",
     
    10766};
    10867static_assert(
    109         sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
     68        sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
    11069        "Each basic type name should have a corresponding kind enum value"
    11170);
     
    152111TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
    153112
    154 void Type::print( std::ostream &os, Indenter indent ) const {
     113void Type::print( std::ostream & os, Indenter indent ) const {
    155114        if ( ! forall.empty() ) {
    156115                os << "forall" << std::endl;
  • src/SynTree/Type.h

    r8e1467d r4a60488  
    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 : Thu Feb 14 17:11:24 2019
    13 // Update Count     : 169
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Sep  4 09:58:00 2019
     13// Update Count     : 170
    1414//
    1515
     
    131131                bool operator>( Qualifiers other ) const { return *this != other && *this >= other; }
    132132                BFCommon( Qualifiers, NumTypeQualifier )
     133
     134                Qualifiers unify( Qualifiers const & other ) const {
     135                        int or_flags = Mask & (val | other.val);
     136                        int and_flags = val & other.val;
     137                        return Qualifiers( or_flags | and_flags );
     138                }
    133139        }; // Qualifiers
    134140
  • src/SynTree/Visitor.h

    r8e1467d r4a60488  
    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 Jul 24 16:28:00 2017
    13 // Update Count     : 13
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 25 22:21:49 2019
     13// Update Count     : 14
    1414//
    1515
     
    123123        virtual void visit( OffsetPackExpr * node ) { visit( const_cast<const OffsetPackExpr *>(node) ); }
    124124        virtual void visit( const OffsetPackExpr * offsetPackExpr ) = 0;
    125         virtual void visit( AttrExpr * node ) { visit( const_cast<const AttrExpr *>(node) ); }
    126         virtual void visit( const AttrExpr * attrExpr ) = 0;
    127125        virtual void visit( LogicalExpr * node ) { visit( const_cast<const LogicalExpr *>(node) ); }
    128126        virtual void visit( const LogicalExpr * logicalExpr ) = 0;
  • src/SynTree/module.mk

    r8e1467d r4a60488  
    4949      SynTree/TypeSubstitution.cc \
    5050      SynTree/Attribute.cc \
    51       SynTree/DeclReplacer.cc
     51      SynTree/DeclReplacer.cc \
     52      SynTree/TopLvalue.cc
    5253
    5354SRC += $(SRC_SYNTREE)
Note: See TracChangeset for help on using the changeset viewer.