Changeset 5235d49 for src/AST


Ignore:
Timestamp:
Jan 1, 2022, 11:14:35 AM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
12c1eef
Parents:
7770cc8 (diff), db1ebed (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/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r7770cc8 r5235d49  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 15 17:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Created On       : Thr Jun 13 13:38:00 2019
    13 // Update Count     : 6
     11// Last Modified By : Andrew Beach
     12// Created On       : Tue Nov 30 14:23:00 2021
     13// Update Count     : 7
    1414//
    1515
     
    141141        /// The type of the address of a type.
    142142        /// Caller is responsible for managing returned memory
    143         Type * addrType( const Type * type ) {
    144                 if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * >( type ) ) {
    145                         return new ReferenceType{ addrType( refType->base ), refType->qualifiers };
     143        Type * addrType( const ptr<Type> & type ) {
     144                if ( auto refType = type.as< ReferenceType >() ) {
     145                        return new ReferenceType( addrType( refType->base ), refType->qualifiers );
    146146                } else {
    147                         return new PointerType{ type };
     147                        return new PointerType( type );
    148148                }
    149149        }
    150 }
    151 
    152 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) {
    153         if ( arg->result ) {
    154                 if ( arg->get_lvalue() ) {
    155                         // lvalue, retains all levels of reference, and gains a pointer inside the references
    156                         Type * res = addrType( arg->result );
    157                         result = res;
     150
     151        /// The type of the address of an expression.
     152        /// Caller is responsible for managing returned memory
     153        Type * addrExprType( const CodeLocation & loc, const Expr * arg ) {
     154                assert( arg );
     155                // If the expression's type is unknown, the address type is unknown.
     156                if ( nullptr == arg->result ) {
     157                        return nullptr;
     158                // An lvalue is transformed directly.
     159                } else if ( arg->get_lvalue() ) {
     160                        return addrType( arg->result );
     161                // Strip a layer of reference to "create" an lvalue expression.
     162                } else if ( auto refType = arg->result.as< ReferenceType >() ) {
     163                        return addrType( refType->base );
    158164                } else {
    159                         // taking address of non-lvalue, must be a reference, loses one layer of reference
    160                         if ( const ReferenceType * refType =
    161                                         dynamic_cast< const ReferenceType * >( arg->result.get() ) ) {
    162                                 Type * res = addrType( refType->base );
    163                                 result = res;
    164                         } else {
    165                                 SemanticError( loc, arg->result.get(),
    166                                         "Attempt to take address of non-lvalue expression: " );
    167                         }
     165                        SemanticError( loc, arg->result.get(),
     166                                "Attempt to take address of non-lvalue expression: " );
    168167                }
    169168        }
    170169}
     170
     171AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) :
     172        Expr( loc, addrExprType( loc, a ) ), arg( a )
     173{}
    171174
    172175// --- LabelAddressExpr
  • src/AST/Print.cpp

    r7770cc8 r5235d49  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Print.cpp --
     7// Print.cpp -- Print an AST (or sub-tree) to a stream.
    88//
    99// Author           : Thierry Delisle
  • src/AST/Print.hpp

    r7770cc8 r5235d49  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Print.hpp --
     7// Print.hpp -- Print an AST (or sub-tree) to a stream.
    88//
    99// Author           : Thierry Delisle
     
    3535template< typename Coll >
    3636void printAll( std::ostream & os, const Coll & c, Indenter indent = {} ) {
    37     for ( const auto & i : c ) {
    38         if ( ! i ) continue;
    39        
    40         os << indent;
    41         print( os, i, indent );
    42         os << std::endl;
    43     }
     37        for ( const auto & i : c ) {
     38                if ( ! i ) continue;
     39
     40                os << indent;
     41                print( os, i, indent );
     42                os << std::endl;
     43        }
    4444}
    4545
Note: See TracChangeset for help on using the changeset viewer.