source: src/SynTree/AddressExpr.cc @ 70d826cd

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 70d826cd was 5809461, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Fix handling of GCC label address and computed goto

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[89231bc]7// AddressExpr.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 23:54:44 2015
[89231bc]11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Apr 26 12:35:13 2016
[a08ba92]13// Update Count     : 6
[0dd3a2f]14//
[51b7345]15
[ea6332d]16#include <ostream>           // for ostream, operator<<, basic_ostream, endl
17#include <string>            // for operator<<, string
18
19#include "Common/utility.h"  // for maybeClone
20#include "Expression.h"      // for AddressExpr, Expression
21#include "Type.h"            // for PointerType, Type, Type::Qualifiers
[51b7345]22
[c5e3208]23// Address expressions are typed based on the following inference rules:
24//    E : lvalue T  &..& (n references)
25//   &E :        T *&..& (n references)
26//
27//    E : T  &..&        (m references)
28//   &E : T *&..&        (m-1 references)
29//
30// That is, lvalues becomes
31
32namespace {
33        Type * addrType( Type * type ) {
34                if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( type ) ) {
35                        return new ReferenceType( refType->get_qualifiers(), addrType( refType->get_base() ) );
36                } else {
37                        return new PointerType( Type::Qualifiers(), type->clone() );
38                }
39        }
40}
41
[0dd3a2f]42AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
[906e24d]43        if ( arg->has_result() ) {
[c5e3208]44                if ( arg->get_result()->get_lvalue() ) {
45                        // lvalue, retains all layers of reference and gains a pointer inside the references
46                        set_result( addrType( arg->get_result() ) );
[ce8c12f]47                } else {
[c5e3208]48                        // taking address of non-lvalue -- must be a reference, loses one layer of reference
49                        ReferenceType * refType = safe_dynamic_cast< ReferenceType * >( arg->get_result() );
50                        set_result( addrType( refType->get_base() ) );
[ce8c12f]51                }
[c5e3208]52                // result of & is never an lvalue
53                get_result()->set_lvalue( false );
[906e24d]54        }
[51b7345]55}
56
[0dd3a2f]57AddressExpr::AddressExpr( const AddressExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
[51b7345]58}
59
[0dd3a2f]60AddressExpr::~AddressExpr() {
[a08ba92]61        delete arg;
[51b7345]62}
63
[0dd3a2f]64void AddressExpr::print( std::ostream &os, int indent ) const {
[89231bc]65        os << "Address of:" << std::endl;
[a08ba92]66        if ( arg ) {
[89231bc]67                os << std::string( indent+2, ' ' );
[906e24d]68                arg->print( os, indent+2 );
[a08ba92]69        } // if
[51b7345]70}
71
[5809461]72LabelAddressExpr::LabelAddressExpr( const Label &arg ) : arg( arg ) {
73        // label address always has type void *
74        result = new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) );
75}
76LabelAddressExpr::LabelAddressExpr( const LabelAddressExpr & other ) : Expression( other ), arg( other.arg ) {}
77LabelAddressExpr::~LabelAddressExpr() {}
78
79void LabelAddressExpr::print( std::ostream & os, int indent ) const {
80        os << "Address of label:" << std::endl << std::string( indent+2, ' ' ) << arg;
81}
82
[0dd3a2f]83// Local Variables: //
84// tab-width: 4 //
85// mode: c++ //
86// compile-command: "make install" //
87// End: //
Note: See TracBrowser for help on using the repository browser.