Changeset 74ec742 for src


Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (4 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (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
Files:
14 added
1 deleted
54 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r29d8c02 r74ec742  
    9393        };
    9494
    95     template<typename T>
    96     Getter<T> get() {
    97         return Getter<T>{ *this };
    98     }
     95        template<typename T>
     96        Getter<T> get() {
     97                return Getter<T>{ *this };
     98        }
    9999
    100100        Label makeLabel(Statement * labelled, const ast::Label& label) {
     
    16511651                        // GET_ACCEPT_1(type, FunctionType),
    16521652                        std::move(forall),
     1653                        std::move(assertions),
    16531654                        std::move(paramVars),
    16541655                        std::move(returnVars),
     
    16641665                cache.emplace( old, decl );
    16651666
    1666                 decl->assertions = std::move(assertions);
    16671667                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    16681668                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
     
    17301730        }
    17311731
    1732         // Convert SynTree::EnumDecl to AST::EnumDecl
     1732
    17331733        virtual void visit( const EnumDecl * old ) override final {
    17341734                if ( inCache( old ) ) return;
     
    27292729                        ty->forall.emplace_back(new ast::TypeInstType(param));
    27302730                        for (auto asst : param->assertions) {
    2731                                 ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
     2731                                ty->assertions.emplace_back(
     2732                                        new ast::VariableExpr(param->location, asst));
    27322733                        }
    27332734                }
  • src/AST/Copy.cpp

    r29d8c02 r74ec742  
    1010// Created On       : Thr Nov 11  9:16:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Nov 11  9:28:00 2021
    13 // Update Count     : 0
     12// Last Modified On : Tue May  3 16:28:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    7777        }
    7878
     79        void postvisit( const UniqueExpr * node ) {
     80                readonlyInsert( &node->object );
     81        }
     82
    7983        void postvisit( const MemberExpr * node ) {
    8084                readonlyInsert( &node->member );
  • src/AST/Decl.cpp

    r29d8c02 r74ec742  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 12 16:54:55 2021
    13 // Update Count     : 23
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu May  5 12:10:00 2022
     13// Update Count     : 24
    1414//
    1515
     
    5353// --- FunctionDecl
    5454
    55 FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name, 
     55FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name,
    5656        std::vector<ptr<TypeDecl>>&& forall,
    5757        std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     
    7474        }
    7575        this->type = ftype;
     76}
     77
     78FunctionDecl::FunctionDecl( const CodeLocation & location, const std::string & name,
     79        std::vector<ptr<TypeDecl>>&& forall, std::vector<ptr<DeclWithType>>&& assertions,
     80        std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     81        CompoundStmt * stmts, Storage::Classes storage, Linkage::Spec linkage,
     82        std::vector<ptr<Attribute>>&& attrs, Function::Specs fs, bool isVarArgs)
     83: DeclWithType( location, name, storage, linkage, std::move(attrs), fs ),
     84                params( std::move(params) ), returns( std::move(returns) ),
     85                type_params( std::move( forall) ), assertions( std::move( assertions ) ),
     86                type( nullptr ), stmts( stmts ) {
     87        FunctionType * type = new FunctionType( (isVarArgs) ? VariableArgs : FixedArgs );
     88        for ( auto & param : this->params ) {
     89                type->params.emplace_back( param->get_type() );
     90        }
     91        for ( auto & ret : this->returns ) {
     92                type->returns.emplace_back( ret->get_type() );
     93        }
     94        for ( auto & param : this->type_params ) {
     95                type->forall.emplace_back( new TypeInstType( param ) );
     96        }
     97        for ( auto & assertion : this->assertions ) {
     98                type->assertions.emplace_back(
     99                        new VariableExpr( assertion->location, assertion ) );
     100        }
     101        this->type = type;
    76102}
    77103
  • src/AST/Decl.hpp

    r29d8c02 r74ec742  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 12 18:25:05 2021
    13 // Update Count     : 32
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu May  5 12:09:00 2022
     13// Update Count     : 33
    1414//
    1515
     
    135135        std::vector< ptr<Expr> > withExprs;
    136136
     137        // The difference between the two constructors is in how they handle
     138        // assertions. The first constructor uses the assertions from the type
     139        // parameters, in the style of the old ast, and puts them on the type.
     140        // The second takes an explicite list of assertions and builds a list of
     141        // references to them on the type.
     142
    137143        FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
    138144                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    139145                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    140146                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
    141         // : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
    142         //  stmts( stmts ) {}
     147
     148        FunctionDecl( const CodeLocation & location, const std::string & name,
     149                std::vector<ptr<TypeDecl>>&& forall, std::vector<ptr<DeclWithType>>&& assertions,
     150                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     151                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
     152                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
    143153
    144154        const Type * get_type() const override;
  • src/AST/Expr.cpp

    r29d8c02 r74ec742  
    1010// Created On       : Wed May 15 17:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Created On       : Tue Nov 30 14:23:00 2021
    13 // Update Count     : 7
     12// Created On       : Wed May 18 13:56:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    2121
    2222#include "Copy.hpp"                // for shallowCopy
    23 #include "Eval.hpp"                // for call
    2423#include "GenericSubstitution.hpp"
    2524#include "LinkageSpec.hpp"
     
    6766// --- UntypedExpr
    6867
     68bool UntypedExpr::get_lvalue() const {
     69        std::string fname = InitTweak::getFunctionName( this );
     70        return lvalueFunctionNames.count( fname );
     71}
     72
    6973UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, const Expr * arg ) {
    7074        assert( arg );
    7175
    72         UntypedExpr * ret = call( loc, "*?", arg );
     76        UntypedExpr * ret = createCall( loc, "*?", { arg } );
    7377        if ( const Type * ty = arg->result ) {
    7478                const Type * base = InitTweak::getPointerBase( ty );
     
    8791}
    8892
    89 bool UntypedExpr::get_lvalue() const {
    90         std::string fname = InitTweak::getFunctionName( this );
    91         return lvalueFunctionNames.count( fname );
    92 }
    93 
    9493UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ) {
    9594        assert( lhs && rhs );
    9695
    97         UntypedExpr * ret = call( loc, "?=?", lhs, rhs );
     96        UntypedExpr * ret = createCall( loc, "?=?", { lhs, rhs } );
    9897        if ( lhs->result && rhs->result ) {
    9998                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
     
    102101        }
    103102        return ret;
     103}
     104
     105UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc,
     106                const std::string & name, std::vector<ptr<Expr>> && args ) {
     107        return new UntypedExpr( loc,
     108                        new NameExpr( loc, name ), std::move( args ) );
    104109}
    105110
  • src/AST/Expr.hpp

    r29d8c02 r74ec742  
    230230        /// Creates a new assignment expression
    231231        static UntypedExpr * createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs );
     232        /// Creates a new call of a variable.
     233        static UntypedExpr * createCall( const CodeLocation & loc,
     234                const std::string & name, std::vector<ptr<Expr>> && args );
    232235
    233236        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    784787public:
    785788        ptr<Expr> expr;
    786         ptr<ObjectDecl> object;
     789        readonly<ObjectDecl> object;
    787790        ptr<VariableExpr> var;
    788791        unsigned long long id;
  • src/AST/Label.hpp

    r29d8c02 r74ec742  
    3434        std::vector< ptr<Attribute> > attributes;
    3535
    36         Label( CodeLocation loc, const std::string& name = "",
     36        Label( const CodeLocation& loc, const std::string& name = "",
    3737                std::vector<ptr<Attribute>> && attrs = std::vector<ptr<Attribute>>{} )
    3838        : location( loc ), name( name ), attributes( attrs ) {}
  • src/AST/Node.hpp

    r29d8c02 r74ec742  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Mar 25 10:33:00 2022
    13 // Update Count     : 7
     12// Last Modified On : Mon May  9 10:20:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    4949
    5050        bool unique() const { return strong_count == 1; }
    51         bool isManaged() const {return strong_count > 0; }
     51        bool isManaged() const { return strong_count > 0; }
     52        bool isReferenced() const { return weak_count > 0; }
     53        bool isStable() const {
     54                return (1 == strong_count || (1 < strong_count && 0 == weak_count));
     55        }
    5256
    5357private:
  • src/AST/Pass.proto.hpp

    r29d8c02 r74ec742  
    131131        template< typename node_t >
    132132        struct result1 {
    133                 bool differs;
    134                 const node_t * value;
     133                bool differs = false;
     134                const node_t * value = nullptr;
    135135
    136136                template< typename object_t, typename super_t, typename field_t >
     
    151151                };
    152152
    153                 bool differs;
     153                bool differs = false;
    154154                container_t< delta > values;
    155155
     
    167167        template< template<class...> class container_t, typename node_t >
    168168        struct resultN {
    169                 bool differs;
     169                bool differs = false;
    170170                container_t<ptr<node_t>> values;
    171171
  • src/AST/Stmt.cpp

    r29d8c02 r74ec742  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May  8 13:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 19:01:20 2022
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue May  3 15:18:20 2022
     13// Update Count     : 4
    1414//
    1515
    1616#include "Stmt.hpp"
    1717
    18 
     18#include "Copy.hpp"
    1919#include "DeclReplacer.hpp"
    2020#include "Type.hpp"
     
    2323
    2424// --- CompoundStmt
    25 CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids(other.kids) {
     25CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids() {
     26        // Statements can have weak references to them, if that happens inserting
     27        // the original node into the new list will put the original node in a
     28        // bad state, where it cannot be mutated. To avoid this, just perform an
     29        // additional shallow copy on the statement.
     30        for ( const Stmt * kid : other.kids ) {
     31                if ( kid->isReferenced() ) {
     32                        kids.emplace_back( ast::shallowCopy( kid ) );
     33                } else {
     34                        kids.emplace_back( kid );
     35                }
     36        }
     37
    2638        // when cloning a compound statement, we may end up cloning declarations which
    2739        // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
  • src/AST/Stmt.hpp

    r29d8c02 r74ec742  
    5858        // cannot be, they are sub-types of this type, for organization.
    5959
    60     StmtClause( const CodeLocation & loc )
     60        StmtClause( const CodeLocation & loc )
    6161                : ParseNode(loc) {}
    6262
     
    396396class WaitForClause final : public StmtClause {
    397397  public:
    398     ptr<Expr> target_func;
    399     std::vector<ptr<Expr>> target_args;
    400     ptr<Stmt> stmt;
    401     ptr<Expr> cond;
    402 
    403     WaitForClause( const CodeLocation & loc )
     398        ptr<Expr> target_func;
     399        std::vector<ptr<Expr>> target_args;
     400        ptr<Stmt> stmt;
     401        ptr<Expr> cond;
     402
     403        WaitForClause( const CodeLocation & loc )
    404404                : StmtClause( loc ) {}
    405405
    406406        const WaitForClause * accept( Visitor & v ) const override { return v.visit( this ); }
    407407  private:
    408     WaitForClause * clone() const override { return new WaitForClause{ *this }; }
    409     MUTATE_FRIEND
     408        WaitForClause * clone() const override { return new WaitForClause{ *this }; }
     409        MUTATE_FRIEND
    410410};
    411411
  • src/AST/Util.cpp

    r29d8c02 r74ec742  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Util.hpp -- General utilities for working with the AST.
     7// Util.cpp -- General utilities for working with the AST.
    88//
    99// Author           : Andrew Beach
    1010// Created On       : Wed Jan 19  9:46:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Mar 11 18:07:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Wed May 11 16:16:00 2022
     13// Update Count     : 3
    1414//
    1515
     
    4646
    4747/// Check that every note that can has a set CodeLocation.
    48 struct SetCodeLocationsCore {
    49         void previsit( const ParseNode * node ) {
    50                 assert( node->location.isSet() );
     48void isCodeLocationSet( const ParseNode * node ) {
     49        assert( node->location.isSet() );
     50}
     51
     52void areLabelLocationsSet( const Stmt * stmt ) {
     53        for ( const Label& label : stmt->labels ) {
     54                assert( label.location.isSet() );
    5155        }
    52 };
     56}
     57
     58/// Make sure the reference counts are in a valid combination.
     59void isStable( const Node * node ) {
     60        assert( node->isStable() );
     61}
     62
     63/// Check that a FunctionDecl is synchronized with it's FunctionType.
     64void functionDeclMatchesType( const FunctionDecl * decl ) {
     65        // The type is a cache of sorts, if it is missing that is only a
     66        // problem if isTypeFixed is set.
     67        if ( decl->isTypeFixed ) {
     68                assert( decl->type );
     69        } else if ( !decl->type ) {
     70                return;
     71        }
     72
     73        const FunctionType * type = decl->type;
     74
     75        // Check that `type->forall` corresponds with `decl->type_params`.
     76        assert( type->forall.size() == decl->type_params.size() );
     77        // Check that `type->assertions` corresponds with `decl->assertions`.
     78        assert( type->assertions.size() == decl->assertions.size() );
     79        // Check that `type->params` corresponds with `decl->params`.
     80        assert( type->params.size() == decl->params.size() );
     81        // Check that `type->returns` corresponds with `decl->returns`.
     82        assert( type->returns.size() == decl->returns.size() );
     83}
    5384
    5485struct InvariantCore {
     
    5687        // None of the passes should make changes so ordering doesn't matter.
    5788        NoStrongCyclesCore no_strong_cycles;
    58         SetCodeLocationsCore set_code_locations;
    5989
    6090        void previsit( const Node * node ) {
    6191                no_strong_cycles.previsit( node );
     92                isStable( node );
    6293        }
    6394
    6495        void previsit( const ParseNode * node ) {
    65                 no_strong_cycles.previsit( node );
    66                 set_code_locations.previsit( node );
     96                previsit( (const Node *)node );
     97                isCodeLocationSet( node );
     98        }
     99
     100        void previsit( const FunctionDecl * node ) {
     101                previsit( (const ParseNode *)node );
     102                functionDeclMatchesType( node );
     103        }
     104
     105        void previsit( const Stmt * node ) {
     106                previsit( (const ParseNode *)node );
     107                areLabelLocationsSet( node );
    67108        }
    68109
  • src/AST/module.mk

    r29d8c02 r74ec742  
    2929        AST/DeclReplacer.cpp \
    3030        AST/DeclReplacer.hpp \
    31         AST/Eval.hpp \
    3231        AST/Expr.cpp \
    3332        AST/Expr.hpp \
  • src/CodeGen/CodeGenerator.cc

    r29d8c02 r74ec742  
    12381238} // namespace CodeGen
    12391239
    1240 
    1241 unsigned Indenter::tabsize = 2;
    1242 
    1243 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {
    1244         if ( node ) {
    1245                 node->print( out );
    1246         } else {
    1247                 out << "nullptr";
    1248         }
    1249         return out;
    1250 }
    1251 
    12521240// Local Variables: //
    12531241// tab-width: 4 //
  • src/CodeGen/FixMain.cc

    r29d8c02 r74ec742  
    4949
    5050}
    51 
    52         bool FixMain::replace_main = false;
    5351
    5452        template<typename container>
  • src/CodeGen/LinkOnce.cc

    r29d8c02 r74ec742  
    5353                                new ConstantExpr( Constant::from_string( section_name ) )
    5454                        );
     55
     56                        // Unconditionnaly add "visibility(default)" to anything with gnu.linkonce
     57                        // visibility is a mess otherwise
     58                        attributes.push_back(new Attribute("visibility", {new ConstantExpr( Constant::from_string( "default" ) )}));
     59
    5560                }
    5661                visit_children = false;
  • src/CodeGen/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Sat Dec 14 07:29:42 2019
    14 ## Update Count     : 4
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:26:00 2022
     14## Update Count     : 5
    1515###############################################################################
    1616
    17 #SRC +=  ArgTweak/Rewriter.cc \
    18 #       ArgTweak/Mutate.cc
     17SRC_CODEGEN = \
     18        CodeGen/FixMain2.cc \
     19        CodeGen/FixMain.h \
     20        CodeGen/OperatorTable.cc \
     21        CodeGen/OperatorTable.h
    1922
    20 SRC_CODEGEN = \
     23SRC += $(SRC_CODEGEN) \
    2124        CodeGen/CodeGenerator.cc \
    2225        CodeGen/CodeGenerator.h \
     26        CodeGen/Generate.cc \
     27        CodeGen/Generate.h \
    2328        CodeGen/FixMain.cc \
    24         CodeGen/FixMain.h \
     29        CodeGen/FixNames.cc \
     30        CodeGen/FixNames.h \
    2531        CodeGen/GenType.cc \
    2632        CodeGen/GenType.h \
    2733        CodeGen/LinkOnce.cc \
    2834        CodeGen/LinkOnce.h \
    29         CodeGen/OperatorTable.cc \
    30         CodeGen/OperatorTable.h \
    3135        CodeGen/Options.h
    3236
    33 SRC += $(SRC_CODEGEN) CodeGen/Generate.cc CodeGen/Generate.h CodeGen/FixNames.cc CodeGen/FixNames.h
    3437SRCDEMANGLE += $(SRC_CODEGEN)
  • src/Common/CodeLocationTools.cpp

    r29d8c02 r74ec742  
    1010// Created On       : Fri Dec  4 15:42:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Mar 14 15:14:00 2022
    13 // Update Count     : 4
     12// Last Modified On : Wed May 11 16:16:00 2022
     13// Update Count     : 5
    1414//
    1515
     
    2424namespace {
    2525
    26 // There are a lot of helpers in this file that could be used much more
    27 // generally if anyone has another use for them.
    28 
    29 // Check if a node type has a code location.
    30 template<typename node_t>
    31 struct has_code_location : public std::is_base_of<ast::ParseNode, node_t> {};
    32 
    33 template<typename node_t, bool has_location>
    34 struct __GetCL;
    35 
    36 template<typename node_t>
    37 struct __GetCL<node_t, true> {
    38         static inline CodeLocation const * get( node_t const * node ) {
    39                 return &node->location;
    40         }
    41 
    42         static inline CodeLocation * get( node_t * node ) {
    43                 return &node->location;
    44         }
    45 };
    46 
    47 template<typename node_t>
    48 struct __GetCL<node_t, false> {
    49         static inline CodeLocation * get( node_t const * ) {
    50                 return nullptr;
    51         }
    52 };
    53 
    54 template<typename node_t>
    55 CodeLocation const * get_code_location( node_t const * node ) {
    56         return __GetCL< node_t, has_code_location< node_t >::value >::get( node );
    57 }
    58 
    59 template<typename node_t>
    60 CodeLocation * get_code_location( node_t * node ) {
    61         return __GetCL< node_t, has_code_location< node_t >::value >::get( node );
    62 }
    63 
    6426// Fill every location with a nearby (parent) location.
    6527class FillCore : public ast::WithGuards {
    6628        CodeLocation const * parent;
     29
     30        template<typename node_t>
     31        node_t const * parse_visit( node_t const * node ) {
     32                if ( node->location.isUnset() ) {
     33                        assert( parent );
     34                        node_t * newNode = ast::mutate( node );
     35                        newNode->location = *parent;
     36                        return newNode;
     37                }
     38                GuardValue( parent ) = &node->location;
     39                return node;
     40        }
     41
     42        bool hasUnsetLabels( const ast::Stmt * stmt ) {
     43                for ( const ast::Label& label : stmt->labels ) {
     44                        if ( label.location.isUnset() ) {
     45                                return true;
     46                        }
     47                }
     48                return false;
     49        }
     50
     51        template<typename node_t>
     52        node_t const * stmt_visit( node_t const * node ) {
     53                assert( node->location.isSet() );
     54
     55                if ( hasUnsetLabels( node ) ) {
     56                        node_t * newNode = ast::mutate( node );
     57                        for ( ast::Label& label : newNode->labels ) {
     58                                if ( label.location.isUnset() ) {
     59                                        label.location = newNode->location;
     60                                }
     61                        }
     62                        return newNode;
     63                }
     64                return node;
     65        }
     66
     67        template<typename node_t>
     68        auto visit( node_t const * node, long ) {
     69                return node;
     70        }
     71
     72        template<typename node_t>
     73        auto visit( node_t const * node, int ) -> typename
     74                        std::remove_reference< decltype( node->location, node ) >::type {
     75                return parse_visit( node );
     76        }
     77
     78        template<typename node_t>
     79        auto visit( node_t const * node, char ) -> typename
     80                        std::remove_reference< decltype( node->labels, node ) >::type {
     81                return stmt_visit( parse_visit( node ) );
     82        }
     83
    6784public:
    6885        FillCore() : parent( nullptr ) {}
     86        FillCore( const CodeLocation& location ) : parent( &location ) {
     87                assert( location.isSet() );
     88        }
    6989
    7090        template<typename node_t>
    7191        node_t const * previsit( node_t const * node ) {
    72                 GuardValue( parent );
    73                 CodeLocation const * location = get_code_location( node );
    74                 if ( location && location->isUnset() ) {
    75                         assert( parent );
    76                         node_t * newNode = ast::mutate( node );
    77                         CodeLocation * newLocation = get_code_location( newNode );
    78                         assert( newLocation );
    79                         *newLocation = *parent;
    80                         parent = newLocation;
    81                         return newNode;
    82                 } else if ( location ) {
    83                         parent = location;
    84                 }
    85                 return node;
     92                return visit( node, '\0' );
    8693        }
    8794};
     
    233240
    234241        template<typename node_t>
    235         void previsit( node_t const * node ) {
    236                 CodeLocation const * location = get_code_location( node );
    237                 if ( location && location->isUnset() ) {
     242        auto previsit( node_t const * node ) -> decltype( node->location, void() ) {
     243                if ( node->location.isUnset() ) {
    238244                        unset.push_back( node );
    239                 }
    240         }
    241 };
    242 
    243 class LocalFillCore : public ast::WithGuards {
    244         CodeLocation const * parent;
    245 public:
    246         LocalFillCore( CodeLocation const & location ) : parent( &location ) {
    247                 assert( location.isSet() );
    248         }
    249 
    250         template<typename node_t>
    251         auto previsit( node_t const * node )
    252                         -> typename std::enable_if<has_code_location<node_t>::value, node_t const *>::type {
    253                 if ( node->location.isSet() ) {
    254                         GuardValue( parent ) = &node->location;
    255                         return node;
    256                 } else {
    257                         node_t * mut = ast::mutate( node );
    258                         mut->location = *parent;
    259                         return mut;
    260245                }
    261246        }
     
    304289ast::Node const * localFillCodeLocations(
    305290                CodeLocation const & location , ast::Node const * node ) {
    306         ast::Pass<LocalFillCore> visitor( location );
     291        ast::Pass<FillCore> visitor( location );
    307292        return node->accept( visitor );
    308293}
  • src/Common/Indenter.h

    r29d8c02 r74ec742  
    1010// Created On       : Fri Jun 30 16:55:23 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 11 11:15:00 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri May 13 14:10:00 2022
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef INDENTER_H
    17 #define INDENTER_H
     16#pragma once
     17
     18#include <ostream>
    1819
    1920struct Indenter {
     
    3738        return out << std::string(indent.indent * indent.amt, ' ');
    3839}
    39 
    40 #endif // INDENTER_H
  • src/Common/SemanticError.h

    r29d8c02 r74ec742  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 19 10:09:17 2018
    13 // Update Count     : 31
     12// Last Modified On : Wed May  4 14:08:26 2022
     13// Update Count     : 35
    1414//
    1515
     
    5959        {"aggregate-forward-decl" , Severity::Warn    , "forward declaration of nested aggregate: %s"                },
    6060        {"superfluous-decl"       , Severity::Warn    , "declaration does not allocate storage: %s"                  },
     61        {"superfluous-else"       , Severity::Warn    , "else clause never executed for empty loop conditional"      },
    6162        {"gcc-attributes"         , Severity::Warn    , "invalid attribute: %s"                                      },
    6263        {"c++-like-copy"          , Severity::Warn    , "Constructor from reference is not a valid copy constructor" },
     
    6970        AggrForwardDecl,
    7071        SuperfluousDecl,
     72        SuperfluousElse,
    7173        GccAttributes,
    7274        CppCopy,
     
    7981);
    8082
    81 #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, __VA_ARGS__)
     83#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, ##__VA_ARGS__)
    8284
    8385void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
  • src/Common/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Tue Sep 27 11:06:38 2016
    14 ## Update Count     : 4
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:27:00 2022
     14## Update Count     : 5
    1515###############################################################################
    1616
    1717SRC_COMMON = \
    18       Common/Assert.cc \
    19       Common/CodeLocation.h \
    20       Common/CodeLocationTools.hpp \
    21       Common/CodeLocationTools.cpp \
    22       Common/CompilerError.h \
    23       Common/Debug.h \
    24       Common/DeclStats.hpp \
    25       Common/DeclStats.cpp \
    26       Common/ErrorObjects.h \
    27       Common/Eval.cc \
    28       Common/Examine.cc \
    29       Common/Examine.h \
    30       Common/FilterCombos.h \
    31       Common/Indenter.h \
    32       Common/PassVisitor.cc \
    33       Common/PassVisitor.h \
    34       Common/PassVisitor.impl.h \
    35       Common/PassVisitor.proto.h \
    36       Common/PersistentMap.h \
    37       Common/ResolvProtoDump.hpp \
    38       Common/ResolvProtoDump.cpp \
    39       Common/ScopedMap.h \
    40       Common/SemanticError.cc \
    41       Common/SemanticError.h \
    42       Common/Stats.h \
    43       Common/Stats/Base.h \
    44       Common/Stats/Counter.cc \
    45       Common/Stats/Counter.h \
    46       Common/Stats/Heap.cc \
    47       Common/Stats/Heap.h \
    48       Common/Stats/ResolveTime.cc \
    49       Common/Stats/ResolveTime.h \
    50       Common/Stats/Stats.cc \
    51       Common/Stats/Time.cc \
    52       Common/Stats/Time.h \
    53       Common/UnimplementedError.h \
    54       Common/UniqueName.cc \
    55       Common/UniqueName.h \
    56       Common/utility.h \
    57       Common/VectorMap.h
     18        Common/Assert.cc \
     19        Common/CodeLocation.h \
     20        Common/CodeLocationTools.hpp \
     21        Common/CodeLocationTools.cpp \
     22        Common/CompilerError.h \
     23        Common/Debug.h \
     24        Common/DeclStats.hpp \
     25        Common/DeclStats.cpp \
     26        Common/ErrorObjects.h \
     27        Common/Eval.cc \
     28        Common/Examine.cc \
     29        Common/Examine.h \
     30        Common/FilterCombos.h \
     31        Common/Indenter.h \
     32        Common/Indenter.cc \
     33        Common/PassVisitor.cc \
     34        Common/PassVisitor.h \
     35        Common/PassVisitor.impl.h \
     36        Common/PassVisitor.proto.h \
     37        Common/PersistentMap.h \
     38        Common/ResolvProtoDump.hpp \
     39        Common/ResolvProtoDump.cpp \
     40        Common/ScopedMap.h \
     41        Common/SemanticError.cc \
     42        Common/SemanticError.h \
     43        Common/Stats.h \
     44        Common/Stats/Base.h \
     45        Common/Stats/Counter.cc \
     46        Common/Stats/Counter.h \
     47        Common/Stats/Heap.cc \
     48        Common/Stats/Heap.h \
     49        Common/Stats/ResolveTime.cc \
     50        Common/Stats/ResolveTime.h \
     51        Common/Stats/Stats.cc \
     52        Common/Stats/Time.cc \
     53        Common/Stats/Time.h \
     54        Common/UnimplementedError.h \
     55        Common/UniqueName.cc \
     56        Common/UniqueName.h \
     57        Common/utility.h \
     58        Common/VectorMap.h
    5859
    59 SRC += $(SRC_COMMON) Common/DebugMalloc.cc
     60SRC += $(SRC_COMMON) \
     61        Common/DebugMalloc.cc
     62
    6063SRCDEMANGLE += $(SRC_COMMON)
  • src/Common/utility.h

    r29d8c02 r74ec742  
    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 11 13:00:36 2020
    13 // Update Count     : 50
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Apr 25 14:26:00 2022
     13// Update Count     : 51
    1414//
    1515
     
    230230}
    231231
     232template<typename Container, typename Pred>
     233void erase_if( Container & cont, Pred && pred ) {
     234        auto keep_end = std::remove_if( cont.begin(), cont.end(), pred );
     235        cont.erase( keep_end, cont.end() );
     236}
     237
    232238template< typename... Args >
    233239auto zip(Args&&... args) -> decltype(zipWith(std::forward<Args>(args)..., std::make_pair)) {
  • src/Concurrency/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Thierry Delisle
    1111## Created On       : Mon Mar 13 12:48:40 2017
    12 ## Last Modified By :
    13 ## Last Modified On :
    14 ## Update Count     : 0
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 13:28:00 2022
     14## Update Count     : 1
    1515###############################################################################
    1616
    17 SRC_CONCURRENCY = \
     17SRC += \
    1818        Concurrency/KeywordsNew.cpp \
    19         Concurrency/Keywords.cc
    20 
    21 SRC += $(SRC_CONCURRENCY) \
     19        Concurrency/Keywords.cc \
    2220        Concurrency/Keywords.h \
    2321        Concurrency/Waitfor.cc \
    2422        Concurrency/Waitfor.h
    25 
    26 SRCDEMANGLE += $(SRC_CONCURRENCY)
    27 
  • src/ControlStruct/LabelGeneratorNew.hpp

    r29d8c02 r74ec742  
    1818#include <string>                                                                               // for string
    1919
    20 class CodeLocation;
     20struct CodeLocation;
    2121
    2222namespace ast {
  • src/ControlStruct/MultiLevelExit.cpp

    r29d8c02 r74ec742  
    1818#include "AST/Pass.hpp"
    1919#include "AST/Stmt.hpp"
     20#include "Common/CodeLocationTools.hpp"
    2021#include "LabelGeneratorNew.hpp"
    2122
     
    228229        // Labels on different stmts require different approaches to access
    229230        switch ( stmt->kind ) {
    230           case BranchStmt::Goto:
     231        case BranchStmt::Goto:
    231232                return stmt;
    232           case BranchStmt::Continue:
    233           case BranchStmt::Break: {
    234                   bool isContinue = stmt->kind == BranchStmt::Continue;
    235                   // Handle unlabeled break and continue.
    236                   if ( stmt->target.empty() ) {
    237                           if ( isContinue ) {
    238                                   targetEntry = findEnclosingControlStructure( isContinueTarget );
    239                           } else {
    240                                   if ( enclosing_control_structures.empty() ) {
     233        case BranchStmt::Continue:
     234        case BranchStmt::Break: {
     235                bool isContinue = stmt->kind == BranchStmt::Continue;
     236                // Handle unlabeled break and continue.
     237                if ( stmt->target.empty() ) {
     238                        if ( isContinue ) {
     239                                targetEntry = findEnclosingControlStructure( isContinueTarget );
     240                        } else {
     241                                if ( enclosing_control_structures.empty() ) {
    241242                                          SemanticError( stmt->location,
    242243                                                                         "'break' outside a loop, 'switch', or labelled block" );
    243                                   }
    244                                   targetEntry = findEnclosingControlStructure( isBreakTarget );
    245                           }
    246                           // Handle labeled break and continue.
    247                   } else {
    248                           // Lookup label in table to find attached control structure.
    249                           targetEntry = findEnclosingControlStructure(
    250                                   [ targetStmt = target_table.at(stmt->target) ](auto entry){
     244                                }
     245                                targetEntry = findEnclosingControlStructure( isBreakTarget );
     246                        }
     247                        // Handle labeled break and continue.
     248                } else {
     249                        // Lookup label in table to find attached control structure.
     250                        targetEntry = findEnclosingControlStructure(
     251                                [ targetStmt = target_table.at(stmt->target) ](auto entry){
    251252                                          return entry.stmt == targetStmt;
    252                                   } );
    253                   }
    254                   // Ensure that selected target is valid.
    255                   if ( targetEntry == enclosing_control_structures.rend() || ( isContinue && ! isContinueTarget( *targetEntry ) ) ) {
    256                           SemanticError( stmt->location, toString( (isContinue ? "'continue'" : "'break'"),
     253                                } );
     254                }
     255                // Ensure that selected target is valid.
     256                if ( targetEntry == enclosing_control_structures.rend() || ( isContinue && ! isContinueTarget( *targetEntry ) ) ) {
     257                        SemanticError( stmt->location, toString( (isContinue ? "'continue'" : "'break'"),
    257258                                                        " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "),
    258259                                                        stmt->originalTarget ) );
    259                   }
    260                   break;
    261           }
    262           // handle fallthrough in case/switch stmts
    263           case BranchStmt::FallThrough: {
    264                   targetEntry = findEnclosingControlStructure( isFallthroughTarget );
    265                   // Check that target is valid.
    266                   if ( targetEntry == enclosing_control_structures.rend() ) {
    267                           SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
    268                   }
    269                   if ( ! stmt->target.empty() ) {
    270                           // Labelled fallthrough: target must be a valid fallthough label.
    271                           if ( ! fallthrough_labels.count( stmt->target ) ) {
    272                                   SemanticError( stmt->location, toString( "'fallthrough' target must be a later case statement: ",
     260                }
     261                break;
     262        }
     263        // handle fallthrough in case/switch stmts
     264        case BranchStmt::FallThrough: {
     265                targetEntry = findEnclosingControlStructure( isFallthroughTarget );
     266                // Check that target is valid.
     267                if ( targetEntry == enclosing_control_structures.rend() ) {
     268                        SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
     269                }
     270                if ( ! stmt->target.empty() ) {
     271                        // Labelled fallthrough: target must be a valid fallthough label.
     272                        if ( ! fallthrough_labels.count( stmt->target ) ) {
     273                                SemanticError( stmt->location, toString( "'fallthrough' target must be a later case statement: ",
    273274                                                                                                                   stmt->originalTarget ) );
    274                           }
    275                           return new BranchStmt( stmt->location, BranchStmt::Goto, stmt->originalTarget );
    276                   }
    277                   break;
    278           }
    279           case BranchStmt::FallThroughDefault: {
    280                   targetEntry = findEnclosingControlStructure( isFallthroughDefaultTarget );
    281 
    282                   // Check if in switch or choose statement.
    283                   if ( targetEntry == enclosing_control_structures.rend() ) {
    284                           SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
    285                   }
    286 
    287                   // Check if switch or choose has default clause.
    288                   auto switchStmt = strict_dynamic_cast< const SwitchStmt * >( targetEntry->stmt );
    289                   bool foundDefault = false;
    290                   for ( auto caseStmt : switchStmt->cases ) {
    291                           if ( caseStmt->isDefault() ) {
    292                                   foundDefault = true;
    293                                   break;
    294                           }
    295                   }
    296                   if ( ! foundDefault ) {
    297                           SemanticError( stmt->location, "'fallthrough default' must be enclosed in a 'switch' or 'choose'"
    298                                                         "control structure with a 'default' clause" );
    299                   }
    300                   break;
    301           }
    302           default:
     275                        }
     276                        return new BranchStmt( stmt->location, BranchStmt::Goto, stmt->originalTarget );
     277                }
     278                break;
     279        }
     280        case BranchStmt::FallThroughDefault: {
     281                targetEntry = findEnclosingControlStructure( isFallthroughDefaultTarget );
     282
     283                // Check if in switch or choose statement.
     284                if ( targetEntry == enclosing_control_structures.rend() ) {
     285                        SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
     286                }
     287
     288                // Check if switch or choose has default clause.
     289                auto switchStmt = strict_dynamic_cast< const SwitchStmt * >( targetEntry->stmt );
     290                bool foundDefault = false;
     291                for ( auto caseStmt : switchStmt->cases ) {
     292                        if ( caseStmt->isDefault() ) {
     293                                foundDefault = true;
     294                                break;
     295                        }
     296                }
     297                if ( ! foundDefault ) {
     298                        SemanticError( stmt->location, "'fallthrough default' must be enclosed in a 'switch' or 'choose'"
     299                                                  "control structure with a 'default' clause" );
     300                }
     301                break;
     302        }
     303        default:
    303304                assert( false );
    304305        }
     
    307308        Label exitLabel( CodeLocation(), "" );
    308309        switch ( stmt->kind ) {
    309           case BranchStmt::Break:
     310        case BranchStmt::Break:
    310311                assert( ! targetEntry->useBreakExit().empty() );
    311312                exitLabel = targetEntry->useBreakExit();
    312313                break;
    313           case BranchStmt::Continue:
     314        case BranchStmt::Continue:
    314315                assert( ! targetEntry->useContExit().empty() );
    315316                exitLabel = targetEntry->useContExit();
    316317                break;
    317           case BranchStmt::FallThrough:
     318        case BranchStmt::FallThrough:
    318319                assert( ! targetEntry->useFallExit().empty() );
    319320                exitLabel = targetEntry->useFallExit();
    320321                break;
    321           case BranchStmt::FallThroughDefault:
     322        case BranchStmt::FallThroughDefault:
    322323                assert( ! targetEntry->useFallDefaultExit().empty() );
    323324                exitLabel = targetEntry->useFallDefaultExit();
     
    327328                }
    328329                break;
    329           default:
     330        default:
    330331                assert(0);
    331332        }
     
    588589                }
    589590
     591                ptr<Stmt> else_stmt = nullptr;
     592                Stmt * loop_kid = nullptr;
     593                // check if loop node and if so add else clause if it exists
     594                const WhileDoStmt * whilePtr = dynamic_cast<const WhileDoStmt *>(kid.get());
     595                if ( whilePtr && whilePtr->else_) {
     596                        else_stmt = whilePtr->else_;
     597                        WhileDoStmt * mutate_ptr = mutate(whilePtr);
     598                        mutate_ptr->else_ = nullptr;
     599                        loop_kid = mutate_ptr;
     600                }
     601                const ForStmt * forPtr = dynamic_cast<const ForStmt *>(kid.get());
     602                if ( forPtr && forPtr->else_) {
     603                        else_stmt = forPtr->else_;
     604                        ForStmt * mutate_ptr = mutate(forPtr);
     605                        mutate_ptr->else_ = nullptr;
     606                        loop_kid = mutate_ptr;
     607                }
     608
    590609                try {
    591                         ret.push_back( kid->accept( *visitor ) );
     610                        if (else_stmt) ret.push_back( loop_kid->accept( *visitor ) );
     611                        else ret.push_back( kid->accept( *visitor ) );
    592612                } catch ( SemanticErrorException & e ) {
    593613                        errors.append( e );
    594614                }
     615
     616                if (else_stmt) ret.push_back(else_stmt);
    595617
    596618                if ( ! break_label.empty() ) {
     
    612634        Pass<MultiLevelExitCore> visitor( labelTable );
    613635        const CompoundStmt * ret = stmt->accept( visitor );
    614         return ret;
     636        // There are some unset code locations slipping in, possibly by Labels.
     637        const Node * node = localFillCodeLocations( ret->location, ret );
     638        return strict_dynamic_cast<const CompoundStmt *>( node );
    615639}
    616640} // namespace ControlStruct
  • src/ControlStruct/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Sat Jan 29 12:04:19 2022
    14 ## Update Count     : 7
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:30:00 2022
     14## Update Count     : 8
    1515###############################################################################
    1616
    17 SRC_CONTROLSTRUCT = \
     17SRC += \
    1818        ControlStruct/ExceptDecl.cc \
    1919        ControlStruct/ExceptDecl.h \
     20        ControlStruct/ExceptTranslateNew.cpp \
     21        ControlStruct/ExceptTranslate.cc \
     22        ControlStruct/ExceptTranslate.h \
    2023        ControlStruct/FixLabels.cpp \
    2124        ControlStruct/FixLabels.hpp \
     
    3740        ControlStruct/Mutate.h
    3841
    39 SRC += $(SRC_CONTROLSTRUCT) \
    40         ControlStruct/ExceptTranslateNew.cpp \
    41         ControlStruct/ExceptTranslate.cc \
    42         ControlStruct/ExceptTranslate.h
    43 
    44 SRCDEMANGLE += $(SRC_CONTROLSTRUCT)
    45 
  • src/GenPoly/Lvalue.cc

    r29d8c02 r74ec742  
    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 Dec 13 23:14:38 2019
    13 // Update Count     : 7
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon May 16 14:09:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    125125        } // namespace
    126126
    127         static bool referencesEliminated = false;
    128         // used by UntypedExpr::createDeref to determine whether result type of dereference should be ReferenceType or value type.
    129         bool referencesPermissable() {
    130                 return ! referencesEliminated;
    131         }
     127        // Stored elsewhere (Lvalue2, initially false).
     128        extern bool referencesEliminated;
    132129
    133130        void convertLvalue( std::list< Declaration* > & translationUnit ) {
  • src/GenPoly/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Mon Jun  1 17:52:30 2015
    14 ## Update Count     : 1
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:31:00 2022
     14## Update Count     : 2
    1515###############################################################################
    1616
    17 SRC += GenPoly/Box.cc \
    18        GenPoly/Box.h \
    19        GenPoly/ErasableScopedMap.h \
    20        GenPoly/FindFunction.cc \
    21        GenPoly/FindFunction.h \
    22        GenPoly/GenPoly.cc \
    23        GenPoly/GenPoly.h \
    24        GenPoly/InstantiateGeneric.cc \
    25        GenPoly/InstantiateGeneric.h \
    26        GenPoly/Lvalue.cc \
    27        GenPoly/Lvalue.h \
    28        GenPoly/ScopedSet.h \
    29        GenPoly/ScrubTyVars.cc \
    30        GenPoly/ScrubTyVars.h \
    31        GenPoly/Specialize.cc \
    32        GenPoly/Specialize.h
     17SRC_GENPOLY = \
     18        GenPoly/GenPoly.cc \
     19        GenPoly/GenPoly.h \
     20        GenPoly/Lvalue2.cc \
     21        GenPoly/Lvalue.h
    3322
    34 SRCDEMANGLE += GenPoly/GenPoly.cc GenPoly/GenPoly.h GenPoly/Lvalue.cc GenPoly/Lvalue.h
     23SRC += $(SRC_GENPOLY) \
     24        GenPoly/Box.cc \
     25        GenPoly/Box.h \
     26        GenPoly/ErasableScopedMap.h \
     27        GenPoly/FindFunction.cc \
     28        GenPoly/FindFunction.h \
     29        GenPoly/InstantiateGeneric.cc \
     30        GenPoly/InstantiateGeneric.h \
     31        GenPoly/Lvalue.cc \
     32        GenPoly/ScopedSet.h \
     33        GenPoly/ScrubTyVars.cc \
     34        GenPoly/ScrubTyVars.h \
     35        GenPoly/Specialize.cc \
     36        GenPoly/Specialize.h
    3537
     38SRCDEMANGLE += $(SRC_GENPOLY)
  • src/InitTweak/FixInitNew.cpp

    r29d8c02 r74ec742  
    454454
    455455                auto expr = new ast::ImplicitCopyCtorExpr( appExpr->location, mutExpr );
    456                 // Move the type substitution to the new top-level, if it is attached to the appExpr.
    457                 // Ensure it is not deleted with the ImplicitCopyCtorExpr by removing it before deletion.
    458                 // The substitution is needed to obtain the type of temporary variables so that copy constructor
    459                 // calls can be resolved.
     456                // Move the type substitution to the new top-level. The substitution
     457                // is needed to obtain the type of temporary variables so that copy
     458                // constructor calls can be resolved.
    460459                assert( typeSubs );
    461                 // assert (mutExpr->env);
    462460                expr->env = tmp;
    463                 // mutExpr->env = nullptr;
    464                 //std::swap( expr->env, appExpr->env );
    465461                return expr;
    466462        }
    467463
    468464        void ResolveCopyCtors::previsit(const ast::Expr * expr) {
    469                 if (expr->env) {
    470                         GuardValue(env);
    471                         GuardValue(envModified);
    472                         env = expr->env->clone();
    473                         envModified = false;
    474                 }
     465                if ( nullptr == expr->env ) {
     466                        return;
     467                }
     468                GuardValue( env ) = expr->env->clone();
     469                GuardValue( envModified ) = false;
    475470        }
    476471
    477472        const ast::Expr * ResolveCopyCtors::postvisit(const ast::Expr * expr) {
    478                 if (expr->env) {
    479                         if (envModified) {
    480                                 auto mutExpr = mutate(expr);
    481                                 mutExpr->env = env;
    482                                 return mutExpr;
    483                         }
    484                         else {
    485                                 // env was not mutated, skip and delete the shallow copy
    486                                 delete env;
    487                                 return expr;
    488                         }
    489                 }
    490                 else {
     473                // No local environment, skip.
     474                if ( nullptr == expr->env ) {
     475                        return expr;
     476                // Environment was modified, mutate and replace.
     477                } else if ( envModified ) {
     478                        auto mutExpr = mutate(expr);
     479                        mutExpr->env = env;
     480                        return mutExpr;
     481                // Environment was not mutated, delete the shallow copy before guard.
     482                } else {
     483                        delete env;
    491484                        return expr;
    492485                }
     
    497490        const ast::Expr * ResolveCopyCtors::makeCtorDtor( const std::string & fname, const ast::ObjectDecl * var, const ast::Expr * cpArg ) {
    498491                assert( var );
    499                 assert (var->isManaged());
    500                 assert (!cpArg || cpArg->isManaged());
     492                assert( var->isManaged() );
     493                assert( !cpArg || cpArg->isManaged() );
    501494                // arrays are not copy constructed, so this should always be an ExprStmt
    502495                ast::ptr< ast::Stmt > stmt = genCtorDtor(var->location, fname, var, cpArg );
     
    504497                auto exprStmt = stmt.strict_as<ast::ImplicitCtorDtorStmt>()->callStmt.strict_as<ast::ExprStmt>();
    505498                ast::ptr<ast::Expr> untyped = exprStmt->expr; // take ownership of expr
    506                 // exprStmt->expr = nullptr;
    507499
    508500                // resolve copy constructor
     
    516508                        env->add( *resolved->env );
    517509                        envModified = true;
    518                         // delete resolved->env;
    519510                        auto mut = mutate(resolved.get());
    520511                        assertf(mut == resolved.get(), "newly resolved expression must be unique");
    521512                        mut->env = nullptr;
    522513                } // if
    523                 // delete stmt;
    524514                if ( auto assign = resolved.as<ast::TupleAssignExpr>() ) {
    525515                        // fix newly generated StmtExpr
  • src/InitTweak/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Rob Schluntz
    13 ## Last Modified On : Fri May 13 11:36:24 2016
    14 ## Update Count     : 3
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:31:00 2022
     14## Update Count     : 4
    1515###############################################################################
    1616
    17 SRC += \
    18         InitTweak/FixGlobalInit.cc \
    19         InitTweak/FixGlobalInit.h \
    20         InitTweak/FixInit.cc \
    21         InitTweak/FixInit.h \
    22         InitTweak/GenInit.cc \
    23         InitTweak/GenInit.h \
    24         InitTweak/InitTweak.cc \
    25         InitTweak/InitTweak.h \
    26         InitTweak/FixInitNew.cpp
    27 
    28 SRCDEMANGLE += \
     17SRC_INITTWEAK = \
    2918        InitTweak/GenInit.cc \
    3019        InitTweak/GenInit.h \
     
    3221        InitTweak/InitTweak.h
    3322
     23SRC += $(SRC_INITTWEAK) \
     24        InitTweak/FixGlobalInit.cc \
     25        InitTweak/FixGlobalInit.h \
     26        InitTweak/FixInit.cc \
     27        InitTweak/FixInit.h \
     28        InitTweak/FixInitNew.cpp
     29
     30SRCDEMANGLE += $(SRC_INITTWEAK)
  • src/Parser/DeclarationNode.cc

    r29d8c02 r74ec742  
    253253} // DeclarationNode::newAggregate
    254254
    255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body) {
     255DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {
    256256        DeclarationNode * newnode = new DeclarationNode;
    257257        newnode->type = new TypeData( TypeData::Enum );
     
    260260        newnode->type->enumeration.body = body;
    261261        newnode->type->enumeration.anon = name == nullptr;
     262        if ( base && base->type)  {
     263                newnode->type->base = base->type;       
     264        } // if
     265
     266        // Check: if base has TypeData
    262267        return newnode;
    263268} // DeclarationNode::newEnum
     
    290295                return newName( name ); // Not explicitly inited enum value;
    291296        } // if
    292 } // DeclarationNode::newEnumGeneric
     297} // DeclarationNode::newEnumValueGeneric
    293298
    294299DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
  • src/Parser/ParseNode.h

    r29d8c02 r74ec742  
    235235        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    236236        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    237         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
     237        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, DeclarationNode * base = nullptr );
    238238        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    239239        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
  • src/Parser/TypeData.cc

    r29d8c02 r74ec742  
    388388                if ( enumeration.body ) {
    389389                        os << string( indent + 2, ' ' ) << " with body" << endl;
     390                } // if
     391                if ( base ) {
     392                        os << "for ";
     393                        base->print( os, indent + 2 );
    390394                } // if
    391395                break;
     
    926930                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    927931                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
    928                 } else {
     932                } else if ( !cur->initializer ) {
    929933                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) {
    930934                                SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." );
    931935                        }
    932                 } // if
     936                }
     937                // else cur is a List Initializer and has been set as init in buildList()
     938                // if
    933939        } // for
    934         ret->set_body( td->enumeration.body ); // Boolean; if it has body
     940        ret->set_body( td->enumeration.body );
    935941        return ret;
    936942} // buildEnum
  • src/Parser/parser.yy

    r29d8c02 r74ec742  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 14 16:35:29 2022
    13 // Update Count     : 5276
     12// Last Modified On : Sat May 14 09:16:22 2022
     13// Update Count     : 5401
    1414//
    1515
     
    5454#include "Common/SemanticError.h"                                               // error_str
    5555#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     56
     57#include "SynTree/Attribute.h"     // for Attribute
    5658
    5759extern DeclarationNode * parseTree;
     
    9395} // appendStr
    9496
    95 DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) {
    96         // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
    97         DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
     97DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
     98        // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
     99        assert( declList );
     100//      printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
     101        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec );
     102//      printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
     103//      cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
     104
    98105        for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    99106                cl->cloneBaseType( cur );
    100107        } // for
    101108        declList->addType( cl );
     109//      printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
    102110        return declList;
    103111} // distAttr
     
    111119
    112120void distInl( DeclarationNode * declaration ) {
    113         // distribute EXTENSION across all declarations
     121        // distribute INLINE across all declarations
    114122        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    115123                iter->set_inLine( true );
     
    171179                if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) {
    172180                        stringstream ss;
    173                         typeSpec->type->print( ss );
     181                        // printf( "fieldDecl1 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
    174182                        SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
    175183                        return nullptr;
    176184                } // if
     185                // printf( "fieldDecl2 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
    177186                fieldList = DeclarationNode::newName( nullptr );
    178187        } // if
    179         return distAttr( typeSpec, fieldList );                         // mark all fields in list
     188//      return distAttr( typeSpec, fieldList );                         // mark all fields in list
     189
     190        // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
     191        DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
     192        // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
     193        return temp;
    180194} // fieldDecl
    181195
     
    12211235
    12221236iteration_statement:
    1223         WHILE '(' ')' statement                                                         // CFA => while ( 1 )
     1237        WHILE '(' ')' statement                                                         %prec THEN // CFA => while ( 1 )
    12241238                { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
     1239        | WHILE '(' ')' statement ELSE statement                        // CFA
     1240                {
     1241                        $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) );
     1242                        SemanticWarning( yylloc, Warning::SuperfluousElse );
     1243                }
    12251244        | WHILE '(' conditional_declaration ')' statement       %prec THEN
    12261245                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
     
    12291248        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    12301249                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
    1231         | DO statement WHILE '(' comma_expression ')' ';'       %prec THEN
     1250        | DO statement WHILE '(' ')' ELSE statement                     // CFA
     1251                {
     1252                        $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) );
     1253                        SemanticWarning( yylloc, Warning::SuperfluousElse );
     1254                }
     1255        | DO statement WHILE '(' comma_expression ')' ';'
    12321256                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
    12331257        | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
    12341258                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); }
    1235         | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     1259        | FOR '(' ')' statement                                                         %prec THEN // CFA => for ( ;; )
    12361260                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
     1261        | FOR '(' ')' statement ELSE statement                          // CFA
     1262                {
     1263                        $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) );
     1264                        SemanticWarning( yylloc, Warning::SuperfluousElse );
     1265                }
    12371266        | FOR '(' for_control_expression_list ')' statement     %prec THEN
    12381267                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
     
    16051634declaration:                                                                                    // old & new style declarations
    16061635        c_declaration ';'
     1636                {
     1637                        // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
     1638                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1639                        //   printf( "\tattr %s\n", attr->name.c_str() );
     1640                        // } // for
     1641                }
    16071642        | cfa_declaration ';'                                                           // CFA
    16081643        | static_assert                                                                         // C11
     
    18101845        basic_type_specifier
    18111846        | sue_type_specifier
     1847                {
     1848                        // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     1849                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1850                        //   printf( "\tattr %s\n", attr->name.c_str() );
     1851                        // } // for
     1852                }
    18121853        | type_type_specifier
    18131854        ;
     
    20262067sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
    20272068        sue_type_specifier
     2069                {
     2070                        // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2071                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2072                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2073                        // } // for
     2074                }
    20282075        | declaration_qualifier_list sue_type_specifier
    20292076                { $$ = $2->addQualifiers( $1 ); }
     
    20362083sue_type_specifier:                                                                             // struct, union, enum + type specifier
    20372084        elaborated_type
     2085                {
     2086                        // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2087                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2088                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2089                        // } // for
     2090                }
    20382091        | type_qualifier_list
    20392092                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     
    21082161elaborated_type:                                                                                // struct, union, enum
    21092162        aggregate_type
     2163                {
     2164                        // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2165                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2166                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2167                        // } // for
     2168                }
    21102169        | enum_type
    21112170        ;
     
    21272186                }
    21282187          '{' field_declaration_list_opt '}' type_parameters_opt
    2129                 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); }
     2188                {
     2189                        // printf( "aggregate_type1 %s\n", $3.str->c_str() );
     2190                        // if ( $2 )
     2191                        //      for ( Attribute * attr: reverseIterate( $2->attributes ) ) {
     2192                        //              printf( "copySpecifiers12 %s\n", attr->name.c_str() );
     2193                        //      } // for
     2194                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     2195                        // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2196                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2197                        //      printf( "aggregate_type3 %s\n", attr->name.c_str() );
     2198                        // } // for
     2199                }
    21302200        | aggregate_key attribute_list_opt TYPEDEFname          // unqualified type name
    21312201                {
     
    21352205          '{' field_declaration_list_opt '}' type_parameters_opt
    21362206                {
     2207                        // printf( "AGG3\n" );
    21372208                        DeclarationNode::newFromTypedef( $3 );
    21382209                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    21452216          '{' field_declaration_list_opt '}' type_parameters_opt
    21462217                {
     2218                        // printf( "AGG4\n" );
    21472219                        DeclarationNode::newFromTypeGen( $3, nullptr );
    21482220                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    22212293field_declaration:
    22222294        type_specifier field_declaring_list_opt ';'
    2223                 { $$ = fieldDecl( $1, $2 ); }
     2295                {
     2296                        // printf( "type_specifier1 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2297                        $$ = fieldDecl( $1, $2 );
     2298                        // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2299                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2300                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2301                        // } // for
     2302                }
    22242303        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    22252304                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     
    23032382        ;
    23042383
    2305 enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );                                                                                         // enum
     2384enum_type:
    23062385        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    23072386                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     
    23182397                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23192398
    2320                         $$ = DeclarationNode::newEnum( nullptr, $7, true ) ->addQualifiers( $5 )  -> addEnumBase( $3 );
    2321                 }
    2322         | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
     2399                        $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 );
     2400                }
     2401        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    23232402                {
    23242403                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    23272406          '{' enumerator_list comma_opt '}'
    23282407                {
    2329                         $$ = DeclarationNode::newEnum( $6, $10, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2408                        $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    23302409                }
    23312410        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23332412                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23342413                        typedefTable.makeTypedef( *$6->name );
    2335                         $$ = DeclarationNode::newEnum( $6->name, $9, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2414                        $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    23362415                }
    23372416        | enum_type_nobody
     
    28302909        // empty
    28312910                { $$ = nullptr; forall = false; }
    2832         | WITH '(' tuple_expression_list ')'
    2833                 { $$ = $3; forall = false; }
     2911        | WITH '(' tuple_expression_list ')' attribute_list_opt
     2912                {
     2913                        $$ = $3; forall = false;
     2914                        if ( $5 ) {
     2915                                SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
     2916                                $$ = nullptr;
     2917                        } // if
     2918                }
    28342919        ;
    28352920
  • src/ResolvExpr/AlternativeFinder.cc

    r29d8c02 r74ec742  
    4242#include "SymTab/Indexer.h"        // for Indexer
    4343#include "SymTab/Mangler.h"        // for Mangler
    44 #include "SymTab/Validate.h"       // for validateType
     44#include "SymTab/ValidateType.h"   // for validateType
    4545#include "SynTree/Constant.h"      // for Constant
    4646#include "SynTree/Declaration.h"   // for DeclarationWithType, TypeDecl, Dec...
  • src/ResolvExpr/Resolver.cc

    r29d8c02 r74ec742  
    427427                        // enumerator initializers should not use the enum type to initialize, since
    428428                        // the enum type is still incomplete at this point. Use signed int instead.
     429                        // TODO: BasicType::SignedInt may not longer be true
    429430                        currentObject = CurrentObject( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    430431                }
     
    14771478                        // enum type is still incomplete at this point. Use `int` instead.
    14781479
    1479                         if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { // const ast::PointerType &
    1480                                 // const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
    1481                                 // const ast::PointerType * enumBaseAsPtr = dynamic_cast<const ast::PointerType *>(enumBase);
    1482 
    1483                                 // if ( enumBaseAsPtr ) {
    1484                                 //      const ast::Type * pointerBase = enumBaseAsPtr->base.get();
    1485                                 //      if ( dynamic_cast<const ast::BasicType *>(pointerBase) ) {
    1486                                 //              objectDecl = fixObjectType(objectDecl, context);
    1487                                 //              if (dynamic_cast<const ast::BasicType *>(pointerBase)->kind == ast::BasicType::Char)
    1488                                 //              currentObject = ast::CurrentObject{
    1489                                 //                      objectDecl->location,  new ast::PointerType{
    1490                                 //                              new ast::BasicType{ ast::BasicType::Char }
    1491                                 //                      } };
    1492                                 //      } else {
    1493                                 //              objectDecl = fixObjectType(objectDecl, context);
    1494                                 //              currentObject = ast::CurrentObject{objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
    1495                                 //      }
    1496                                 // }
     1480                        if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) {
    14971481                                objectDecl = fixObjectType( objectDecl, context );
    14981482                                const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
  • src/SymTab/Autogen.h

    r29d8c02 r74ec742  
    2121
    2222#include "AST/Decl.hpp"
    23 #include "AST/Eval.hpp"
    2423#include "AST/Expr.hpp"
    2524#include "AST/Init.hpp"
     
    7170        template< typename OutIter >
    7271        ast::ptr< ast::Stmt > genCall(
    73                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    74                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
     72                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     73                const CodeLocation & loc, const std::string & fname, OutIter && out,
    7574                const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
    7675
     
    128127        }
    129128
    130         /// inserts into out a generated call expression to function fname with arguments dstParam and 
     129        /// inserts into out a generated call expression to function fname with arguments dstParam and
    131130        /// srcParam. Should only be called with non-array types.
    132         /// optionally returns a statement which must be inserted prior to the containing loop, if 
     131        /// optionally returns a statement which must be inserted prior to the containing loop, if
    133132        /// there is one
    134133        template< typename OutIter >
    135         ast::ptr< ast::Stmt > genScalarCall( 
    136                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    137                 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 
     134        ast::ptr< ast::Stmt > genScalarCall(
     135                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     136                const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type,
    138137                const ast::Type * addCast = nullptr
    139138        ) {
     
    153152
    154153                if ( addCast ) {
    155                         // cast to T& with qualifiers removed, so that qualified objects can be constructed and 
    156                         // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 
    157                         // is considered a qualifier - for AddressExpr to resolve, its argument must have an 
     154                        // cast to T& with qualifiers removed, so that qualified objects can be constructed and
     155                        // destructed with the same functions as non-qualified objects. Unfortunately, lvalue
     156                        // is considered a qualifier - for AddressExpr to resolve, its argument must have an
    158157                        // lvalue-qualified type, so remove all qualifiers except lvalue.
    159158                        // xxx -- old code actually removed lvalue too...
    160159                        ast::ptr< ast::Type > guard = addCast;  // prevent castType from mutating addCast
    161160                        ast::ptr< ast::Type > castType = addCast;
    162                         ast::remove_qualifiers( 
    163                                 castType, 
     161                        ast::remove_qualifiers(
     162                                castType,
    164163                                ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic );
    165164                        dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } };
     
    181180
    182181                srcParam.clearArrayIndices();
    183                
     182
    184183                return listInit;
    185184        }
     
    249248        }
    250249
    251         /// Store in out a loop which calls fname on each element of the array with srcParam and 
     250        /// Store in out a loop which calls fname on each element of the array with srcParam and
    252251        /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0
    253252        template< typename OutIter >
    254253        void genArrayCall(
    255                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    256                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
    257                 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 
    258                 LoopDirection forward = LoopForward 
     254                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     255                const CodeLocation & loc, const std::string & fname, OutIter && out,
     256                const ast::ArrayType * array, const ast::Type * addCast = nullptr,
     257                LoopDirection forward = LoopForward
    259258        ) {
    260259                static UniqueName indexName( "_index" );
     
    279278                } else {
    280279                        // generate: for ( int i = N-1; i >= 0; --i )
    281                         begin = ast::call(
    282                                 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ) );
     280                        begin = ast::UntypedExpr::createCall( loc, "?-?",
     281                                { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } );
    283282                        end = ast::ConstantExpr::from_int( loc, 0 );
    284283                        cmp = "?>=?";
     
    286285                }
    287286
    288                 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 
    289                         loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 
     287                ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{
     288                        loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt },
    290289                        new ast::SingleInit{ loc, begin } };
    291290                ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index };
    292                
    293                 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end );
    294                
    295                 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar );
    296                
    297                 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar );
    298                
    299                 // srcParam must keep track of the array indices to build the source parameter and/or
     291
     292                ast::ptr< ast::Expr > cond = ast::UntypedExpr::createCall(
     293                        loc, cmp, { indexVar, end } );
     294
     295                ast::ptr< ast::Expr > inc = ast::UntypedExpr::createCall(
     296                        loc, update, { indexVar } );
     297
     298                ast::ptr< ast::Expr > dstIndex = ast::UntypedExpr::createCall(
     299                        loc, "?[?]", { dstParam, indexVar } );
     300
     301                // srcParam must keep track of the array indices to build the source parameter and/or
    300302                // array list initializer
    301303                srcParam.addArrayIndex( indexVar, array->dimension );
     
    303305                // for stmt's body, eventually containing call
    304306                ast::CompoundStmt * body = new ast::CompoundStmt{ loc };
    305                 ast::ptr< ast::Stmt > listInit = genCall( 
    306                         srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 
     307                ast::ptr< ast::Stmt > listInit = genCall(
     308                        srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast,
    307309                        forward );
    308                
     310
    309311                // block containing the stmt and index variable
    310312                ast::CompoundStmt * block = new ast::CompoundStmt{ loc };
     
    328330        template< typename OutIter >
    329331        ast::ptr< ast::Stmt > genCall(
    330                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    331                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
     332                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     333                const CodeLocation & loc, const std::string & fname, OutIter && out,
    332334                const ast::Type * type, const ast::Type * addCast, LoopDirection forward
    333335        ) {
    334336                if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    335                         genArrayCall( 
    336                                 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 
     337                        genArrayCall(
     338                                srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
    337339                                forward );
    338340                        return {};
    339341                } else {
    340                         return genScalarCall( 
     342                        return genScalarCall(
    341343                                srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
    342344                }
     
    377379        }
    378380
    379         static inline ast::ptr< ast::Stmt > genImplicitCall( 
    380                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    381                 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 
    382                 LoopDirection forward = LoopForward 
     381        static inline ast::ptr< ast::Stmt > genImplicitCall(
     382                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     383                const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
     384                LoopDirection forward = LoopForward
    383385        ) {
    384386                // unnamed bit fields are not copied as they cannot be accessed
     
    392394
    393395                std::vector< ast::ptr< ast::Stmt > > stmts;
    394                 genCall( 
     396                genCall(
    395397                        srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
    396398
     
    400402                        const ast::Stmt * callStmt = stmts.front();
    401403                        if ( addCast ) {
    402                                 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 
     404                                // implicitly generated ctor/dtor calls should be wrapped so that later passes are
    403405                                // aware they were generated.
    404406                                callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt };
     
    417419// compile-command: "make install" //
    418420// End: //
    419 
  • src/SymTab/Demangle.cc

    r29d8c02 r74ec742  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Demangler.cc --
     7// Demangle.cc -- Convert a mangled name into a human readable name.
    88//
    99// Author           : Rob Schluntz
  • src/SymTab/Mangler.h

    r29d8c02 r74ec742  
    111111}
    112112
    113 extern "C" {
    114         char * cforall_demangle(const char *, int);
    115 }
    116 
    117113// Local Variables: //
    118114// tab-width: 4 //
  • src/SymTab/Validate.cc

    r29d8c02 r74ec742  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Nov 12 11:00:00 2021
    13 // Update Count     : 364
     12// Last Modified On : Tue May 17 14:36:00 2022
     13// Update Count     : 366
    1414//
    1515
     
    7474#include "ResolvExpr/ResolveTypeof.h"  // for resolveTypeof
    7575#include "SymTab/Autogen.h"            // for SizeType
     76#include "SymTab/ValidateType.h"       // for decayEnumsAndPointers, decayFo...
    7677#include "SynTree/LinkageSpec.h"       // for C
    7778#include "SynTree/Attribute.h"         // for noAttributes, Attribute
     
    134135        };
    135136
    136         /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    137         struct EnumAndPointerDecay_old {
    138                 void previsit( EnumDecl * aggregateDecl );
    139                 void previsit( FunctionType * func );
    140         };
    141 
    142         /// Associates forward declarations of aggregates with their definitions
    143         struct LinkReferenceToTypes_old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {
    144                 LinkReferenceToTypes_old( const Indexer * indexer );
    145                 void postvisit( TypeInstType * typeInst );
    146 
    147                 void postvisit( EnumInstType * enumInst );
    148                 void postvisit( StructInstType * structInst );
    149                 void postvisit( UnionInstType * unionInst );
    150                 void postvisit( TraitInstType * traitInst );
    151                 void previsit( QualifiedType * qualType );
    152                 void postvisit( QualifiedType * qualType );
    153 
    154                 void postvisit( EnumDecl * enumDecl );
    155                 void postvisit( StructDecl * structDecl );
    156                 void postvisit( UnionDecl * unionDecl );
    157                 void postvisit( TraitDecl * traitDecl );
    158 
    159                 void previsit( StructDecl * structDecl );
    160                 void previsit( UnionDecl * unionDecl );
    161 
    162                 void renameGenericParams( std::list< TypeDecl * > & params );
    163 
    164           private:
    165                 const Indexer * local_indexer;
    166 
    167                 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
    168                 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
    169                 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
    170                 ForwardEnumsType forwardEnums;
    171                 ForwardStructsType forwardStructs;
    172                 ForwardUnionsType forwardUnions;
    173                 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately
    174                 bool inGeneric = false;
    175         };
    176 
    177137        /// Does early resolution on the expressions that give enumeration constants their values
    178138        struct ResolveEnumInitializers final : public WithIndexer, public WithGuards, public WithVisitorRef<ResolveEnumInitializers>, public WithShortCircuiting {
     
    192152                void previsit( StructDecl * aggrDecl );
    193153                void previsit( UnionDecl * aggrDecl );
    194         };
    195 
    196         // These structs are the sub-sub-passes of ForallPointerDecay_old.
    197 
    198         struct TraitExpander_old final {
    199                 void previsit( FunctionType * );
    200                 void previsit( StructDecl * );
    201                 void previsit( UnionDecl * );
    202         };
    203 
    204         struct AssertionFixer_old final {
    205                 void previsit( FunctionType * );
    206                 void previsit( StructDecl * );
    207                 void previsit( UnionDecl * );
    208         };
    209 
    210         struct CheckOperatorTypes_old final {
    211                 void previsit( ObjectDecl * );
    212         };
    213 
    214         struct FixUniqueIds_old final {
    215                 void previsit( DeclarationWithType * );
    216154        };
    217155
     
    357295
    358296        void validate_A( std::list< Declaration * > & translationUnit ) {
    359                 PassVisitor<EnumAndPointerDecay_old> epc;
    360297                PassVisitor<HoistTypeDecls> hoistDecls;
    361298                {
     
    366303                        ReplaceTypedef::replaceTypedef( translationUnit );
    367304                        ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
    368                         acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling
     305                        decayEnumsAndPointers( translationUnit ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling
    369306                }
    370307        }
    371308
    372309        void validate_B( std::list< Declaration * > & translationUnit ) {
    373                 PassVisitor<LinkReferenceToTypes_old> lrt( nullptr );
    374310                PassVisitor<FixQualifiedTypes> fixQual;
    375311                {
    376312                        Stats::Heap::newPass("validate-B");
    377313                        Stats::Time::BlockGuard guard("validate-B");
    378                         acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
     314                        //linkReferenceToTypes( translationUnit );
    379315                        mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed
    380316                        HoistStruct::hoistStruct( translationUnit );
     
    407343                        });
    408344                }
    409         }
    410 
    411         static void decayForallPointers( std::list< Declaration * > & translationUnit ) {
    412                 PassVisitor<TraitExpander_old> te;
    413                 acceptAll( translationUnit, te );
    414                 PassVisitor<AssertionFixer_old> af;
    415                 acceptAll( translationUnit, af );
    416                 PassVisitor<CheckOperatorTypes_old> cot;
    417                 acceptAll( translationUnit, cot );
    418                 PassVisitor<FixUniqueIds_old> fui;
    419                 acceptAll( translationUnit, fui );
    420345        }
    421346
     
    496421        }
    497422
    498         void validateType( Type * type, const Indexer * indexer ) {
    499                 PassVisitor<EnumAndPointerDecay_old> epc;
    500                 PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
    501                 PassVisitor<TraitExpander_old> te;
    502                 PassVisitor<AssertionFixer_old> af;
    503                 PassVisitor<CheckOperatorTypes_old> cot;
    504                 PassVisitor<FixUniqueIds_old> fui;
    505                 type->accept( epc );
    506                 type->accept( lrt );
    507                 type->accept( te );
    508                 type->accept( af );
    509                 type->accept( cot );
    510                 type->accept( fui );
    511         }
    512 
    513423        void HoistTypeDecls::handleType( Type * type ) {
    514424                // some type declarations are buried in expressions and not easy to hoist during parsing; hoist them here
     
    703613        }
    704614
    705         void EnumAndPointerDecay_old::previsit( EnumDecl * enumDecl ) {
    706                 // Set the type of each member of the enumeration to be EnumConstant
    707                 for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) {
    708                         ObjectDecl * obj = dynamic_cast< ObjectDecl * >( * i );
    709                         assert( obj );
    710                         obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->name ) );
    711                 } // for
    712         }
    713 
    714         namespace {
    715                 template< typename DWTList >
    716                 void fixFunctionList( DWTList & dwts, bool isVarArgs, FunctionType * func ) {
    717                         auto nvals = dwts.size();
    718                         bool containsVoid = false;
    719                         for ( auto & dwt : dwts ) {
    720                                 // fix each DWT and record whether a void was found
    721                                 containsVoid |= fixFunction( dwt );
    722                         }
    723 
    724                         // the only case in which "void" is valid is where it is the only one in the list
    725                         if ( containsVoid && ( nvals > 1 || isVarArgs ) ) {
    726                                 SemanticError( func, "invalid type void in function type " );
    727                         }
    728 
    729                         // one void is the only thing in the list; remove it.
    730                         if ( containsVoid ) {
    731                                 delete dwts.front();
    732                                 dwts.clear();
    733                         }
    734                 }
    735         }
    736 
    737         void EnumAndPointerDecay_old::previsit( FunctionType * func ) {
    738                 // Fix up parameters and return types
    739                 fixFunctionList( func->parameters, func->isVarArgs, func );
    740                 fixFunctionList( func->returnVals, false, func );
    741         }
    742 
    743         LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) : WithIndexer( false ) {
    744                 if ( other_indexer ) {
    745                         local_indexer = other_indexer;
    746                 } else {
    747                         local_indexer = &indexer;
    748                 } // if
    749         }
    750 
    751         void LinkReferenceToTypes_old::postvisit( EnumInstType * enumInst ) {
    752                 const EnumDecl * st = local_indexer->lookupEnum( enumInst->name );
    753                 // it's not a semantic error if the enum is not found, just an implicit forward declaration
    754                 if ( st ) {
    755                         enumInst->baseEnum = const_cast<EnumDecl *>(st); // Just linking in the node
    756                 } // if
    757                 if ( ! st || ! st->body ) {
    758                         // use of forward declaration
    759                         forwardEnums[ enumInst->name ].push_back( enumInst );
    760                 } // if
    761         }
    762 
    763         void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {
    764                 const StructDecl * st = local_indexer->lookupStruct( structInst->name );
    765                 // it's not a semantic error if the struct is not found, just an implicit forward declaration
    766                 if ( st ) {
    767                         structInst->baseStruct = const_cast<StructDecl *>(st); // Just linking in the node
    768                 } // if
    769                 if ( ! st || ! st->body ) {
    770                         // use of forward declaration
    771                         forwardStructs[ structInst->name ].push_back( structInst );
    772                 } // if
    773         }
    774 
    775         void LinkReferenceToTypes_old::postvisit( UnionInstType * unionInst ) {
    776                 const UnionDecl * un = local_indexer->lookupUnion( unionInst->name );
    777                 // it's not a semantic error if the union is not found, just an implicit forward declaration
    778                 if ( un ) {
    779                         unionInst->baseUnion = const_cast<UnionDecl *>(un); // Just linking in the node
    780                 } // if
    781                 if ( ! un || ! un->body ) {
    782                         // use of forward declaration
    783                         forwardUnions[ unionInst->name ].push_back( unionInst );
    784                 } // if
    785         }
    786 
    787         void LinkReferenceToTypes_old::previsit( QualifiedType * ) {
    788                 visit_children = false;
    789         }
    790 
    791         void LinkReferenceToTypes_old::postvisit( QualifiedType * qualType ) {
    792                 // linking only makes sense for the 'oldest ancestor' of the qualified type
    793                 qualType->parent->accept( * visitor );
    794         }
    795 
    796         template< typename Decl >
    797         void normalizeAssertions( std::list< Decl * > & assertions ) {
    798                 // ensure no duplicate trait members after the clone
    799                 auto pred = [](Decl * d1, Decl * d2) {
    800                         // only care if they're equal
    801                         DeclarationWithType * dwt1 = dynamic_cast<DeclarationWithType *>( d1 );
    802                         DeclarationWithType * dwt2 = dynamic_cast<DeclarationWithType *>( d2 );
    803                         if ( dwt1 && dwt2 ) {
    804                                 if ( dwt1->name == dwt2->name && ResolvExpr::typesCompatible( dwt1->get_type(), dwt2->get_type(), SymTab::Indexer() ) ) {
    805                                         // std::cerr << "=========== equal:" << std::endl;
    806                                         // std::cerr << "d1: " << d1 << std::endl;
    807                                         // std::cerr << "d2: " << d2 << std::endl;
    808                                         return false;
    809                                 }
    810                         }
    811                         return d1 < d2;
    812                 };
    813                 std::set<Decl *, decltype(pred)> unique_members( assertions.begin(), assertions.end(), pred );
    814                 // if ( unique_members.size() != assertions.size() ) {
    815                 //      std::cerr << "============different" << std::endl;
    816                 //      std::cerr << unique_members.size() << " " << assertions.size() << std::endl;
    817                 // }
    818 
    819                 std::list< Decl * > order;
    820                 order.splice( order.end(), assertions );
    821                 std::copy_if( order.begin(), order.end(), back_inserter( assertions ), [&]( Decl * decl ) {
    822                         return unique_members.count( decl );
    823                 });
    824         }
    825 
    826615        // expand assertions from trait instance, performing the appropriate type variable substitutions
    827616        template< typename Iterator >
     
    834623                // substitute trait decl parameters for instance parameters
    835624                applySubstitution( inst->baseTrait->parameters.begin(), inst->baseTrait->parameters.end(), inst->parameters.begin(), asserts.begin(), asserts.end(), out );
    836         }
    837 
    838         void LinkReferenceToTypes_old::postvisit( TraitDecl * traitDecl ) {
    839                 if ( traitDecl->name == "sized" ) {
    840                         // "sized" is a special trait - flick the sized status on for the type variable
    841                         assertf( traitDecl->parameters.size() == 1, "Built-in trait 'sized' has incorrect number of parameters: %zd", traitDecl->parameters.size() );
    842                         TypeDecl * td = traitDecl->parameters.front();
    843                         td->set_sized( true );
    844                 }
    845 
    846                 // move assertions from type parameters into the body of the trait
    847                 for ( TypeDecl * td : traitDecl->parameters ) {
    848                         for ( DeclarationWithType * assert : td->assertions ) {
    849                                 if ( TraitInstType * inst = dynamic_cast< TraitInstType * >( assert->get_type() ) ) {
    850                                         expandAssertions( inst, back_inserter( traitDecl->members ) );
    851                                 } else {
    852                                         traitDecl->members.push_back( assert->clone() );
    853                                 }
    854                         }
    855                         deleteAll( td->assertions );
    856                         td->assertions.clear();
    857                 } // for
    858         }
    859 
    860         void LinkReferenceToTypes_old::postvisit( TraitInstType * traitInst ) {
    861                 // handle other traits
    862                 const TraitDecl * traitDecl = local_indexer->lookupTrait( traitInst->name );
    863                 if ( ! traitDecl ) {
    864                         SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
    865                 } // if
    866                 if ( traitDecl->parameters.size() != traitInst->parameters.size() ) {
    867                         SemanticError( traitInst, "incorrect number of trait parameters: " );
    868                 } // if
    869                 traitInst->baseTrait = const_cast<TraitDecl *>(traitDecl); // Just linking in the node
    870 
    871                 // need to carry over the 'sized' status of each decl in the instance
    872                 for ( auto p : group_iterate( traitDecl->parameters, traitInst->parameters ) ) {
    873                         TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );
    874                         if ( ! expr ) {
    875                                 SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );
    876                         }
    877                         if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
    878                                 TypeDecl * formalDecl = std::get<0>(p);
    879                                 TypeDecl * instDecl = inst->baseType;
    880                                 if ( formalDecl->get_sized() ) instDecl->set_sized( true );
    881                         }
    882                 }
    883                 // normalizeAssertions( traitInst->members );
    884         }
    885 
    886         void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {
    887                 // visit enum members first so that the types of self-referencing members are updated properly
    888                 if ( enumDecl->body ) {
    889                         ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->name );
    890                         if ( fwds != forwardEnums.end() ) {
    891                                 for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    892                                         (* inst)->baseEnum = enumDecl;
    893                                 } // for
    894                                 forwardEnums.erase( fwds );
    895                         } // if
    896                 } // if
    897         }
    898 
    899         void LinkReferenceToTypes_old::renameGenericParams( std::list< TypeDecl * > & params ) {
    900                 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g.
    901                 //   forall(otype T)
    902                 //   struct Box {
    903                 //     T x;
    904                 //   };
    905                 //   forall(otype T)
    906                 //   void f(Box(T) b) {
    907                 //     ...
    908                 //   }
    909                 // The T in Box and the T in f are different, so internally the naming must reflect that.
    910                 GuardValue( inGeneric );
    911                 inGeneric = ! params.empty();
    912                 for ( TypeDecl * td : params ) {
    913                         td->name = "__" + td->name + "_generic_";
    914                 }
    915         }
    916 
    917         void LinkReferenceToTypes_old::previsit( StructDecl * structDecl ) {
    918                 renameGenericParams( structDecl->parameters );
    919         }
    920 
    921         void LinkReferenceToTypes_old::previsit( UnionDecl * unionDecl ) {
    922                 renameGenericParams( unionDecl->parameters );
    923         }
    924 
    925         void LinkReferenceToTypes_old::postvisit( StructDecl * structDecl ) {
    926                 // visit struct members first so that the types of self-referencing members are updated properly
    927                 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)
    928                 if ( structDecl->body ) {
    929                         ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->name );
    930                         if ( fwds != forwardStructs.end() ) {
    931                                 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    932                                         (* inst)->baseStruct = structDecl;
    933                                 } // for
    934                                 forwardStructs.erase( fwds );
    935                         } // if
    936                 } // if
    937         }
    938 
    939         void LinkReferenceToTypes_old::postvisit( UnionDecl * unionDecl ) {
    940                 if ( unionDecl->body ) {
    941                         ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name );
    942                         if ( fwds != forwardUnions.end() ) {
    943                                 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    944                                         (* inst)->baseUnion = unionDecl;
    945                                 } // for
    946                                 forwardUnions.erase( fwds );
    947                         } // if
    948                 } // if
    949         }
    950 
    951         void LinkReferenceToTypes_old::postvisit( TypeInstType * typeInst ) {
    952                 // ensure generic parameter instances are renamed like the base type
    953                 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;
    954                 if ( const NamedTypeDecl * namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {
    955                         if ( const TypeDecl * typeDecl = dynamic_cast< const TypeDecl * >( namedTypeDecl ) ) {
    956                                 typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );
    957                         } // if
    958                 } // if
    959625        }
    960626
     
    985651                                                }
    986652                                        }
    987                                        
    988653                                }
    989654                        }
     
    1073738        void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) {
    1074739                forallFixer( aggrDecl->parameters, aggrDecl );
    1075         }
    1076 
    1077         void TraitExpander_old::previsit( FunctionType * ftype ) {
    1078                 expandTraits( ftype->forall );
    1079         }
    1080 
    1081         void TraitExpander_old::previsit( StructDecl * aggrDecl ) {
    1082                 expandTraits( aggrDecl->parameters );
    1083         }
    1084 
    1085         void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {
    1086                 expandTraits( aggrDecl->parameters );
    1087         }
    1088 
    1089         void AssertionFixer_old::previsit( FunctionType * ftype ) {
    1090                 fixAssertions( ftype->forall, ftype );
    1091         }
    1092 
    1093         void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {
    1094                 fixAssertions( aggrDecl->parameters, aggrDecl );
    1095         }
    1096 
    1097         void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {
    1098                 fixAssertions( aggrDecl->parameters, aggrDecl );
    1099         }
    1100 
    1101         void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {
    1102                 // ensure that operator names only apply to functions or function pointers
    1103                 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
    1104                         SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." )  );
    1105                 }
    1106         }
    1107 
    1108         void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {
    1109                 decl->fixUniqueId();
    1110740        }
    1111741
  • src/SymTab/Validate.h

    r29d8c02 r74ec742  
    1010// Author           : Richard C. Bilson
    1111// Created On       : Sun May 17 21:53:34 2015
    12 // Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sat Jul 22 09:46:07 2017
    14 // Update Count     : 4
     12// Last Modified By : Andrew Beach
     13// Last Modified On : Tue May 17 14:35:00 2022
     14// Update Count     : 5
    1515//
    1616
     
    3333        /// Normalizes struct and function declarations
    3434        void validate( std::list< Declaration * > &translationUnit, bool doDebug = false );
    35         void validateType( Type *type, const Indexer *indexer );
    3635
    3736        // Sub-passes of validate.
     
    4241        void validate_E( std::list< Declaration * > &translationUnit );
    4342        void validate_F( std::list< Declaration * > &translationUnit );
    44 
    45         const ast::Type * validateType(
    46                 const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab );
    4743} // namespace SymTab
    4844
  • src/SymTab/demangler.cc

    r29d8c02 r74ec742  
    1 #include "Mangler.h"
     1#include "Demangle.h"
    22#include <iostream>
    33#include <fstream>
  • src/SymTab/module.mk

    r29d8c02 r74ec742  
    1111## Created On       : Mon Jun  1 17:49:17 2015
    1212## Last Modified By : Andrew Beach
    13 ## Last Modified On : Thr Aug 10 16:08:00 2017
    14 ## Update Count     : 4
     13## Last Modified On : Tue May 17 14:46:00 2022
     14## Update Count     : 5
    1515###############################################################################
    1616
    1717SRC_SYMTAB = \
    18       SymTab/Autogen.cc \
    19       SymTab/Autogen.h \
    20       SymTab/FixFunction.cc \
    21       SymTab/FixFunction.h \
    22       SymTab/Indexer.cc \
    23       SymTab/Indexer.h \
    24       SymTab/Mangler.cc \
    25       SymTab/ManglerCommon.cc \
    26       SymTab/Mangler.h \
    27       SymTab/Validate.cc \
    28       SymTab/Validate.h
     18        SymTab/Autogen.cc \
     19        SymTab/Autogen.h \
     20        SymTab/FixFunction.cc \
     21        SymTab/FixFunction.h \
     22        SymTab/Indexer.cc \
     23        SymTab/Indexer.h \
     24        SymTab/Mangler.cc \
     25        SymTab/ManglerCommon.cc \
     26        SymTab/Mangler.h \
     27        SymTab/ValidateType.cc \
     28        SymTab/ValidateType.h
    2929
    30 SRC += $(SRC_SYMTAB)
    31 SRCDEMANGLE += $(SRC_SYMTAB) SymTab/Demangle.cc
     30SRC += $(SRC_SYMTAB) \
     31        SymTab/Validate.cc \
     32        SymTab/Validate.h
     33
     34SRCDEMANGLE += $(SRC_SYMTAB) \
     35        SymTab/Demangle.cc \
     36        SymTab/Demangle.h
  • src/SynTree/module.mk

    r29d8c02 r74ec742  
    2424      SynTree/AttrType.cc \
    2525      SynTree/BaseSyntaxNode.h \
     26      SynTree/BaseSyntaxNode.cc \
    2627      SynTree/BasicType.cc \
    2728      SynTree/CommaExpr.cc \
  • src/Tuples/TupleExpansion.cc

    r29d8c02 r74ec742  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:45:51 2019
    13 // Update Count     : 24
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue May 17 15:02:00 2022
     13// Update Count     : 25
    1414//
    1515
     
    367367                return nullptr;
    368368        }
    369 
    370         namespace {
    371                 /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure
    372                 struct ImpurityDetector : public WithShortCircuiting {
    373                         ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
    374 
    375                         void previsit( const ApplicationExpr * appExpr ) {
    376                                 visit_children = false;
    377                                 if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
    378                                         if ( function->linkage == LinkageSpec::Intrinsic ) {
    379                                                 if ( function->name == "*?" || function->name == "?[?]" ) {
    380                                                         // intrinsic dereference, subscript are pure, but need to recursively look for impurity
    381                                                         visit_children = true;
    382                                                         return;
    383                                                 }
    384                                         }
    385                                 }
    386                                 maybeImpure = true;
    387                         }
    388                         void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; }
    389                         void previsit( const UniqueExpr * ) {
    390                                 if ( ignoreUnique ) {
    391                                         // bottom out at unique expression.
    392                                         // The existence of a unique expression doesn't change the purity of an expression.
    393                                         // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.
    394                                         visit_children = false;
    395                                         return;
    396                                 }
    397                         }
    398 
    399                         bool maybeImpure = false;
    400                         bool ignoreUnique;
    401                 };
    402         } // namespace
    403 
    404         bool maybeImpure( const Expression * expr ) {
    405                 PassVisitor<ImpurityDetector> detector( false );
    406                 expr->accept( detector );
    407                 return detector.pass.maybeImpure;
    408         }
    409 
    410         bool maybeImpureIgnoreUnique( const Expression * expr ) {
    411                 PassVisitor<ImpurityDetector> detector( true );
    412                 expr->accept( detector );
    413                 return detector.pass.maybeImpure;
    414         }
    415369} // namespace Tuples
    416370
  • src/Tuples/Tuples.cc

    r29d8c02 r74ec742  
    1010// Created On       : Mon Jun 17 14:41:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun 18  9:31:00 2019
    13 // Update Count     : 1
     12// Last Modified On : Mon May 16 16:15:00 2022
     13// Update Count     : 2
    1414//
    1515
     
    1818#include "AST/Pass.hpp"
    1919#include "AST/LinkageSpec.hpp"
     20#include "Common/PassVisitor.h"
    2021#include "InitTweak/InitTweak.h"
    2122
     
    2324
    2425namespace {
     26        /// Checks if impurity (read: side-effects) may exist in a piece of code.
     27        /// Currently gives a very crude approximation, wherein any function
     28        /// call expression means the code may be impure.
     29        struct ImpurityDetector_old : public WithShortCircuiting {
     30                bool const ignoreUnique;
     31                bool maybeImpure;
     32
     33                ImpurityDetector_old( bool ignoreUnique ) :
     34                        ignoreUnique( ignoreUnique ), maybeImpure( false )
     35                {}
     36
     37                void previsit( const ApplicationExpr * appExpr ) {
     38                        visit_children = false;
     39                        if ( const DeclarationWithType * function =
     40                                        InitTweak::getFunction( appExpr ) ) {
     41                                if ( function->linkage == LinkageSpec::Intrinsic ) {
     42                                        if ( function->name == "*?" || function->name == "?[?]" ) {
     43                                                // intrinsic dereference, subscript are pure,
     44                                                // but need to recursively look for impurity
     45                                                visit_children = true;
     46                                                return;
     47                                        }
     48                                }
     49                        }
     50                        maybeImpure = true;
     51                }
     52
     53                void previsit( const UntypedExpr * ) {
     54                        maybeImpure = true;
     55                        visit_children = false;
     56                }
     57
     58                void previsit( const UniqueExpr * ) {
     59                        if ( ignoreUnique ) {
     60                                // bottom out at unique expression.
     61                                // The existence of a unique expression doesn't change the purity of an expression.
     62                                // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.
     63                                visit_children = false;
     64                                return;
     65                        }
     66                }
     67        };
     68
     69        bool detectImpurity( const Expression * expr, bool ignoreUnique ) {
     70                PassVisitor<ImpurityDetector_old> detector( ignoreUnique );
     71                expr->accept( detector );
     72                return detector.pass.maybeImpure;
     73        }
     74
    2575        /// Determines if impurity (read: side-effects) may exist in a piece of code. Currently gives
    2676        /// a very crude approximation, wherein any function call expression means the code may be
    2777        /// impure.
    2878    struct ImpurityDetector : public ast::WithShortCircuiting {
    29                 bool maybeImpure = false;
     79                bool result = false;
    3080
    3181                void previsit( ast::ApplicationExpr const * appExpr ) {
     
    3686                                }
    3787                        }
    38                         maybeImpure = true; visit_children = false;
     88                        result = true; visit_children = false;
    3989                }
    4090                void previsit( ast::UntypedExpr const * ) {
    41                         maybeImpure = true; visit_children = false;
     91                        result = true; visit_children = false;
    4292                }
    4393        };
     94
    4495        struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
    4596                using ImpurityDetector::previsit;
     
    4899                }
    49100        };
    50 
    51         template<typename Detector>
    52         bool detectImpurity( const ast::Expr * expr ) {
    53                 ast::Pass<Detector> detector;
    54                 expr->accept( detector );
    55                 return detector.core.maybeImpure;
    56         }
    57101} // namespace
    58102
    59103bool maybeImpure( const ast::Expr * expr ) {
    60         return detectImpurity<ImpurityDetector>( expr );
     104        return ast::Pass<ImpurityDetector>::read( expr );
    61105}
    62106
    63107bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
    64         return detectImpurity<ImpurityDetectorIgnoreUnique>( expr );
     108        return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr );
     109}
     110
     111bool maybeImpure( const Expression * expr ) {
     112        return detectImpurity( expr, false );
     113}
     114
     115bool maybeImpureIgnoreUnique( const Expression * expr ) {
     116        return detectImpurity( expr, true );
    65117}
    66118
  • src/Tuples/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Henry Xue
    13 ## Last Modified On : Mon Aug 23 15:36:09 2021
    14 ## Update Count     : 2
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Mon May 17 15:00:00 2022
     14## Update Count     : 3
    1515###############################################################################
    1616
     
    2424        Tuples/Tuples.h
    2525
     26SRC += $(SRC_TUPLES)
    2627
    27 SRC += $(SRC_TUPLES)
    2828SRCDEMANGLE += $(SRC_TUPLES)
  • src/Validate/Autogen.cpp

    r29d8c02 r74ec742  
    350350                name,
    351351                std::move( type_params ),
     352                std::move( assertions ),
    352353                std::move( params ),
    353354                std::move( returns ),
     
    360361                // Auto-generated routines are inline to avoid conflicts.
    361362                ast::Function::Specs( ast::Function::Inline ) );
    362         decl->assertions = std::move( assertions );
    363363        decl->fixUniqueId();
    364364        return decl;
  • src/Validate/ForallPointerDecay.cpp

    r29d8c02 r74ec742  
    1010// Created On       : Tue Dec  7 16:15:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Feb 11 10:59:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Sat Apr 23 13:10:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    237237}
    238238
     239std::vector<ast::ptr<ast::DeclWithType>> expandAssertions(
     240                std::vector<ast::ptr<ast::DeclWithType>> const & old ) {
     241        return TraitExpander::expandAssertions( old );
     242}
     243
    239244} // namespace Validate
    240245
  • src/Validate/ForallPointerDecay.hpp

    r29d8c02 r74ec742  
    1010// Created On       : Tue Dec  7 16:15:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Dec  8 11:50:00 2021
    13 // Update Count     : 0
     12// Last Modified On : Sat Apr 23 13:13:00 2022
     13// Update Count     : 1
    1414//
    1515
    1616#pragma once
    1717
     18#include <vector>
     19#include "AST/Node.hpp"
     20
    1821namespace ast {
     22        class DeclWithType;
    1923        class TranslationUnit;
    2024}
     
    2731void decayForallPointers( ast::TranslationUnit & transUnit );
    2832
     33/// Expand all traits in an assertion list.
     34std::vector<ast::ptr<ast::DeclWithType>> expandAssertions(
     35        std::vector<ast::ptr<ast::DeclWithType>> const & );
     36
    2937}
    3038
  • src/Validate/GenericParameter.cpp

    r29d8c02 r74ec742  
    1010// Created On       : Fri Mar 21 10:02:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Apr 13 10:09:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Fri Apr 22 16:43:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    2222#include "AST/TranslationUnit.hpp"
    2323#include "AST/Type.hpp"
     24#include "Validate/NoIdSymbolTable.hpp"
    2425
    2526namespace Validate {
     
    138139// --------------------------------------------------------------------------
    139140
    140 // A SymbolTable that only has the operations used in the Translate Dimension
    141 // pass. More importantly, it doesn't have some methods that should no be
    142 // called by the Pass template (lookupId and addId).
    143 class NoIdSymbolTable {
    144         ast::SymbolTable base;
    145 public:
    146 #       define FORWARD_X( func, types_and_names, just_names ) \
    147         inline auto func types_and_names -> decltype( base.func just_names ) { \
    148                 return base.func just_names ; \
    149         }
    150 #       define FORWARD_0( func )         FORWARD_X( func, (),             () )
    151 #       define FORWARD_1( func, type )   FORWARD_X( func, (type arg),     (arg) )
    152 #       define FORWARD_2( func, t0, t1 ) FORWARD_X( func, (t0 a0, t1 a1), (a0, a1) )
    153 
    154         FORWARD_0( enterScope )
    155         FORWARD_0( leaveScope )
    156         FORWARD_1( lookupType, const std::string &        )
    157         FORWARD_1( addType   , const ast::NamedTypeDecl * )
    158         FORWARD_1( addStruct , const ast::StructDecl *    )
    159         FORWARD_1( addEnum   , const ast::EnumDecl *      )
    160         FORWARD_1( addUnion  , const ast::UnionDecl *     )
    161         FORWARD_1( addTrait  , const ast::TraitDecl *     )
    162         FORWARD_2( addWith   , const std::vector< ast::ptr<ast::Expr> > &, const ast::Decl * )
    163 };
    164 
    165 struct TranslateDimensionCore : public ast::WithGuards {
    166         NoIdSymbolTable symtab;
     141struct TranslateDimensionCore :
     142                public WithNoIdSymbolTable, public ast::WithGuards {
    167143
    168144        // SUIT: Struct- or Union- InstType
  • src/Validate/module.mk

    r29d8c02 r74ec742  
    1010## Author           : Rob Schluntz
    1111## Created On       : Fri Jul 27 10:10:10 2018
    12 ## Last Modified By : Rob Schluntz
    13 ## Last Modified On : Fri Jul 27 10:10:26 2018
    14 ## Update Count     : 2
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Tue May 17 14:59:00 2022
     14## Update Count     : 3
    1515###############################################################################
    1616
    1717SRC_VALIDATE = \
     18        Validate/FindSpecialDecls.cc \
     19        Validate/FindSpecialDecls.h
     20
     21SRC += $(SRC_VALIDATE) \
    1822        Validate/Autogen.cpp \
    1923        Validate/Autogen.hpp \
    2024        Validate/CompoundLiteral.cpp \
    2125        Validate/CompoundLiteral.hpp \
     26        Validate/EliminateTypedef.cpp \
     27        Validate/EliminateTypedef.hpp \
     28        Validate/FindSpecialDeclsNew.cpp \
     29        Validate/FixQualifiedTypes.cpp \
     30        Validate/FixQualifiedTypes.hpp \
    2231        Validate/ForallPointerDecay.cpp \
    2332        Validate/ForallPointerDecay.hpp \
     
    2635        Validate/HandleAttributes.cc \
    2736        Validate/HandleAttributes.h \
     37        Validate/HoistStruct.cpp \
     38        Validate/HoistStruct.hpp \
    2839        Validate/InitializerLength.cpp \
    2940        Validate/InitializerLength.hpp \
    3041        Validate/LabelAddressFixer.cpp \
    3142        Validate/LabelAddressFixer.hpp \
     43        Validate/NoIdSymbolTable.hpp \
    3244        Validate/ReturnCheck.cpp \
    33         Validate/ReturnCheck.hpp \
    34         Validate/FindSpecialDeclsNew.cpp \
    35         Validate/FindSpecialDecls.cc \
    36         Validate/FindSpecialDecls.h
     45        Validate/ReturnCheck.hpp
    3746
    38 SRC += $(SRC_VALIDATE)
    3947SRCDEMANGLE += $(SRC_VALIDATE)
  • src/Virtual/module.mk

    r29d8c02 r74ec742  
    1111## Created On       : Tus Jul 25 10:18:00 2017
    1212## Last Modified By : Andrew Beach
    13 ## Last Modified On : Tus Jul 25 10:18:00 2017
    14 ## Update Count     : 0
     13## Last Modified On : Tus May 17 14:59:00 2022
     14## Update Count     : 1
    1515###############################################################################
    1616
    17 SRC += Virtual/ExpandCasts.cc Virtual/ExpandCasts.h \
    18         Virtual/Tables.cc Virtual/Tables.h
    19 
    20 SRCDEMANGLE += Virtual/Tables.cc
     17SRC += \
     18        Virtual/ExpandCasts.cc \
     19        Virtual/ExpandCasts.h \
     20        Virtual/Tables.cc \
     21        Virtual/Tables.h
  • src/main.cc

    r29d8c02 r74ec742  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Apr 13 11:11:00 2022
    13 // Update Count     : 672
     12// Last Modified On : Fri Apr 29  9:52:00 2022
     13// Update Count     : 673
    1414//
    1515
     
    7070#include "ResolvExpr/Resolver.h"            // for resolve
    7171#include "SymTab/Validate.h"                // for validate
     72#include "SymTab/ValidateType.h"            // for linkReferenceToTypes
    7273#include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    7374#include "SynTree/Declaration.h"            // for Declaration
     
    7576#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    7677#include "Validate/Autogen.hpp"             // for autogenerateRoutines
     78#include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
     79#include "Validate/EliminateTypedef.hpp"    // for eliminateTypedef
     80#include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
     81#include "Validate/FixQualifiedTypes.hpp"   // for fixQualifiedTypes
     82#include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
    7783#include "Validate/GenericParameter.hpp"    // for fillGenericParameters, tr...
    78 #include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
    79 #include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
    80 #include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
     84#include "Validate/HoistStruct.hpp"         // for hoistStruct
    8185#include "Validate/InitializerLength.hpp"   // for setLengthFromInitializer
    8286#include "Validate/LabelAddressFixer.hpp"   // for fixLabelAddresses
     
    328332                // add the assignment statement after the initialization of a type parameter
    329333                PASS( "Validate-A", SymTab::validate_A( translationUnit ) );
    330                 PASS( "Validate-B", SymTab::validate_B( translationUnit ) );
     334
     335                // Must happen before auto-gen, because it uses the sized flag.
     336                PASS( "Link Reference To Types", SymTab::linkReferenceToTypes( translationUnit ) );
    331337
    332338                CodeTools::fillLocations( translationUnit );
     
    342348
    343349                        forceFillCodeLocations( transUnit );
     350
     351                        // Must happen after Link References To Types,
     352                        // because aggregate members are accessed.
     353                        PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) );
     354
     355                        PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) );
     356                        PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) );
    344357
    345358                        // Check as early as possible. Can't happen before
     
    438451                        translationUnit = convert( move( transUnit ) );
    439452                } else {
     453                        PASS( "Validate-B", SymTab::validate_B( translationUnit ) );
    440454                        PASS( "Validate-C", SymTab::validate_C( translationUnit ) );
    441455                        PASS( "Validate-D", SymTab::validate_D( translationUnit ) );
Note: See TracChangeset for help on using the changeset viewer.