Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r558d13b r6355ba7  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Man Jun 10 11:51:00 2019
    13 // Update Count     : 11
     12// Last Modified On : Thu May 06 19:51:00 2019
     13// Update Count     : 10
    1414//
    1515
     
    9292
    9393        Label makeLabel(Statement * labelled, const ast::Label& label) {
    94                 // This probably will leak memory, but only until we get rid of the old tree.
    95                 if ( nullptr == labelled && label.location.isSet() ) {
    96                         labelled = new NullStmt();
    97                         labelled->location = label.location;
    98                 }
    9994                return Label(
    10095                        label.name,
     
    13891384        // Local Utilities:
    13901385
     1386        #define construct(T, key, ...) ({ \
     1387                void * data = ::operator new(sizeof(T)); \
     1388                cache.emplace( key, (T*)data ); \
     1389                new (data) T( __VA_ARGS__ ); \
     1390        })
     1391
    13911392        template<typename NewT, typename OldT>
    13921393        NewT * getAccept1( OldT old ) {
     
    14021403
    14031404        template<typename NewT, typename OldC>
    1404         std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
     1405        std::vector< ast::ptr<NewT> > getAcceptV( OldC& old ) {
    14051406                std::vector< ast::ptr<NewT> > ret;
    14061407                ret.reserve( old.size() );
     
    14171418
    14181419        template<typename NewT, typename OldC>
    1419         std::deque< ast::ptr<NewT> > getAcceptD( const OldC& old ) {
     1420        std::deque< ast::ptr<NewT> > getAcceptD( OldC& old ) {
    14201421                std::deque< ast::ptr<NewT> > ret;
    14211422                for ( auto a : old ) {
     
    14301431                getAcceptD< ast::type, decltype( old->child ) >( old->child )
    14311432
    1432         ast::Label make_label(const Label* old) {
    1433                 CodeLocation const & location =
    1434                     ( old->labelled ) ? old->labelled->location : CodeLocation();
     1433        ast::Label make_label(Label* old) {
    14351434                return ast::Label(
    1436                         location,
     1435                        old->labelled->location,
    14371436                        old->name,
    14381437                        GET_ACCEPT_V(attributes, Attribute)
     
    18061805                        }
    18071806
     1807                        Label label = old->originalTarget;
    18081808                        auto stmt = new ast::BranchStmt(
    18091809                                old->location,
    18101810                                kind,
    1811                                 make_label(&old->originalTarget),
     1811                                make_label(&label),
    18121812                                GET_LABELS_V(old->labels)
    18131813                        );
     
    21912191
    21922192        int isStringlikeConstantType(const Type *t) {
    2193                 const Type *referentType = nullptr;
    21942193                if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
    2195                         referentType = aty->base;
    2196                 } else if ( const PointerType * pty = dynamic_cast< const PointerType * >( t ) ) {
    2197                         referentType = pty->base;
    2198                 }
    2199                 if (referentType) {
    2200                         if ( const BasicType * bty = dynamic_cast< const BasicType * >( referentType ) ) {
     2194                        if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
    22012195                           if ( bty->kind == BasicType::Kind::Char ) {
    22022196                                   return true;
     
    22092203        virtual void visit( ConstantExpr * old ) override final {
    22102204                ast::ConstantExpr *rslt = nullptr;
    2211                 if (isStringlikeConstantType(old->result)) {
    2212                         rslt = new ast::ConstantExpr(
    2213                                 old->location,
    2214                                 GET_ACCEPT_1(result, Type),
    2215                                 old->constant.get_value(),
    2216                                 0,
    2217                                 ast::ConstantExpr::Kind::String
    2218                         );
    2219                 } else if (isIntlikeConstantType(old->result)) {
     2205                if (isIntlikeConstantType(old->result)) {
    22202206                        rslt = new ast::ConstantExpr(
    22212207                                old->location,
     
    22312217                                old->constant.get_value(),
    22322218                                (double) old->constant.get_dval()
     2219                        );
     2220                } else if (isStringlikeConstantType(old->result)) {
     2221                        rslt = new ast::ConstantExpr(
     2222                                old->location,
     2223                                GET_ACCEPT_1(result, Type),
     2224                                old->constant.get_value(),
     2225                                0,
     2226                                ast::ConstantExpr::Kind::String
    22332227                        );
    22342228                }
Note: See TracChangeset for help on using the changeset viewer.