Changeset 21300d7 for src/AST


Ignore:
Timestamp:
Jun 12, 2019, 4:06:37 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
462a7c7, d60780c
Parents:
aaeacf4 (diff), 6625727 (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:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    raaeacf4 r21300d7  
    21932193
    21942194        int isStringlikeConstantType(const Type *t) {
     2195                const Type *referentType = nullptr;
    21952196                if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
    2196                         if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
     2197                        referentType = aty->base;
     2198                } else if ( const PointerType * pty = dynamic_cast< const PointerType * >( t ) ) {
     2199                        referentType = pty->base;
     2200                }
     2201                if (referentType) {
     2202                        if ( const BasicType * bty = dynamic_cast< const BasicType * >( referentType ) ) {
    21972203                           if ( bty->kind == BasicType::Kind::Char ) {
    21982204                                   return true;
     
    22052211        virtual void visit( ConstantExpr * old ) override final {
    22062212                ast::ConstantExpr *rslt = nullptr;
    2207                 if (isIntlikeConstantType(old->result)) {
     2213                if (isStringlikeConstantType(old->result)) {
     2214                        rslt = new ast::ConstantExpr(
     2215                                old->location,
     2216                                GET_ACCEPT_1(result, Type),
     2217                                old->constant.get_value(),
     2218                                0,
     2219                                ast::ConstantExpr::Kind::String
     2220                        );
     2221                } else if (isIntlikeConstantType(old->result)) {
    22082222                        rslt = new ast::ConstantExpr(
    22092223                                old->location,
     
    22192233                                old->constant.get_value(),
    22202234                                (double) old->constant.get_dval()
    2221                         );
    2222                 } else if (isStringlikeConstantType(old->result)) {
    2223                         rslt = new ast::ConstantExpr(
    2224                                 old->location,
    2225                                 GET_ACCEPT_1(result, Type),
    2226                                 old->constant.get_value(),
    2227                                 0,
    2228                                 ast::ConstantExpr::Kind::String
    22292235                        );
    22302236                }
  • src/AST/Node.hpp

    raaeacf4 r21300d7  
    9999
    100100/// Mutate a node field (only clones if not equal to existing value)
    101 template<typename node_t, typename field_t>
    102 const node_t * mutate_field(
    103         const node_t * node,
    104         typename std::remove_const<typename std::remove_reference<field_t>::type>::type node_t::* field,
    105         field_t&& val
    106 ) {
     101template<typename node_t, typename field_t, typename assn_t>
     102const node_t * mutate_field( const node_t * node, field_t node_t::* field, assn_t && val ) {
     103        // skip mutate if equivalent
    107104        if ( node->*field == val ) return node;
    108105       
     106        // mutate and return
    109107        node_t * ret = mutate( node );
    110         ret->*field = std::forward< field_t >( val );
     108        ret->*field = std::forward< assn_t >( val );
     109        return ret;
     110}
     111
     112/// Mutate a single index of a node field (only clones if not equal to existing value)
     113template<typename node_t, typename coll_t, typename ind_t, typename field_t>
     114const node_t * mutate_field_index(
     115        const node_t * node, coll_t node_t::* field, ind_t i, field_t && val
     116) {
     117        // skip mutate if equivalent
     118        if  ( (node->*field)[i] == val ) return node;
     119
     120        // mutate and return
     121        node_t * ret = mutate( node );
     122        (ret->*field)[i] = std::forward< field_t >( val );
    111123        return ret;
    112124}
  • src/AST/Print.hpp

    raaeacf4 r21300d7  
    1616#pragma once
    1717
    18 #include <iosfwd>
    19 #include <utility> // for forward
     18#include <iostream>
     19#include <utility>   // for forward
    2020
    2121#include "AST/Node.hpp"
     
    3232void printShort( std::ostream & os, const ast::Decl * node, Indenter indent = {} );
    3333
    34 inline void printShort( std::ostream & os, const ast::Decl * node, unsigned int indent ) {
    35     printShort( os, node, Indenter{ indent } );
     34/// Print a collection of items
     35template< typename Coll >
     36void 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    }
    3644}
    3745
  • src/AST/porting.md

    raaeacf4 r21300d7  
    299299* `openVars` => `open`
    300300
     301`ExplodedActual` => `ExplodedArg`
     302* `ExplodedActual.h` => `ExplodedArg.hpp`
     303
    301304[1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes
    302305
Note: See TracChangeset for help on using the changeset viewer.