Changeset 7030dab for src


Ignore:
Timestamp:
Apr 6, 2020, 4:46:28 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
e3bc51c
Parents:
71d6bd8 (diff), 057298e (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' into new-ast

Location:
src
Files:
1 added
2 deleted
99 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r71d6bd8 r7030dab  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:21:46 2019
    13 // Update Count     : 13
     12// Last Modified On : Wed Dec 11 21:39:32 2019
     13// Update Count     : 33
    1414//
    1515
     
    245245                auto decl = new StructDecl(
    246246                        node->name,
    247                         node->kind,
     247                        (AggregateDecl::Aggregate)node->kind,
    248248                        get<Attribute>().acceptL( node->attributes ),
    249249                        LinkageSpec::Spec( node->linkage.val )
     
    493493        }
    494494
     495        const ast::Stmt * visit(const ast::SuspendStmt * node ) override final {
     496                if ( inCache( node ) ) return nullptr;
     497                auto stmt = new SuspendStmt();
     498                stmt->then   = get<CompoundStmt>().accept1( node->then   );
     499                switch(node->type) {
     500                        case ast::SuspendStmt::None     : stmt->type = SuspendStmt::None     ; break;
     501                        case ast::SuspendStmt::Coroutine: stmt->type = SuspendStmt::Coroutine; break;
     502                        case ast::SuspendStmt::Generator: stmt->type = SuspendStmt::Generator; break;
     503                }
     504                return stmtPostamble( stmt, node );
     505        }
     506
    495507        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    496508                if ( inCache( node ) ) return nullptr;
     
    686698
    687699        const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
    688                 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS;
    689                 switch (node->target) {
    690                         case ast::KeywordCastExpr::Coroutine:
    691                                 castTarget = KeywordCastExpr::Coroutine;
    692                                 break;
    693                         case ast::KeywordCastExpr::Thread:
    694                                 castTarget = KeywordCastExpr::Thread;
    695                                 break;
    696                         case ast::KeywordCastExpr::Monitor:
    697                                 castTarget = KeywordCastExpr::Monitor;
    698                                 break;
    699                         default:
    700                                 break;
    701                 }
    702                 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS );
     700                AggregateDecl::Aggregate castTarget = (AggregateDecl::Aggregate)node->target;
     701                assert( AggregateDecl::Generator <= castTarget && castTarget <= AggregateDecl::Thread );
    703702                auto expr = visitBaseExpr( node,
    704703                        new KeywordCastExpr(
     
    12471246                                cv( node ),
    12481247                                node->name,
    1249                                 node->kind == ast::TypeVar::Ftype,
     1248                                node->kind == ast::TypeDecl::Ftype,
    12501249                                get<Attribute>().acceptL( node->attributes )
    12511250                        };
     
    15151514                        old->location,
    15161515                        old->name,
    1517                         old->kind,
     1516                        (ast::AggregateDecl::Aggregate)old->kind,
    15181517                        GET_ACCEPT_V(attributes, Attribute),
    15191518                        { old->linkage.val }
     
    16021601                        { old->storageClasses.val },
    16031602                        GET_ACCEPT_1(base, Type),
    1604                         (ast::TypeVar::Kind)(unsigned)old->kind,
     1603                        (ast::TypeDecl::Kind)(unsigned)old->kind,
    16051604                        old->sized,
    16061605                        GET_ACCEPT_1(init, Type)
     
    18831882        }
    18841883
     1884        virtual void visit( const SuspendStmt * old ) override final {
     1885                if ( inCache( old ) ) return;
     1886                ast::SuspendStmt::Type type;
     1887                switch (old->type) {
     1888                        case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break;
     1889                        case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break;
     1890                        case SuspendStmt::None     : type = ast::SuspendStmt::None     ; break;
     1891                        default: abort();
     1892                }
     1893                this->node = new ast::SuspendStmt(
     1894                        old->location,
     1895                        GET_ACCEPT_1(then  , CompoundStmt),
     1896                        type,
     1897                        GET_LABELS_V(old->labels)
     1898                );
     1899                cache.emplace( old, this->node );
     1900        }
     1901
    18851902        virtual void visit( const WaitForStmt * old ) override final {
    18861903                if ( inCache( old ) ) return;
     
    20562073        }
    20572074
    2058         virtual void visit( const KeywordCastExpr * old) override final {
    2059                 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS;
    2060                 switch (old->target) {
    2061                         case KeywordCastExpr::Coroutine:
    2062                                 castTarget = ast::KeywordCastExpr::Coroutine;
    2063                                 break;
    2064                         case KeywordCastExpr::Thread:
    2065                                 castTarget = ast::KeywordCastExpr::Thread;
    2066                                 break;
    2067                         case KeywordCastExpr::Monitor:
    2068                                 castTarget = ast::KeywordCastExpr::Monitor;
    2069                                 break;
    2070                         default:
    2071                                 break;
    2072                 }
    2073                 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS );
     2075        virtual void visit( const KeywordCastExpr * old ) override final {
     2076                ast::AggregateDecl::Aggregate castTarget = (ast::AggregateDecl::Aggregate)old->target;
     2077                assert( ast::AggregateDecl::Generator <= castTarget && castTarget <= ast::AggregateDecl::Thread );
    20742078                this->node = visitBaseExpr( old,
    20752079                        new ast::KeywordCastExpr(
     
    25992603                        ty = new ast::TypeInstType{
    26002604                                old->name,
    2601                                 old->isFtype ? ast::TypeVar::Ftype : ast::TypeVar::Dtype,
     2605                                old->isFtype ? ast::TypeDecl::Ftype : ast::TypeDecl::Dtype,
    26022606                                cv( old ),
    26032607                                GET_ACCEPT_V( attributes, Attribute )
  • src/AST/Decl.cpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 16:23:15 2019
     13// Update Count     : 20
    1414//
    1515
     
    1818#include <cassert>             // for assert, strict_dynamic_cast
    1919#include <iostream>
    20 #include <string>
    2120#include <unordered_map>
    2221
     
    2726#include "Node.hpp"            // for readonly
    2827#include "Type.hpp"            // for readonly
    29 #include "Parser/ParseNode.h"  // for DeclarationNode
    3028
    3129namespace ast {
     
    5856// --- TypeDecl
    5957
    60 std::string TypeDecl::typeString() const {
    61         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
    62         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1,
    63                 "typeString: kindNames is out of sync." );
    64         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    65         return (sized ? "sized " : "") + kindNames[ kind ];
     58const char * TypeDecl::typeString() const {
     59        static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" };
     60        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
     61        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
     62        return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    6663}
    6764
    68 std::string TypeDecl::genTypeString() const {
    69         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
    70         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    71         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     65const char * TypeDecl::genTypeString() const {
     66        static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" };
     67        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." );
     68        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    7269        return kindNames[ kind ];
    7370}
     
    7572std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) {
    7673        return out << data.kind << ", " << data.isComplete;
     74}
     75
     76// --- AggregateDecl
     77
     78// These must harmonize with the corresponding AggregateDecl::Aggregate enumerations.
     79static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" };
     80
     81const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) {
     82        return aggregateNames[aggr];
    7783}
    7884
  • src/AST/Decl.hpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 17:38:33 2019
     13// Update Count     : 29
    1414//
    1515
     
    2020#include <unordered_map>
    2121#include <vector>
     22#include <algorithm>
    2223
    2324#include "FunctionSpec.hpp"
     
    2728#include "ParseNode.hpp"
    2829#include "StorageClasses.hpp"
    29 #include "TypeVar.hpp"
    3030#include "Visitor.hpp"
    31 #include "Parser/ParseNode.h"  // for DeclarationNode::Aggregate
     31#include "Common/utility.h"
     32#include "Common/SemanticError.h"                                               // error_str
    3233
    3334// Must be included in *all* AST classes; should be #undef'd at the end of the file
     
    127128        std::vector< ptr<Expr> > withExprs;
    128129
    129         FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
     130        FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,
    130131                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    131132                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
     
    138139        bool has_body() const { return stmts; }
    139140
    140         const DeclWithType * accept( Visitor &v ) const override { return v.visit( this ); }
     141        const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }
    141142private:
    142143        FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
     
    151152        std::vector<ptr<DeclWithType>> assertions;
    152153
    153         NamedTypeDecl( 
     154        NamedTypeDecl(
    154155                const CodeLocation & loc, const std::string & name, Storage::Classes storage,
    155156                const Type * b, Linkage::Spec spec = Linkage::Cforall )
     
    157158
    158159        /// Produces a name for the kind of alias
    159         virtual std::string typeString() const = 0;
     160        virtual const char * typeString() const = 0;
    160161
    161162private:
     
    166167/// Cforall type variable: `dtype T`
    167168class TypeDecl final : public NamedTypeDecl {
    168 public:
    169         TypeVar::Kind kind;
     169  public:
     170        enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS };
     171
     172        Kind kind;
    170173        bool sized;
    171174        ptr<Type> init;
     
    173176        /// Data extracted from a type decl
    174177        struct Data {
    175                 TypeVar::Kind kind;
     178                Kind kind;
    176179                bool isComplete;
    177180
    178                 Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {}
     181                Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {}
    179182                Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {}
    180                 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}
     183                Data( Kind k, bool c ) : kind( k ), isComplete( c ) {}
    181184                Data( const Data & d1, const Data & d2 )
    182                 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
    183 
    184                 bool operator== ( const Data & o ) const {
    185                         return kind == o.kind && isComplete == o.isComplete;
    186                 }
    187                 bool operator!= ( const Data & o ) const { return !(*this == o); }
     185                        : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
     186
     187                bool operator==( const Data & o ) const { return kind == o.kind && isComplete == o.isComplete; }
     188                bool operator!=( const Data & o ) const { return !(*this == o); }
    188189        };
    189190
    190         TypeDecl( 
    191                 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 
     191        TypeDecl(
     192                const CodeLocation & loc, const std::string & name, Storage::Classes storage,
    192193                const Type * b, TypeVar::Kind k, bool s, const Type * i = nullptr )
    193194        : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ),
    194195          init( i ) {}
    195196
    196         std::string typeString() const override;
     197        const char * typeString() const override;
    197198        /// Produces a name for generated code
    198         std::string genTypeString() const;
     199        const char * genTypeString() const;
    199200
    200201        /// convenience accessor to match Type::isComplete()
     
    202203
    203204        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    204 private:
     205  private:
    205206        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
    206207        MUTATE_FRIEND
     
    216217        : NamedTypeDecl( loc, name, storage, b, spec ) {}
    217218
    218         std::string typeString() const override { return "typedef"; }
     219        const char * typeString() const override { return "typedef"; }
    219220
    220221        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    227228class AggregateDecl : public Decl {
    228229public:
     230        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     231        static const char * aggrString( Aggregate aggr );
     232
    229233        std::vector<ptr<Decl>> members;
    230234        std::vector<ptr<TypeDecl>> params;
     
    241245
    242246        /// Produces a name for the kind of aggregate
    243         virtual std::string typeString() const = 0;
     247        virtual const char * typeString() const = 0;
    244248
    245249private:
     
    251255class StructDecl final : public AggregateDecl {
    252256public:
    253         DeclarationNode::Aggregate kind;
     257        Aggregate kind;
    254258
    255259        StructDecl( const CodeLocation& loc, const std::string& name,
    256                 DeclarationNode::Aggregate kind = DeclarationNode::Struct,
     260                Aggregate kind = Struct,
    257261                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    258262        : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {}
    259263
    260         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    261         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    262         bool is_thread() { return kind == DeclarationNode::Thread; }
    263 
    264         const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    265 
    266         std::string typeString() const override { return "struct"; }
     264        bool is_coroutine() { return kind == Coroutine; }
     265        bool is_generator() { return kind == Generator; }
     266        bool is_monitor  () { return kind == Monitor  ; }
     267        bool is_thread   () { return kind == Thread   ; }
     268
     269        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     270
     271        const char * typeString() const override { return aggrString( kind ); }
    267272
    268273private:
     
    280285        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    281286
    282         std::string typeString() const override { return "union"; }
     287        const char * typeString() const override { return aggrString( Union ); }
    283288
    284289private:
     
    299304        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    300305
    301         std::string typeString() const override { return "enum"; }
     306        const char * typeString() const override { return aggrString( Enum ); }
    302307
    303308private:
     
    318323        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    319324
    320         std::string typeString() const override { return "trait"; }
     325        const char * typeString() const override { return "trait"; }
    321326
    322327private:
     
    344349        ptr<AsmStmt> stmt;
    345350
    346         AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
     351        AsmDecl( const CodeLocation & loc, AsmStmt * stmt )
    347352        : Decl( loc, "", {}, {} ), stmt(stmt) {}
    348353
    349         const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
    350 private:
    351         AsmDecl *clone() const override { return new AsmDecl( *this ); }
     354        const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     355private:
     356        AsmDecl * clone() const override { return new AsmDecl( *this ); }
    352357        MUTATE_FRIEND
    353358};
     
    361366        : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
    362367
    363         const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     368        const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }
    364369private:
    365370        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
  • src/AST/Expr.cpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 15 17:00:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Created On       : Fri Oct  4 15:34:00 2019
    13 // Update Count     : 4
     11// Last Modified By : Peter A. Buhr
     12// Created On       : Thr Jun 13 13:38:00 2019
     13// Update Count     : 6
    1414//
    1515
     
    163163// --- KeywordCastExpr
    164164
    165 const std::string & KeywordCastExpr::targetString() const {
    166         static const std::string targetStrs[] = {
    167                 "coroutine", "thread", "monitor"
    168         };
    169         static_assert(
    170                 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
    171                 "Each KeywordCastExpr::Target should have a corresponding string representation"
    172         );
    173         return targetStrs[(unsigned long)target];
     165const char * KeywordCastExpr::targetString() const {
     166        return AggregateDecl::aggrString( target );
    174167}
    175168
  • src/AST/Expr.hpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri May 10 10:30:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Created On       : Thr Sep 26 12:51:00 2019
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Created On       : Fri May 10 10:30:00 2019
     13// Update Count     : 7
    1414//
    1515
     
    2626#include "Fwd.hpp"        // for UniqueId
    2727#include "Label.hpp"
     28#include "Decl.hpp"
    2829#include "ParseNode.hpp"
    2930#include "Visitor.hpp"
     
    310311public:
    311312        ptr<Expr> arg;
    312         enum Target { Coroutine, Thread, Monitor, NUMBER_OF_TARGETS } target;
    313 
    314         KeywordCastExpr( const CodeLocation & loc, const Expr * a, Target t )
     313        ast::AggregateDecl::Aggregate target;
     314
     315        KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t )
    315316        : Expr( loc ), arg( a ), target( t ) {}
    316317
    317318        /// Get a name for the target type
    318         const std::string& targetString() const;
     319        const char * targetString() const;
    319320
    320321        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Fwd.hpp

    r71d6bd8 r7030dab  
    5353class CatchStmt;
    5454class FinallyStmt;
     55class SuspendStmt;
    5556class WaitForStmt;
    5657class WithStmt;
  • src/AST/Pass.hpp

    r71d6bd8 r7030dab  
    114114        const ast::Stmt *             visit( const ast::CatchStmt            * ) override final;
    115115        const ast::Stmt *             visit( const ast::FinallyStmt          * ) override final;
     116        const ast::Stmt *             visit( const ast::SuspendStmt          * ) override final;
    116117        const ast::Stmt *             visit( const ast::WaitForStmt          * ) override final;
    117118        const ast::Decl *             visit( const ast::WithStmt             * ) override final;
  • src/AST/Pass.impl.hpp

    r71d6bd8 r7030dab  
    838838
    839839//--------------------------------------------------------------------------
     840// FinallyStmt
     841template< typename pass_t >
     842const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SuspendStmt * node ) {
     843        VISIT_START( node );
     844
     845        VISIT(
     846                maybe_accept( node, &SuspendStmt::then   );
     847        )
     848
     849        VISIT_END( Stmt, node );
     850}
     851
     852//--------------------------------------------------------------------------
    840853// WaitForStmt
    841854template< typename pass_t >
  • src/AST/Print.cpp

    r71d6bd8 r7030dab  
    674674                safe_print( node->body );
    675675                --indent;
     676
     677                return node;
     678        }
     679
     680        virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final {
     681                os << "Suspend Statement";
     682                switch (node->type) {
     683                        case ast::SuspendStmt::None     : os << " with implicit target"; break;
     684                        case ast::SuspendStmt::Generator: os << " for generator"; break;
     685                        case ast::SuspendStmt::Coroutine: os << " for coroutine"; break;
     686                }
     687                os << endl;
     688
     689                ++indent;
     690                if(node->then) {
     691                        os << indent << " with post statement :" << endl;
     692                        safe_print( node->then );
     693                }
     694                ++indent;
    676695
    677696                return node;
     
    13591378                preprint( node );
    13601379                os << "instance of type " << node->name
    1361                    << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";
     1380                   << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
    13621381                print( node->params );
    13631382
  • src/AST/Stmt.hpp

    r71d6bd8 r7030dab  
    344344};
    345345
     346/// Suspend statement
     347class SuspendStmt final : public Stmt {
     348public:
     349        ptr<CompoundStmt> then;
     350        enum Type { None, Coroutine, Generator } type = None;
     351
     352        SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, std::vector<Label> && labels = {} )
     353        : Stmt(loc, std::move(labels)), then(then), type(type) {}
     354
     355        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     356private:
     357        SuspendStmt * clone() const override { return new SuspendStmt{ *this }; }
     358        MUTATE_FRIEND
     359};
     360
    346361/// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`
    347362class WaitForStmt final : public Stmt {
  • src/AST/Type.cpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Mon May 13 15:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Mon May 13 15:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Dec 15 16:56:28 2019
     13// Update Count     : 4
    1414//
    1515
     
    5050// --- BasicType
    5151
    52 const char *BasicType::typeNames[] = {
     52// GENERATED START, DO NOT EDIT
     53// GENERATED BY BasicTypes-gen.cc
     54const char * BasicType::typeNames[] = {
    5355        "_Bool",
    5456        "char",
     
    8890        "_Float128x _Complex",
    8991};
    90 static_assert(
    91         sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
    92         "Each basic type name should have a corresponding kind enum value"
    93 );
     92// GENERATED END
    9493
    9594// --- ParameterizedType
  • src/AST/Type.hpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:56:46 2019
     13// Update Count     : 5
    1414//
    1515
     
    2626#include "Fwd.hpp"
    2727#include "Node.hpp"          // for Node, ptr, ptr_base
    28 #include "TypeVar.hpp"
    2928#include "Visitor.hpp"
    3029
     
    448447public:
    449448        readonly<TypeDecl> base;
    450         TypeVar::Kind kind;
     449        TypeDecl::Kind kind;
    451450
    452451        TypeInstType(
     
    454453                std::vector<ptr<Attribute>> && as = {} )
    455454        : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
    456 
    457         TypeInstType(
    458                 const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {},
     455        TypeInstType( const std::string& n, TypeDecl::Kind k, CV::Qualifiers q = {},
    459456                std::vector<ptr<Attribute>> && as = {} )
    460457        : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {}
  • src/AST/TypeEnvironment.cpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 29 11:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 29 11:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:49:13 2019
     13// Update Count     : 4
    1414//
    1515
     
    240240                return true;
    241241        } else if ( auto typeInst = dynamic_cast< const TypeInstType * >( type ) ) {
    242                 return typeInst->kind == TypeVar::Ftype;
     242                return typeInst->kind == TypeDecl::Ftype;
    243243        } else return false;
    244244}
     
    248248        bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) {
    249249                switch ( data.kind ) {
    250                   case TypeVar::Dtype:
     250                  case TypeDecl::Dtype:
    251251                        // to bind to an object type variable, the type must not be a function type.
    252252                        // if the type variable is specified to be a complete type then the incoming
     
    254254                        // xxx - should this also check that type is not a tuple type and that it's not a ttype?
    255255                        return ! isFtype( type ) && ( ! data.isComplete || type->isComplete() );
    256                   case TypeVar::Ftype:
     256                  case TypeDecl::Ftype:
    257257                        return isFtype( type );
    258                   case TypeVar::Ttype:
     258                  case TypeDecl::Ttype:
    259259                        // ttype unifies with any tuple type
    260260                        return dynamic_cast< const TupleType * >( type ) || Tuples::isTtype( type );
  • src/AST/TypeEnvironment.hpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 29 11:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 29 11:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:55:54 2019
     13// Update Count     : 3
    1414//
    1515
     
    2828#include "Type.hpp"
    2929#include "TypeSubstitution.hpp"
    30 #include "TypeVar.hpp"
    3130#include "Common/Indenter.h"
    3231#include "ResolvExpr/WidenMode.h"
     
    107106        /// Singleton class constructor from substitution
    108107        EqvClass( const std::string & v, const Type * b )
    109         : vars{ v }, bound( b ), allowWidening( false ), data( TypeVar::Dtype, false ) {}
     108        : vars{ v }, bound( b ), allowWidening( false ), data( TypeDecl::Dtype, false ) {}
    110109
    111110        /// Single-var constructor (strips qualifiers from bound type)
  • src/AST/Visitor.hpp

    r71d6bd8 r7030dab  
    4747    virtual const ast::Stmt *             visit( const ast::CatchStmt            * ) = 0;
    4848    virtual const ast::Stmt *             visit( const ast::FinallyStmt          * ) = 0;
     49    virtual const ast::Stmt *             visit( const ast::SuspendStmt          * ) = 0;
    4950    virtual const ast::Stmt *             visit( const ast::WaitForStmt          * ) = 0;
    5051    virtual const ast::Decl *             visit( const ast::WithStmt             * ) = 0;
  • src/AST/module.mk

    r71d6bd8 r7030dab  
    1010## Author           : Thierry Delisle
    1111## Created On       : Thu May 09 16:05:36 2019
    12 ## Last Modified By :
    13 ## Last Modified On :
    14 ## Update Count     :
     12## Last Modified By : Peter A. Buhr
     13## Last Modified On : Sat Dec 14 07:29:10 2019
     14## Update Count     : 3
    1515###############################################################################
    1616
     
    3535        AST/TypeSubstitution.cpp
    3636
    37 
    38 
    3937SRC += $(SRC_AST)
    4038SRCDEMANGLE += $(SRC_AST)
  • src/BasicTypes-gen.cc

    r71d6bd8 r7030dab  
    273273
    274274
    275         #define Type TOP_SRCDIR "src/SynTree/Type.h"
    276         resetInput( file, Type, buffer, code, str );
    277 
    278         if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", Type );
     275        #define TypeH TOP_SRCDIR "src/SynTree/Type.h"
     276        resetInput( file, TypeH, buffer, code, str );
     277
     278        if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeH );
    279279        start += sizeof( STARTMK );                                                     // includes newline
    280280        code << str.substr( 0, start );
     
    289289        code << "\t";                                                                           // indentation for end marker
    290290
    291         if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", Type );
    292         code << str.substr( start );
    293 
    294         output( file, Type, code );
     291        if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeH );
     292        code << str.substr( start );
     293
     294        output( file, TypeH, code );
     295        // cout << code.str();
     296
     297
     298        #define TypeC TOP_SRCDIR "src/SynTree/Type.cc"
     299        resetInput( file, TypeC, buffer, code, str );
     300
     301        if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeC );
     302        start += sizeof( STARTMK );                                                     // includes newline
     303        code << str.substr( 0, start );
     304
     305        code << BYMK << endl;
     306        code << "const char * BasicType::typeNames[] = {" << endl;
     307        for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
     308                code << "\t\"" << graph[r].type << "\"," << endl;
     309        } // for       
     310        code << "};" << endl;
     311
     312        if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeC );
     313        code << str.substr( start );
     314
     315        output( file, TypeC, code );
    295316        // cout << code.str();
    296317
    297318
    298319        // TEMPORARY DURING CHANGE OVER
    299         #define TypeAST TOP_SRCDIR "src/AST/Type.hpp"
    300         resetInput( file, TypeAST, buffer, code, str );
    301 
    302         if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeAST );
     320        #define TypeH_AST TOP_SRCDIR "src/AST/Type.hpp"
     321        resetInput( file, TypeH_AST, buffer, code, str );
     322
     323        if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeH_AST );
    303324        start += sizeof( STARTMK );                                                     // includes newline
    304325        code << str.substr( 0, start );
     
    313334        code << "\t";                                                                           // indentation for end marker
    314335
    315         if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeAST );
    316         code << str.substr( start );
    317 
    318         output( file, TypeAST, code );
     336        if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeH_AST );
     337        code << str.substr( start );
     338
     339        output( file, TypeH_AST, code );
     340        // cout << code.str();
     341
     342
     343        #define TypeC_AST TOP_SRCDIR "src/AST/Type.cpp"
     344        resetInput( file, TypeC_AST, buffer, code, str );
     345
     346        if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeC_AST );
     347        start += sizeof( STARTMK );                                                     // includes newline
     348        code << str.substr( 0, start );
     349
     350        code << BYMK << endl;
     351        code << "const char * BasicType::typeNames[] = {" << endl;
     352        for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
     353                code << "\t\"" << graph[r].type << "\"," << endl;
     354        } // for       
     355        code << "};" << endl;
     356
     357        if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeC_AST );
     358        code << str.substr( start );
     359
     360        output( file, TypeC_AST, code );
    319361        // cout << code.str();
    320362
  • src/CodeGen/CodeGenerator.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct 19 19:30:38 2019
    13 // Update Count     : 506
     12// Last Modified On : Sun Feb 16 08:32:48 2020
     13// Update Count     : 532
    1414//
    1515#include "CodeGenerator.h"
     
    2323#include "InitTweak/InitTweak.h"     // for getPointerBase
    2424#include "OperatorTable.h"           // for OperatorInfo, operatorLookup
    25 #include "Parser/LinkageSpec.h"      // for Spec, Intrinsic
     25#include "SynTree/LinkageSpec.h"     // for Spec, Intrinsic
    2626#include "SynTree/Attribute.h"       // for Attribute
    2727#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
     
    3939        int CodeGenerator::tabsize = 4;
    4040
    41         // the kinds of statements that would ideally be followed by whitespace
     41        // The kinds of statements that would ideally be followed by whitespace.
    4242        bool wantSpacing( Statement * stmt) {
    4343                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
     
    7878        }
    7979
    80         /* Using updateLocation at the beginning of a node and endl
    81          * within a node should become the method of formating.
    82          */
     80        // Using updateLocation at the beginning of a node and endl within a node should become the method of formating.
    8381        void CodeGenerator::updateLocation( CodeLocation const & to ) {
    8482                // skip if linemarks shouldn't appear or if codelocation is unset
     
    9593                } else {
    9694                        output << "\n# " << to.first_line << " \"" << to.filename
    97                                << "\"\n" << indent;
     95                                   << "\"\n" << indent;
    9896                        currentLocation = to;
    9997                }
     
    131129
    132130        void CodeGenerator::genAttributes( list< Attribute * > & attributes ) {
    133           if ( attributes.empty() ) return;
     131                if ( attributes.empty() ) return;
    134132                output << "__attribute__ ((";
    135133                for ( list< Attribute * >::iterator attr( attributes.begin() );; ) {
     
    140138                                output << ")";
    141139                        } // if
    142                   if ( ++attr == attributes.end() ) break;
     140                        if ( ++attr == attributes.end() ) break;
    143141                        output << ",";                                                          // separator
    144142                } // for
     
    165163                previsit( (BaseSyntaxNode *)node );
    166164                GuardAction( [this, node](){
    167                         if ( options.printExprTypes && node->result ) {
    168                                 output << " /* " << genType( node->result, "", options ) << " */ ";
    169                         }
    170                 } );
     165                                if ( options.printExprTypes && node->result ) {
     166                                        output << " /* " << genType( node->result, "", options ) << " */ ";
     167                                }
     168                        } );
    171169        }
    172170
     
    399397                extension( applicationExpr );
    400398                if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
    401                         OperatorInfo opInfo;
    402                         if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
     399                        const OperatorInfo * opInfo;
     400                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && ( opInfo = operatorLookup( varExpr->get_var()->get_name() ) ) ) {
    403401                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    404                                 switch ( opInfo.type ) {
     402                                switch ( opInfo->type ) {
    405403                                  case OT_INDEX:
    406404                                        assert( applicationExpr->get_args().size() == 2 );
     
    423421                                                output << "(";
    424422                                                (*arg++)->accept( *visitor );
    425                                                 output << ") /* " << opInfo.inputName << " */";
     423                                                output << ") /* " << opInfo->inputName << " */";
    426424                                        } else if ( applicationExpr->get_args().size() == 2 ) {
    427425                                                // intrinsic two parameter constructors are essentially bitwise assignment
    428426                                                output << "(";
    429427                                                (*arg++)->accept( *visitor );
    430                                                 output << opInfo.symbol;
     428                                                output << opInfo->symbol;
    431429                                                (*arg)->accept( *visitor );
    432                                                 output << ") /* " << opInfo.inputName << " */";
     430                                                output << ") /* " << opInfo->inputName << " */";
    433431                                        } else {
    434432                                                // no constructors with 0 or more than 2 parameters
     
    441439                                        assert( applicationExpr->get_args().size() == 1 );
    442440                                        output << "(";
    443                                         output << opInfo.symbol;
     441                                        output << opInfo->symbol;
    444442                                        (*arg)->accept( *visitor );
    445443                                        output << ")";
     
    450448                                        assert( applicationExpr->get_args().size() == 1 );
    451449                                        (*arg)->accept( *visitor );
    452                                         output << opInfo.symbol;
     450                                        output << opInfo->symbol;
    453451                                        break;
    454452
     
    459457                                        output << "(";
    460458                                        (*arg++)->accept( *visitor );
    461                                         output << opInfo.symbol;
     459                                        output << opInfo->symbol;
    462460                                        (*arg)->accept( *visitor );
    463461                                        output << ")";
     
    486484                extension( untypedExpr );
    487485                if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) {
    488                         OperatorInfo opInfo;
    489                         if ( operatorLookup( nameExpr->name, opInfo ) ) {
     486                        const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     487                        if ( opInfo ) {
    490488                                std::list< Expression* >::iterator arg = untypedExpr->args.begin();
    491                                 switch ( opInfo.type ) {
     489                                switch ( opInfo->type ) {
    492490                                  case OT_INDEX:
    493491                                        assert( untypedExpr->args.size() == 2 );
     
    508506                                                output << "(";
    509507                                                (*arg++)->accept( *visitor );
    510                                                 output << ") /* " << opInfo.inputName << " */";
     508                                                output << ") /* " << opInfo->inputName << " */";
    511509                                        } else if ( untypedExpr->get_args().size() == 2 ) {
    512510                                                // intrinsic two parameter constructors are essentially bitwise assignment
    513511                                                output << "(";
    514512                                                (*arg++)->accept( *visitor );
    515                                                 output << opInfo.symbol;
     513                                                output << opInfo->symbol;
    516514                                                (*arg)->accept( *visitor );
    517                                                 output << ") /* " << opInfo.inputName << " */";
     515                                                output << ") /* " << opInfo->inputName << " */";
    518516                                        } else {
    519517                                                // no constructors with 0 or more than 2 parameters
     
    521519                                                output << "(";
    522520                                                (*arg++)->accept( *visitor );
    523                                                 output << opInfo.symbol << "{ ";
     521                                                output << opInfo->symbol << "{ ";
    524522                                                genCommaList( arg, untypedExpr->args.end() );
    525                                                 output << "}) /* " << opInfo.inputName << " */";
     523                                                output << "}) /* " << opInfo->inputName << " */";
    526524                                        } // if
    527525                                        break;
     
    532530                                        assert( untypedExpr->args.size() == 1 );
    533531                                        output << "(";
    534                                         output << opInfo.symbol;
     532                                        output << opInfo->symbol;
    535533                                        (*arg)->accept( *visitor );
    536534                                        output << ")";
     
    541539                                        assert( untypedExpr->args.size() == 1 );
    542540                                        (*arg)->accept( *visitor );
    543                                         output << opInfo.symbol;
     541                                        output << opInfo->symbol;
    544542                                        break;
    545543
     
    549547                                        output << "(";
    550548                                        (*arg++)->accept( *visitor );
    551                                         output << opInfo.symbol;
     549                                        output << opInfo->symbol;
    552550                                        (*arg)->accept( *visitor );
    553551                                        output << ")";
     
    581579        void CodeGenerator::postvisit( NameExpr * nameExpr ) {
    582580                extension( nameExpr );
    583                 OperatorInfo opInfo;
    584                 if ( operatorLookup( nameExpr->name, opInfo ) ) {
    585                         if ( opInfo.type == OT_CONSTANT ) {
    586                                 output << opInfo.symbol;
     581                const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     582                if ( opInfo ) {
     583                        if ( opInfo->type == OT_CONSTANT ) {
     584                                output << opInfo->symbol;
    587585                        } else {
    588                                 output << opInfo.outputName;
     586                                output << opInfo->outputName;
    589587                        }
    590588                } else {
     
    654652        void CodeGenerator::postvisit( VariableExpr * variableExpr ) {
    655653                extension( variableExpr );
    656                 OperatorInfo opInfo;
    657                 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
    658                         output << opInfo.symbol;
     654                const OperatorInfo * opInfo;
     655                if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && (opInfo = operatorLookup( variableExpr->get_var()->get_name() )) && opInfo->type == OT_CONSTANT ) {
     656                        output << opInfo->symbol;
    659657                } else {
    660658                        output << mangleName( variableExpr->get_var() );
     
    10111009                  case BranchStmt::FallThroughDefault:
    10121010                        assertf( ! options.genC, "fallthru should not reach code generation." );
    1013                   output << "fallthru";
     1011                        output << "fallthru";
    10141012                        break;
    10151013                } // switch
     
    10351033
    10361034                output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ?
    1037                            "throw" : "throwResume");
     1035                                   "throw" : "throwResume");
    10381036                if (throwStmt->get_expr()) {
    10391037                        output << " ";
     
    10501048
    10511049                output << ((stmt->get_kind() == CatchStmt::Terminate) ?
    1052                 "catch" : "catchResume");
     1050                                   "catch" : "catchResume");
    10531051                output << "( ";
    10541052                stmt->decl->accept( *visitor );
     
    11871185
    11881186        std::string genName( DeclarationWithType * decl ) {
    1189                 CodeGen::OperatorInfo opInfo;
    1190                 if ( operatorLookup( decl->get_name(), opInfo ) ) {
    1191                         return opInfo.outputName;
     1187                const OperatorInfo * opInfo = operatorLookup( decl->get_name() );
     1188                if ( opInfo ) {
     1189                        return opInfo->outputName;
    11921190                } else {
    11931191                        return decl->get_name();
  • src/CodeGen/CodeGenerator.h

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr 30 12:01:00 2019
    13 // Update Count     : 57
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Feb 16 03:58:31 2020
     13// Update Count     : 62
    1414//
    1515
     
    2929namespace CodeGen {
    3030        struct CodeGenerator : public WithShortCircuiting, public WithGuards, public WithVisitorRef<CodeGenerator> {
    31           static int tabsize;
     31                static int tabsize;
    3232
    3333                CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false );
     
    104104                void postvisit( AsmStmt * );
    105105                void postvisit( DirectiveStmt * );
    106                 void postvisit( AsmDecl * );                            // special: statement in declaration context
     106                void postvisit( AsmDecl * );                                    // special: statement in declaration context
    107107                void postvisit( IfStmt * );
    108108                void postvisit( SwitchStmt * );
     
    147147                LabelPrinter printLabels;
    148148                Options options;
    149         public:
     149          public:
    150150                LineEnder endl;
    151         private:
     151          private:
    152152
    153153                CodeLocation currentLocation;
     
    162162        template< class Iterator >
    163163        void CodeGenerator::genCommaList( Iterator begin, Iterator end ) {
    164           if ( begin == end ) return;
     164                if ( begin == end ) return;
    165165                for ( ;; ) {
    166166                        (*begin++)->accept( *visitor );
    167                   if ( begin == end ) break;
     167                        if ( begin == end ) break;
    168168                        output << ", ";                                                         // separator
    169169                } // for
  • src/CodeGen/FixMain.h

    r71d6bd8 r7030dab  
    1010// Created On       : Thr Jan 12 14:11:09 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:16:59 2017
    13 // Update Count     : 1
     12// Last Modified On : Sun Feb 16 03:24:32 2020
     13// Update Count     : 5
    1414//
    1515
     
    1919#include <memory>
    2020
    21 #include "Parser/LinkageSpec.h"
     21#include "SynTree/LinkageSpec.h"
    2222
    2323class FunctionDecl;
     
    4242                static std::unique_ptr<FunctionDecl> main_signature;
    4343        };
    44 };
     44} // namespace CodeGen
  • src/CodeGen/FixNames.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jun 28 15:26:00 2017
    13 // Update Count     : 20
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:39:14 2019
     13// Update Count     : 21
    1414//
    1515
     
    2222#include "Common/SemanticError.h"  // for SemanticError
    2323#include "FixMain.h"               // for FixMain
    24 #include "Parser/LinkageSpec.h"    // for Cforall, isMangled
    2524#include "SymTab/Mangler.h"        // for Mangler
     25#include "SynTree/LinkageSpec.h"   // for Cforall, isMangled
    2626#include "SynTree/Constant.h"      // for Constant
    2727#include "SynTree/Declaration.h"   // for FunctionDecl, ObjectDecl, Declarat...
  • src/CodeGen/GenType.h

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr 30 11:47:00 2019
    13 // Update Count     : 3
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Feb 16 04:11:40 2020
     13// Update Count     : 5
    1414//
    1515
     
    2525        std::string genType( Type *type, const std::string &baseString, const Options &options );
    2626        std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false );
    27   std::string genPrettyType( Type * type, const std::string & baseString );
     27        std::string genPrettyType( Type * type, const std::string & baseString );
    2828} // namespace CodeGen
    2929
  • src/CodeGen/Generate.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:39:00 2017
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Feb 16 03:01:51 2020
     13// Update Count     : 9
    1414//
    1515#include "Generate.h"
     
    2222#include "GenType.h"                 // for genPrettyType
    2323#include "Common/PassVisitor.h"      // for PassVisitor
    24 #include "Parser/LinkageSpec.h"      // for isBuiltin, isGeneratable
     24#include "SynTree/LinkageSpec.h"     // for isBuiltin, isGeneratable
    2525#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
    2626#include "SynTree/Declaration.h"     // for Declaration
     
    6464        void generate( BaseSyntaxNode * node, std::ostream & os ) {
    6565                if ( Type * type = dynamic_cast< Type * >( node ) ) {
    66                         os << CodeGen::genPrettyType( type, "" );
     66                        os << genPrettyType( type, "" );
    6767                } else {
    6868                        PassVisitor<CodeGenerator> cgv( os, true, false, false, false );
  • src/CodeGen/OperatorTable.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 15 17:12:22 2017
    13 // Update Count     : 15
     12// Last Modified On : Tue Feb 18 15:55:01 2020
     13// Update Count     : 55
    1414//
    1515
     
    1717#include <map>        // for map, _Rb_tree_const_iterator, map<>::const_iterator
    1818#include <utility>    // for pair
     19using namespace std;
    1920
    2021#include "OperatorTable.h"
     
    2223
    2324namespace CodeGen {
    24         namespace {
    25                 const OperatorInfo tableValues[] = {
    26                         {       "?[?]",         "",             "_operator_index",                              OT_INDEX                        },
    27                         {       "?{}",          "=",    "_constructor",                                 OT_CTOR                         },
    28                         {       "^?{}",         "",             "_destructor",                                  OT_DTOR                         },
    29                         {       "?()",          "",             "_operator_call",                               OT_CALL                         },
    30                         {       "?++",          "++",   "_operator_postincr",                   OT_POSTFIXASSIGN        },
    31                         {       "?--",          "--",   "_operator_postdecr",                   OT_POSTFIXASSIGN        },
    32                         {       "*?",           "*",    "_operator_deref",                              OT_PREFIX                       },
    33                         {       "+?",           "+",    "_operator_unaryplus",                  OT_PREFIX                       },
    34                         {       "-?",           "-",    "_operator_unaryminus",                 OT_PREFIX                       },
    35                         {       "~?",           "~",    "_operator_bitnot",                             OT_PREFIX                       },
    36                         {       "!?",           "!",    "_operator_lognot",                             OT_PREFIX                       },
    37                         {       "++?",          "++",   "_operator_preincr",                    OT_PREFIXASSIGN         },
    38                         {       "--?",          "--",   "_operator_predecr",                    OT_PREFIXASSIGN         },
    39                         {       "?\\?",         "\\",   "_operator_exponential",                OT_INFIX                        },
    40                         {       "?*?",          "*",    "_operator_multiply",                   OT_INFIX                        },
    41                         {       "?/?",          "/",    "_operator_divide",                             OT_INFIX                        },
    42                         {       "?%?",          "%",    "_operator_modulus",                    OT_INFIX                        },
    43                         {       "?+?",          "+",    "_operator_add",                                OT_INFIX                        },
    44                         {       "?-?",          "-",    "_operator_subtract",                   OT_INFIX                        },
    45                         {       "?<<?",         "<<",   "_operator_shiftleft",                  OT_INFIX                        },
    46                         {       "?>>?",         ">>",   "_operator_shiftright",                 OT_INFIX                        },
    47                         {       "?<?",          "<",    "_operator_less",                               OT_INFIX                        },
    48                         {       "?>?",          ">",    "_operator_greater",                    OT_INFIX                        },
    49                         {       "?<=?",         "<=",   "_operator_lessequal",                  OT_INFIX                        },
    50                         {       "?>=?",         ">=",   "_operator_greaterequal",               OT_INFIX                        },
    51                         {       "?==?",         "==",   "_operator_equal",                              OT_INFIX                        },
    52                         {       "?!=?",         "!=",   "_operator_notequal",                   OT_INFIX                        },
    53                         {       "?&?",          "&",    "_operator_bitand",                             OT_INFIX                        },
    54                         {       "?^?",          "^",    "_operator_bitxor",                             OT_INFIX                        },
    55                         {       "?|?",          "|",    "_operator_bitor",                              OT_INFIX                        },
    56                         {       "?=?",          "=",    "_operator_assign",                             OT_INFIXASSIGN          },
    57                         {       "?\\=?",        "\\=",  "_operator_expassign",                  OT_INFIXASSIGN          },
    58                         {       "?*=?",         "*=",   "_operator_multassign",                 OT_INFIXASSIGN          },
    59                         {       "?/=?",         "/=",   "_operator_divassign",                  OT_INFIXASSIGN          },
    60                         {       "?%=?",         "%=",   "_operator_modassign",                  OT_INFIXASSIGN          },
    61                         {       "?+=?",         "+=",   "_operator_addassign",                  OT_INFIXASSIGN          },
    62                         {       "?-=?",         "-=",   "_operator_subassign",                  OT_INFIXASSIGN          },
    63                         {       "?<<=?",        "<<=",  "_operator_shiftleftassign",    OT_INFIXASSIGN          },
    64                         {       "?>>=?",        ">>=",  "_operator_shiftrightassign",   OT_INFIXASSIGN          },
    65                         {       "?&=?",         "&=",   "_operator_bitandassign",               OT_INFIXASSIGN          },
    66                         {       "?^=?",         "^=",   "_operator_bitxorassign",               OT_INFIXASSIGN          },
    67                         {       "?|=?",         "|=",   "_operator_bitorassign",                OT_INFIXASSIGN          },
    68                 };
     25        const OperatorInfo CodeGen::tableValues[] = {
     26                // inputName symbol   outputName                     friendlyName                  type
     27                {       "?[?]",   "",     "_operator_index",             "Index",                      OT_INDEX          },
     28                {       "?{}",    "=",    "_constructor",                "Constructor",                OT_CTOR           },
     29                {       "^?{}",   "",     "_destructor",                 "Destructor",                 OT_DTOR           },
     30                {       "?()",    "",     "_operator_call",              "Call Operator",              OT_CALL           },
     31                {       "?++",    "++",   "_operator_postincr",          "Postfix Increment",          OT_POSTFIXASSIGN  },
     32                {       "?--",    "--",   "_operator_postdecr",          "Postfix Decrement",          OT_POSTFIXASSIGN  },
     33                {       "*?",     "*",    "_operator_deref",             "Dereference",                OT_PREFIX         },
     34                {       "+?",     "+",    "_operator_unaryplus",         "Plus",                       OT_PREFIX         },
     35                {       "-?",     "-",    "_operator_unaryminus",        "Minus",                      OT_PREFIX         },
     36                {       "~?",     "~",    "_operator_bitnot",            "Bitwise Not",                OT_PREFIX         },
     37                {       "!?",     "!",    "_operator_lognot",            "Logical Not",                OT_PREFIX         },
     38                {       "++?",    "++",   "_operator_preincr",           "Prefix Increment",           OT_PREFIXASSIGN   },
     39                {       "--?",    "--",   "_operator_predecr",           "Prefix Decrement",           OT_PREFIXASSIGN   },
     40                {       "?\\?",   "\\",   "_operator_exponential",       "Exponentiation",             OT_INFIX          },
     41                {       "?*?",    "*",    "_operator_multiply",          "Multiplication",             OT_INFIX          },
     42                {       "?/?",    "/",    "_operator_divide",            "Division",                   OT_INFIX          },
     43                {       "?%?",    "%",    "_operator_modulus",           "Modulo",                     OT_INFIX          },
     44                {       "?+?",    "+",    "_operator_add",               "Addition",                   OT_INFIX          },
     45                {       "?-?",    "-",    "_operator_subtract",          "Substraction",               OT_INFIX          },
     46                {       "?<<?",   "<<",   "_operator_shiftleft",         "Shift Left",                 OT_INFIX          },
     47                {       "?>>?",   ">>",   "_operator_shiftright",        "Shift Right",                OT_INFIX          },
     48                {       "?<?",    "<",    "_operator_less",              "Less-than",                  OT_INFIX          },
     49                {       "?>?",    ">",    "_operator_greater",           "Greater-than",               OT_INFIX          },
     50                {       "?<=?",   "<=",   "_operator_lessequal",         "Less-than-or-Equal",         OT_INFIX          },
     51                {       "?>=?",   ">=",   "_operator_greaterequal",      "Greater-than-or-Equal",      OT_INFIX          },
     52                {       "?==?",   "==",   "_operator_equal",             "Equality",                   OT_INFIX          },
     53                {       "?!=?",   "!=",   "_operator_notequal",          "Not-Equal",                  OT_INFIX          },
     54                {       "?&?",    "&",    "_operator_bitand",            "Bitwise And",                OT_INFIX          },
     55                {       "?^?",    "^",    "_operator_bitxor",            "Bitwise Xor",                OT_INFIX          },
     56                {       "?|?",    "|",    "_operator_bitor",             "Bitwise Or",                 OT_INFIX          },
     57                {       "?=?",    "=",    "_operator_assign",            "Assignment",                 OT_INFIXASSIGN    },
     58                {       "?\\=?",  "\\=",  "_operator_expassign",         "Exponentiation Assignment",  OT_INFIXASSIGN    },
     59                {       "?*=?",   "*=",   "_operator_multassign",        "Multiplication Assignment",  OT_INFIXASSIGN    },
     60                {       "?/=?",   "/=",   "_operator_divassign",         "Division Assignment",        OT_INFIXASSIGN    },
     61                {       "?%=?",   "%=",   "_operator_modassign",         "Modulo Assignment",          OT_INFIXASSIGN    },
     62                {       "?+=?",   "+=",   "_operator_addassign",         "Addition Assignment",        OT_INFIXASSIGN    },
     63                {       "?-=?",   "-=",   "_operator_subassign",         "Substrction Assignment",     OT_INFIXASSIGN    },
     64                {       "?<<=?",  "<<=",  "_operator_shiftleftassign",   "Shift Left Assignment",      OT_INFIXASSIGN    },
     65                {       "?>>=?",  ">>=",  "_operator_shiftrightassign",  "Shift Right Assignment",     OT_INFIXASSIGN    },
     66                {       "?&=?",   "&=",   "_operator_bitandassign",      "Bitwise And Assignment",     OT_INFIXASSIGN    },
     67                {       "?^=?",   "^=",   "_operator_bitxorassign",      "Bitwise Xor Assignment",     OT_INFIXASSIGN    },
     68                {       "?|=?",   "|=",   "_operator_bitorassign",       "Bitwise Or Assignment",      OT_INFIXASSIGN    },
     69        }; // tableValues
    6970
    70                 const int numOps = sizeof( tableValues ) / sizeof( OperatorInfo );
     71        std::map< std::string, OperatorInfo > CodeGen::table;
    7172
    72                 std::map< std::string, OperatorInfo > table;
    73 
    74                 void initialize() {
    75                         for ( int i = 0; i < numOps; ++i ) {
    76                                 table[ tableValues[i].inputName ] = tableValues[i];
    77                         } // for
    78                 }
    79         } // namespace
    80 
    81         bool operatorLookup( const std::string & funcName, OperatorInfo & info ) {
    82                 static bool init = false;
    83                 if ( ! init ) {
    84                         initialize();
    85                 } // if
    86 
    87                 std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName );
    88                 if ( i == table.end() ) {
    89                         if ( isPrefix( funcName, "?`" ) ) {
    90                                 // handle literal suffixes, which are user-defined postfix operators
    91                                 info.inputName = funcName;
    92                                 info.symbol = funcName.substr(2);
    93                                 info.outputName = toString( "__operator_literal_", info.symbol );
    94                                 info.type = OT_POSTFIX;
    95                                 return true;
    96                         }
    97                         return false;
    98                 } else {
    99                         info = i->second;
    100                         return true;
    101                 } // if
     73        CodeGen::CodeGen() {
     74                enum { numOps = sizeof( tableValues ) / sizeof( OperatorInfo ) };
     75                for ( int i = 0; i < numOps; i += 1 ) {
     76                        table[ tableValues[i].inputName ] = tableValues[i];
     77                } // for
    10278        }
    10379
    104         bool isOperator( const std::string & funcName ) {
    105                 OperatorInfo info;
    106                 return operatorLookup( funcName, info );
     80        const OperatorInfo * operatorLookup( const string & funcName ) {
     81                if ( funcName.find_first_of( "?^*+-!", 0, 1 ) == string::npos ) return nullptr; // prefilter
     82                const OperatorInfo * ret = &CodeGen::table.find( funcName )->second; // must be in the table
     83                assert( ret );
     84                return ret;
    10785        }
    10886
    109         /// determines if a given function name is one of the operator types between [begin, end)
    110         template<typename Iterator>
    111         bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) {
    112                 OperatorInfo info;
    113                 if ( operatorLookup( funcName, info ) ) {
    114                         return std::find( begin, end, info.type ) != end;
    115                 }
     87        bool isOperator( const string & funcName ) {
     88                return operatorLookup( funcName ) != nullptr;
     89        }
     90
     91        string operatorFriendlyName( const string & funcName ) {
     92                const OperatorInfo * info = operatorLookup( funcName );
     93                if ( info ) return info->friendlyName;
     94                return "";
     95        }
     96
     97        bool isConstructor( const string & funcName ) {
     98                const OperatorInfo * info = operatorLookup( funcName );
     99                if ( info ) return info->type == OT_CTOR;
    116100                return false;
    117101        }
    118102
    119         bool isConstructor( const std::string & funcName ) {
    120                 static OperatorType types[] = { OT_CTOR };
    121                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     103        bool isDestructor( const string & funcName ) {
     104                const OperatorInfo * info = operatorLookup( funcName );
     105                if ( info ) return info->type == OT_DTOR;
     106                return false;
    122107        }
    123108
    124         bool isDestructor( const std::string & funcName ) {
    125                 static OperatorType types[] = { OT_DTOR };
    126                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     109        bool isCtorDtor( const string & funcName ) {
     110                const OperatorInfo * info = operatorLookup( funcName );
     111                if ( info ) return info->type <= OT_CONSTRUCTOR;
     112                return false;
    127113        }
    128114
    129         bool isAssignment( const std::string & funcName ) {
    130                 static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN };
    131                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     115        bool isAssignment( const string & funcName ) {
     116                const OperatorInfo * info = operatorLookup( funcName );
     117                if ( info ) return info->type > OT_CONSTRUCTOR && info->type <= OT_ASSIGNMENT;
     118                return false;
    132119        }
    133120
    134         bool isCtorDtor( const std::string & funcName ) {
    135                 static OperatorType types[] = { OT_CTOR, OT_DTOR };
    136                 return isOperatorType( funcName, std::begin(types), std::end(types) );
     121        bool isCtorDtorAssign( const string & funcName ) {
     122                const OperatorInfo * info = operatorLookup( funcName );
     123                if ( info ) return info->type <= OT_ASSIGNMENT;
     124                return false;
    137125        }
    138126
    139         bool isCtorDtorAssign( const std::string & funcName ) {
    140                 static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN };
    141                 return isOperatorType( funcName, std::begin(types), std::end(types) );
    142         }
     127        CodeGen codegen;                                                                        // initialize singleton package
    143128} // namespace CodeGen
    144129
    145130// Local Variables: //
    146131// tab-width: 4 //
    147 // mode: c++ //
    148 // compile-command: "make install" //
    149132// End: //
  • src/CodeGen/OperatorTable.h

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:17:11 2017
    13 // Update Count     : 6
     12// Last Modified On : Sun Feb 16 08:13:34 2020
     13// Update Count     : 26
    1414//
    1515
     
    1717
    1818#include <string>
     19#include <map>
    1920
    2021namespace CodeGen {
    2122        enum OperatorType {
    22                 OT_INDEX,
    2323                OT_CTOR,
    2424                OT_DTOR,
    25                 OT_CALL,
    26                 OT_PREFIX,
    27                 OT_POSTFIX,
    28                 OT_INFIX,
     25                OT_CONSTRUCTOR = OT_DTOR,
    2926                OT_PREFIXASSIGN,
    3027                OT_POSTFIXASSIGN,
    3128                OT_INFIXASSIGN,
     29                OT_ASSIGNMENT = OT_INFIXASSIGN,
     30                OT_CALL,
     31                OT_PREFIX,
     32                OT_INFIX,
     33                OT_POSTFIX,
     34                OT_INDEX,
    3235                OT_LABELADDRESS,
    3336                OT_CONSTANT
     
    3841                std::string symbol;
    3942                std::string outputName;
     43                std::string friendlyName;
    4044                OperatorType type;
    4145        };
    4246
     47        class CodeGen {
     48                friend const OperatorInfo * operatorLookup( const std::string & funcName );
     49
     50                static const OperatorInfo tableValues[];
     51                static std::map< std::string, OperatorInfo > table;
     52          public:
     53                CodeGen();
     54        }; // CodeGen
     55
    4356        bool isOperator( const std::string & funcName );
    44         bool operatorLookup( const std::string & funcName, OperatorInfo & info );
     57        const OperatorInfo * operatorLookup( const std::string & funcName );
     58        std::string operatorFriendlyName( const std::string & funcName );
    4559
    4660        bool isConstructor( const std::string & );
  • src/CodeGen/Options.h

    r71d6bd8 r7030dab  
    99// Author           : Andrew Beach
    1010// Created On       : Tue Apr 30 11:36:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May  2 10:45:00 2019
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Feb 15 18:37:06 2020
     13// Update Count     : 3
    1414//
    1515
    1616#pragma once
    1717
    18 namespace CodeGen {
    19         struct Options {
    20                 // External Options: Same thoughout a pass.
    21                 bool pretty;
    22                 bool genC;
    23                 bool lineMarks;
    24                 bool printExprTypes;
     18struct Options {
     19        // External Options: Same thoughout a pass.
     20        bool pretty;
     21        bool genC;
     22        bool lineMarks;
     23        bool printExprTypes;
    2524
    26                 // Internal Options: Changed on some recurisive calls.
    27                 bool anonymousUnused = false;
     25        // Internal Options: Changed on some recurisive calls.
     26        bool anonymousUnused = false;
    2827
    29                 Options(bool pretty, bool genC, bool lineMarks, bool printExprTypes) :
    30                         pretty(pretty), genC(genC), lineMarks(lineMarks), printExprTypes(printExprTypes)
     28        Options(bool pretty, bool genC, bool lineMarks, bool printExprTypes) :
     29                pretty(pretty), genC(genC), lineMarks(lineMarks), printExprTypes(printExprTypes)
    3130                {}
    32         };
    33 } // namespace CodeGen
     31};
    3432
    3533// Local Variables: //
  • src/CodeGen/module.mk

    r71d6bd8 r7030dab  
    1111## Created On       : Mon Jun  1 17:49:17 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Tue Jun  2 11:17:02 2015
    14 ## Update Count     : 3
     13## Last Modified On : Sat Dec 14 07:29:42 2019
     14## Update Count     : 4
    1515###############################################################################
    1616
     
    2424        CodeGen/OperatorTable.cc
    2525
    26 
    2726SRC += $(SRC_CODEGEN) CodeGen/Generate.cc CodeGen/FixNames.cc
    2827SRCDEMANGLE += $(SRC_CODEGEN)
  • src/CodeTools/DeclStats.cc

    r71d6bd8 r7030dab  
    99// Author           : Aaron Moss
    1010// Created On       : Wed Jan 31 16:40:00 2016
    11 // Last Modified By : Aaron Moss
    12 // Last Modified On : Wed Jan 31 16:40:00 2016
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:39:33 2019
     13// Update Count     : 2
    1414//
    1515
     
    2626#include "Common/VectorMap.h"      // for VectorMap
    2727#include "GenPoly/GenPoly.h"       // for hasPolyBase
    28 #include "Parser/LinkageSpec.h"    // for ::NoOfSpecs, Spec
     28#include "SynTree/LinkageSpec.h"   // for ::NoOfSpecs, Spec
    2929#include "SynTree/Declaration.h"   // for FunctionDecl, TypeDecl, Declaration
    3030#include "SynTree/Expression.h"    // for UntypedExpr, Expression
  • src/CodeTools/ResolvProtoDump.cc

    r71d6bd8 r7030dab  
    99// Author           : Aaron Moss
    1010// Created On       : Tue Sep 11 09:04:00 2018
    11 // Last Modified By : Aaron Moss
    12 // Last Modified On : Tue Sep 11 09:04:00 2018
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Feb 15 13:50:11 2020
     13// Update Count     : 3
    1414//
    1515
     
    182182
    183183                        // replace operator names
    184                         CodeGen::OperatorInfo info;
    185                         if ( CodeGen::operatorLookup( name, info ) ) {
     184                        const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( name );
     185                        if ( opInfo ) {
    186186                                ss << new_prefix(pre, "");
    187                                 op_name( info.outputName, ss );
     187                                op_name( opInfo->outputName, ss );
    188188                                return;
    189189                        }
  • src/Common/Debug.h

    r71d6bd8 r7030dab  
    99// Author           : Rob Schluntz
    1010// Created On       : Fri Sep 1 11:09:14 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Sep 1 11:09:36 2017
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:39:42 2019
     13// Update Count     : 3
    1414//
    1515
     
    2121
    2222#include "CodeGen/Generate.h"
    23 #include "Parser/LinkageSpec.h"
     23#include "SynTree/LinkageSpec.h"
    2424#include "SynTree/Declaration.h"
    2525
  • src/Common/PassVisitor.h

    r71d6bd8 r7030dab  
    110110        virtual void visit( FinallyStmt * finallyStmt ) override final;
    111111        virtual void visit( const FinallyStmt * finallyStmt ) override final;
     112        virtual void visit( SuspendStmt * suspendStmt ) override final;
     113        virtual void visit( const SuspendStmt * suspendStmt ) override final;
    112114        virtual void visit( WaitForStmt * waitforStmt ) override final;
    113115        virtual void visit( const WaitForStmt * waitforStmt ) override final;
     
    276278        virtual Statement * mutate( CatchStmt * catchStmt ) override final;
    277279        virtual Statement * mutate( FinallyStmt * finallyStmt ) override final;
     280        virtual Statement * mutate( SuspendStmt * suspendStmt ) override final;
    278281        virtual Statement * mutate( WaitForStmt * waitforStmt ) override final;
    279282        virtual Declaration * mutate( WithStmt * withStmt ) override final;
  • src/Common/PassVisitor.impl.h

    r71d6bd8 r7030dab  
    15221522
    15231523//--------------------------------------------------------------------------
     1524// SuspendStmt
     1525template< typename pass_type >
     1526void PassVisitor< pass_type >::visit( SuspendStmt * node ) {
     1527        VISIT_START( node );
     1528
     1529        maybeAccept_impl( node->then  , *this );
     1530
     1531        VISIT_END( node );
     1532}
     1533
     1534template< typename pass_type >
     1535void PassVisitor< pass_type >::visit( const SuspendStmt * node ) {
     1536        VISIT_START( node );
     1537
     1538        maybeAccept_impl( node->then  , *this );
     1539
     1540        VISIT_END( node );
     1541}
     1542
     1543template< typename pass_type >
     1544Statement * PassVisitor< pass_type >::mutate( SuspendStmt * node ) {
     1545        MUTATE_START( node );
     1546
     1547        maybeMutate_impl( node->then  , *this );
     1548
     1549        MUTATE_END( Statement, node );
     1550}
     1551
     1552//--------------------------------------------------------------------------
    15241553// WaitForStmt
    15251554template< typename pass_type >
     
    33023331        VISIT_START( node );
    33033332
    3304         indexerAddStruct( node->name );
     3333        indexerAddUnion( node->name );
    33053334
    33063335        {
     
    33173346        VISIT_START( node );
    33183347
    3319         indexerAddStruct( node->name );
     3348        indexerAddUnion( node->name );
    33203349
    33213350        {
     
    33323361        MUTATE_START( node );
    33333362
    3334         indexerAddStruct( node->name );
     3363        indexerAddUnion( node->name );
    33353364
    33363365        {
  • src/Common/SemanticError.cc

    r71d6bd8 r7030dab  
    149149// Helpers
    150150namespace ErrorHelpers {
     151        Colors colors = Colors::Auto;
     152
     153        static inline bool with_colors() {
     154                return colors == Colors::Auto ? isatty( STDERR_FILENO ) : bool(colors);
     155        }
     156
    151157        const std::string & error_str() {
    152                 static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
     158                static std::string str = with_colors() ? "\e[31merror:\e[39m " : "error: ";
    153159                return str;
    154160        }
    155161
    156162        const std::string & warning_str() {
    157                 static std::string str = isatty( STDERR_FILENO ) ? "\e[95mwarning:\e[39m " : "warning: ";
     163                static std::string str = with_colors() ? "\e[95mwarning:\e[39m " : "warning: ";
    158164                return str;
    159165        }
    160166
    161167        const std::string & bold_ttycode() {
    162                 static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : "";
     168                static std::string str = with_colors() ? "\e[1m" : "";
    163169                return str;
    164170        }
    165171
    166172        const std::string & reset_font_ttycode() {
    167                 static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";
     173                static std::string str = with_colors() ? "\e[0m" : "";
    168174                return str;
    169175        }
  • src/Common/SemanticError.h

    r71d6bd8 r7030dab  
    4949struct WarningData {
    5050        const char * const name;
     51        const Severity default_severity;
    5152        const char * const message;
    52         const Severity default_severity;
    5353};
    5454
    5555constexpr WarningData WarningFormats[] = {
    56         {"self-assign"            , "self assignment of expression: %s"            , Severity::Warn},
    57         {"reference-conversion"   , "rvalue to reference conversion of rvalue: %s" , Severity::Warn},
    58         {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
    59         {"aggregate-forward-decl" , "forward declaration of nested aggregate: %s"  , Severity::Warn},
    60         {"superfluous-decl"       , "declaration does not allocate storage: %s"    , Severity::Warn},
    61         {"gcc-attributes"         , "invalid attribute: %s"                        , Severity::Warn},
     56        {"self-assign"            , Severity::Warn    , "self assignment of expression: %s"                          },
     57        {"reference-conversion"   , Severity::Warn    , "rvalue to reference conversion of rvalue: %s"               },
     58        {"qualifiers-zero_t-one_t", Severity::Warn    , "questionable use of type qualifier %s with %s"              },
     59        {"aggregate-forward-decl" , Severity::Warn    , "forward declaration of nested aggregate: %s"                },
     60        {"superfluous-decl"       , Severity::Warn    , "declaration does not allocate storage: %s"                  },
     61        {"gcc-attributes"         , Severity::Warn    , "invalid attribute: %s"                                      },
     62        {"c++-like-copy"          , Severity::Warn    , "Constructor from reference is not a valid copy constructor" },
    6263};
    6364
     
    6970        SuperfluousDecl,
    7071        GccAttributes,
     72        CppCopy,
    7173        NUMBER_OF_WARNINGS, // This MUST be the last warning
    7274};
     
    9799// Helpers
    98100namespace ErrorHelpers {
     101        enum class Colors {
     102                Never = false,
     103                Always = true,
     104                Auto,
     105        };
     106
     107        extern Colors colors;
     108
    99109        const std::string & error_str();
    100110        const std::string & warning_str();
  • src/Common/Stats/Time.h

    r71d6bd8 r7030dab  
    99// Author           : Thierry Delisle
    1010// Created On       : Fri Mar 01 15:14:11 2019
    11 // Last Modified By :
     11// Last Modified By : Andrew Beach
    1212// Last Modified On :
    1313// Update Count     :
     
    4141                                f();
    4242                        }
     43
     44                        template<typename ret_t = void, typename func_t, typename... arg_t>
     45                        inline ret_t TimeCall(
     46                                        const char *, func_t func, arg_t&&... arg) {
     47                                return func(std::forward<arg_t>(arg)...);
     48                        }
    4349#               else
    4450                        void StartGlobal();
     
    5965                                func();
    6066                        }
     67
     68                        template<typename ret_t = void, typename func_t, typename... arg_t>
     69                        inline ret_t TimeCall(
     70                                        const char * name, func_t func, arg_t&&... arg) {
     71                                BlockGuard guard(name);
     72                                return func(std::forward<arg_t>(arg)...);
     73                        }
    6174#               endif
    6275        }
  • src/Common/utility.h

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 24 14:28:19 2019
    13 // Update Count     : 41
     12// Last Modified On : Tue Feb 11 13:00:36 2020
     13// Update Count     : 50
    1414//
    1515
     
    2929#include <utility>
    3030#include <vector>
     31#include <cstring>                                                                              // memcmp
    3132
    3233#include "Common/Indenter.h"
     
    264265}
    265266
    266 /// determines if `pref` is a prefix of `str`
    267 static inline bool isPrefix( const std::string & str, const std::string & pref ) {
     267// determines if pref is a prefix of str
     268static inline bool isPrefix( const std::string & str, const std::string & pref, unsigned int start = 0 ) {
    268269        if ( pref.size() > str.size() ) return false;
    269         auto its = std::mismatch( pref.begin(), pref.end(), str.begin() );
    270         return its.first == pref.end();
     270    return 0 == memcmp( str.c_str() + start, pref.c_str(), pref.size() );
     271        // return prefix == full.substr(0, prefix.size()); // for future, requires c++17
    271272}
    272273
  • src/Concurrency/Keywords.cc

    r71d6bd8 r7030dab  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 5
     13// Update Count     : 10
    1414//
    1515
    1616#include "Concurrency/Keywords.h"
    1717
    18 #include <cassert>                 // for assert
    19 #include <string>                  // for string, operator==
    20 
    21 #include "Common/PassVisitor.h"    // for PassVisitor
    22 #include "Common/SemanticError.h"  // for SemanticError
    23 #include "Common/utility.h"        // for deleteAll, map_range
    24 #include "CodeGen/OperatorTable.h" // for isConstructor
    25 #include "InitTweak/InitTweak.h"   // for getPointerBase
    26 #include "Parser/LinkageSpec.h"    // for Cforall
    27 #include "SynTree/Constant.h"      // for Constant
    28 #include "SynTree/Declaration.h"   // for StructDecl, FunctionDecl, ObjectDecl
    29 #include "SynTree/Expression.h"    // for VariableExpr, ConstantExpr, Untype...
    30 #include "SynTree/Initializer.h"   // for SingleInit, ListInit, Initializer ...
    31 #include "SynTree/Label.h"         // for Label
    32 #include "SynTree/Statement.h"     // for CompoundStmt, DeclStmt, ExprStmt
    33 #include "SynTree/Type.h"          // for StructInstType, Type, PointerType
    34 #include "SynTree/Visitor.h"       // for Visitor, acceptAll
     18#include <cassert>                        // for assert
     19#include <string>                         // for string, operator==
     20
     21#include "Common/PassVisitor.h"           // for PassVisitor
     22#include "Common/SemanticError.h"         // for SemanticError
     23#include "Common/utility.h"               // for deleteAll, map_range
     24#include "CodeGen/OperatorTable.h"        // for isConstructor
     25#include "ControlStruct/LabelGenerator.h" // for LebelGenerator
     26#include "InitTweak/InitTweak.h"          // for getPointerBase
     27#include "SynTree/LinkageSpec.h"          // for Cforall
     28#include "SynTree/Constant.h"             // for Constant
     29#include "SynTree/Declaration.h"          // for StructDecl, FunctionDecl, ObjectDecl
     30#include "SynTree/Expression.h"           // for VariableExpr, ConstantExpr, Untype...
     31#include "SynTree/Initializer.h"          // for SingleInit, ListInit, Initializer ...
     32#include "SynTree/Label.h"                // for Label
     33#include "SynTree/Statement.h"            // for CompoundStmt, DeclStmt, ExprStmt
     34#include "SynTree/Type.h"                 // for StructInstType, Type, PointerType
     35#include "SynTree/Visitor.h"              // for Visitor, acceptAll
    3536
    3637class Attribute;
     
    5354          public:
    5455
    55                 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) :
     56                ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate cast_target ) :
    5657                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {}
    5758
     
    5960
    6061                Declaration * postmutate( StructDecl * decl );
     62                DeclarationWithType * postmutate( FunctionDecl * decl );
    6163
    6264                void handle( StructDecl * );
     
    7577                const std::string context_error;
    7678                bool needs_main;
    77                 KeywordCastExpr::Target cast_target;
    78 
    79                 StructDecl* type_decl = nullptr;
     79                AggregateDecl::Aggregate cast_target;
     80
     81                StructDecl   * type_decl = nullptr;
     82                FunctionDecl * dtor_decl = nullptr;
    8083        };
    8184
     
    8689        //      int data;                                  int data;
    8790        //      a_struct_t more_data;                      a_struct_t more_data;
    88         //                                =>             thread_desc __thrd_d;
     91        //                                =>             $thread __thrd_d;
    8992        // };                                        };
    90         //                                           static inline thread_desc * get_thread( MyThread * this ) { return &this->__thrd_d; }
     93        //                                           static inline $thread * get_thread( MyThread * this ) { return &this->__thrd_d; }
    9194        //
    9295        class ThreadKeyword final : public ConcurrentSueKeyword {
     
    9497
    9598                ThreadKeyword() : ConcurrentSueKeyword(
    96                         "thread_desc",
     99                        "$thread",
    97100                        "__thrd",
    98101                        "get_thread",
    99                         "thread keyword requires threads to be in scope, add #include <thread.hfa>",
     102                        "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
    100103                        true,
    101                         KeywordCastExpr::Thread
     104                        AggregateDecl::Thread
    102105                )
    103106                {}
     
    118121        //      int data;                                  int data;
    119122        //      a_struct_t more_data;                      a_struct_t more_data;
    120         //                                =>             coroutine_desc __cor_d;
     123        //                                =>             $coroutine __cor_d;
    121124        // };                                        };
    122         //                                           static inline coroutine_desc * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
     125        //                                           static inline $coroutine * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
    123126        //
    124127        class CoroutineKeyword final : public ConcurrentSueKeyword {
     
    126129
    127130                CoroutineKeyword() : ConcurrentSueKeyword(
    128                         "coroutine_desc",
     131                        "$coroutine",
    129132                        "__cor",
    130133                        "get_coroutine",
    131                         "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>",
     134                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n",
    132135                        true,
    133                         KeywordCastExpr::Coroutine
     136                        AggregateDecl::Coroutine
    134137                )
    135138                {}
     
    144147                }
    145148        };
     149
     150
    146151
    147152        //-----------------------------------------------------------------------------
     
    150155        //      int data;                                  int data;
    151156        //      a_struct_t more_data;                      a_struct_t more_data;
    152         //                                =>             monitor_desc __mon_d;
     157        //                                =>             $monitor __mon_d;
    153158        // };                                        };
    154         //                                           static inline monitor_desc * get_coroutine( MyMonitor * this ) { return &this->__cor_d; }
     159        //                                           static inline $monitor * get_coroutine( MyMonitor * this ) { return &this->__cor_d; }
    155160        //
    156161        class MonitorKeyword final : public ConcurrentSueKeyword {
     
    158163
    159164                MonitorKeyword() : ConcurrentSueKeyword(
    160                         "monitor_desc",
     165                        "$monitor",
    161166                        "__mon",
    162167                        "get_monitor",
    163                         "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>",
     168                        "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n",
    164169                        false,
    165                         KeywordCastExpr::Monitor
     170                        AggregateDecl::Monitor
    166171                )
    167172                {}
     
    178183
    179184        //-----------------------------------------------------------------------------
     185        //Handles generator type declarations :
     186        // generator MyGenerator {                   struct MyGenerator {
     187        //      int data;                                  int data;
     188        //      a_struct_t more_data;                      a_struct_t more_data;
     189        //                                =>             int __gen_next;
     190        // };                                        };
     191        //
     192        class GeneratorKeyword final : public ConcurrentSueKeyword {
     193          public:
     194
     195                GeneratorKeyword() : ConcurrentSueKeyword(
     196                        "$generator",
     197                        "__generator_state",
     198                        "get_generator",
     199                        "Unable to find builtin type $generator\n",
     200                        true,
     201                        AggregateDecl::Generator
     202                )
     203                {}
     204
     205                virtual ~GeneratorKeyword() {}
     206
     207                virtual bool is_target( StructDecl * decl ) override final { return decl->is_generator(); }
     208
     209                static void implement( std::list< Declaration * > & translationUnit ) {
     210                        PassVisitor< GeneratorKeyword > impl;
     211                        mutateAll( translationUnit, impl );
     212                }
     213        };
     214
     215
     216        //-----------------------------------------------------------------------------
     217        class SuspendKeyword final : public WithStmtsToAdd, public WithGuards {
     218        public:
     219                SuspendKeyword() = default;
     220                virtual ~SuspendKeyword() = default;
     221
     222                void  premutate( FunctionDecl * );
     223                DeclarationWithType * postmutate( FunctionDecl * );
     224
     225                Statement * postmutate( SuspendStmt * );
     226
     227                static void implement( std::list< Declaration * > & translationUnit ) {
     228                        PassVisitor< SuspendKeyword > impl;
     229                        mutateAll( translationUnit, impl );
     230                }
     231
     232        private:
     233                DeclarationWithType * is_main( FunctionDecl * );
     234                bool is_real_suspend( FunctionDecl * );
     235
     236                Statement * make_generator_suspend( SuspendStmt * );
     237                Statement * make_coroutine_suspend( SuspendStmt * );
     238
     239                struct LabelPair {
     240                        Label obj;
     241                        int   idx;
     242                };
     243
     244                LabelPair make_label() {
     245                        labels.push_back( gen.newLabel("generator") );
     246                        return { labels.back(), int(labels.size()) };
     247                }
     248
     249                DeclarationWithType * in_generator = nullptr;
     250                FunctionDecl * decl_suspend = nullptr;
     251                std::vector<Label> labels;
     252                ControlStruct::LabelGenerator & gen = *ControlStruct::LabelGenerator::getGenerator();
     253        };
     254
     255        //-----------------------------------------------------------------------------
    180256        //Handles mutex routines definitions :
    181257        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    182         //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     258        //                                                                       $monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    183259        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    184260        //    /*Some code*/                                       =>           /*Some code*/
     
    219295        //Handles mutex routines definitions :
    220296        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    221         //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     297        //                                                                       $monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    222298        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    223299        //    /*Some code*/                                       =>           /*Some code*/
     
    249325                CoroutineKeyword        ::implement( translationUnit );
    250326                MonitorKeyword  ::implement( translationUnit );
     327                GeneratorKeyword  ::implement( translationUnit );
     328                SuspendKeyword    ::implement( translationUnit );
    251329        }
    252330
     
    284362        }
    285363
     364        DeclarationWithType * ConcurrentSueKeyword::postmutate( FunctionDecl * decl ) {
     365                if( !type_decl ) return decl;
     366                if( !CodeGen::isDestructor( decl->name ) ) return decl;
     367
     368                auto params = decl->type->parameters;
     369                if( params.size() != 1 ) return decl;
     370
     371                auto type = dynamic_cast<ReferenceType*>( params.front()->get_type() );
     372                if( !type ) return decl;
     373
     374                auto stype = dynamic_cast<StructInstType*>( type->base );
     375                if( !stype ) return decl;
     376                if( stype->baseStruct != type_decl ) return decl;
     377
     378                if( !dtor_decl ) dtor_decl = decl;
     379                return decl;
     380        }
     381
    286382        Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) {
    287383                if ( cast_target == cast->target ) {
    288                         // convert (thread &)t to (thread_desc &)*get_thread(t), etc.
     384                        // convert (thread &)t to ($thread &)*get_thread(t), etc.
    289385                        if( !type_decl ) SemanticError( cast, context_error );
    290                         Expression * arg = cast->arg;
    291                         cast->arg = nullptr;
    292                         delete cast;
    293                         return new CastExpr(
    294                                 UntypedExpr::createDeref(
    295                                         new UntypedExpr( new NameExpr( getter_name ), { arg } )
    296                                 ),
    297                                 new ReferenceType(
    298                                         noQualifiers,
    299                                         new StructInstType( noQualifiers, type_decl ) )
    300                                 );
     386                        if( !dtor_decl ) SemanticError( cast, context_error );
     387                        assert( cast->result == nullptr );
     388                        cast->set_result( new ReferenceType( noQualifiers, new StructInstType( noQualifiers, type_decl ) ) );
     389                        cast->concrete_target.field  = field_name;
     390                        cast->concrete_target.getter = getter_name;
    301391                }
    302392                return cast;
     
    308398
    309399                if( !type_decl ) SemanticError( decl, context_error );
     400                if( !dtor_decl ) SemanticError( decl, context_error );
    310401
    311402                FunctionDecl * func = forwardDeclare( decl );
     
    362453                        get_type,
    363454                        nullptr,
    364                         noAttributes,
     455                        { new Attribute("const") },
    365456                        Type::Inline
    366457                );
     
    431522
    432523                declsToAddAfter.push_back( get_decl );
    433 
    434                 // get_decl->fixUniqueId();
    435         }
     524        }
     525
     526        //=============================================================================================
     527        // Suspend keyword implementation
     528        //=============================================================================================
     529        DeclarationWithType * SuspendKeyword::is_main( FunctionDecl * func) {
     530                if(func->name != "main") return nullptr;
     531                if(func->type->parameters.size() != 1) return nullptr;
     532
     533                auto param = func->type->parameters.front();
     534
     535                auto type  = dynamic_cast<ReferenceType * >(param->get_type());
     536                if(!type) return nullptr;
     537
     538                auto obj   = dynamic_cast<StructInstType *>(type->base);
     539                if(!obj) return nullptr;
     540
     541                if(!obj->baseStruct->is_generator()) return nullptr;
     542
     543                return param;
     544        }
     545
     546        bool SuspendKeyword::is_real_suspend( FunctionDecl * func ) {
     547                if(isMangled(func->linkage)) return false; // the real suspend isn't mangled
     548                if(func->name != "__cfactx_suspend") return false; // the real suspend has a specific name
     549                if(func->type->parameters.size() != 0) return false; // Too many parameters
     550                if(func->type->returnVals.size() != 0) return false; // Too many return values
     551
     552                return true;
     553        }
     554
     555        void SuspendKeyword::premutate( FunctionDecl * func ) {
     556                GuardValue(in_generator);
     557                in_generator = nullptr;
     558
     559                // Is this the real suspend?
     560                if(is_real_suspend(func)) {
     561                        decl_suspend = decl_suspend ? decl_suspend : func;
     562                        return;
     563                }
     564
     565                // Is this the main of a generator?
     566                auto param = is_main( func );
     567                if(!param) return;
     568
     569                if(func->type->returnVals.size() != 0) SemanticError(func->location, "Generator main must return void");
     570
     571                in_generator = param;
     572                GuardValue(labels);
     573                labels.clear();
     574        }
     575
     576        DeclarationWithType * SuspendKeyword::postmutate( FunctionDecl * func ) {
     577                if( !func->statements ) return func; // Not the actual definition, don't do anything
     578                if( !in_generator     ) return func; // Not in a generator, don't do anything
     579                if( labels.empty()    ) return func; // Generator has no states, nothing to do, could throw a warning
     580
     581                // This is a generator main, we need to add the following code to the top
     582                // static void * __generator_labels[] = {&&s0, &&s1, ...};
     583                // goto * __generator_labels[gen.__generator_state];
     584                const auto & loc = func->location;
     585
     586                const auto first_label = gen.newLabel("generator");
     587
     588                // for each label add to declaration
     589                std::list<Initializer*> inits = { new SingleInit( new LabelAddressExpr( first_label ) ) };
     590                for(const auto & label : labels) {
     591                        inits.push_back(
     592                                new SingleInit(
     593                                        new LabelAddressExpr( label )
     594                                )
     595                        );
     596                }
     597                auto init = new ListInit(std::move(inits), noDesignators, true);
     598                labels.clear();
     599
     600                // create decl
     601                auto decl = new ObjectDecl(
     602                        "__generator_labels",
     603                        Type::StorageClasses( Type::Static ),
     604                        LinkageSpec::AutoGen,
     605                        nullptr,
     606                        new ArrayType(
     607                                Type::Qualifiers(),
     608                                new PointerType(
     609                                        Type::Qualifiers(),
     610                                        new VoidType( Type::Qualifiers() )
     611                                ),
     612                                nullptr,
     613                                false, false
     614                        ),
     615                        init
     616                );
     617
     618                // create the goto
     619                assert(in_generator);
     620
     621                auto go_decl = new ObjectDecl(
     622                        "__generator_label",
     623                        noStorageClasses,
     624                        LinkageSpec::AutoGen,
     625                        nullptr,
     626                        new PointerType(
     627                                Type::Qualifiers(),
     628                                new VoidType( Type::Qualifiers() )
     629                        ),
     630                        new SingleInit(
     631                                new UntypedExpr(
     632                                        new NameExpr("?[?]"),
     633                                        {
     634                                                new NameExpr("__generator_labels"),
     635                                                new UntypedMemberExpr(
     636                                                        new NameExpr("__generator_state"),
     637                                                        new VariableExpr( in_generator )
     638                                                )
     639                                        }
     640                                )
     641                        )
     642                );
     643                go_decl->location = loc;
     644
     645                auto go = new BranchStmt(
     646                        new VariableExpr( go_decl ),
     647                        BranchStmt::Goto
     648                );
     649                go->location = loc;
     650                go->computedTarget->location = loc;
     651
     652                auto noop = new NullStmt({ first_label });
     653                noop->location = loc;
     654
     655                // wrap everything in a nice compound
     656                auto body = new CompoundStmt({
     657                        new DeclStmt( decl ),
     658                        new DeclStmt( go_decl ),
     659                        go,
     660                        noop,
     661                        func->statements
     662                });
     663                body->location   = loc;
     664                func->statements = body;
     665
     666                return func;
     667        }
     668
     669        Statement * SuspendKeyword::postmutate( SuspendStmt * stmt ) {
     670                SuspendStmt::Type type = stmt->type;
     671                if(type == SuspendStmt::None) {
     672                        // This suspend has a implicit target, find it
     673                        type = in_generator ? SuspendStmt::Generator : SuspendStmt::Coroutine;
     674                }
     675
     676                // Check that the target makes sense
     677                if(!in_generator && type == SuspendStmt::Generator) SemanticError( stmt->location, "'suspend generator' must be used inside main of generator type.");
     678
     679                // Act appropriately
     680                switch(type) {
     681                        case SuspendStmt::Generator: return make_generator_suspend(stmt);
     682                        case SuspendStmt::Coroutine: return make_coroutine_suspend(stmt);
     683                        default: abort();
     684                }
     685        }
     686
     687        Statement * SuspendKeyword::make_generator_suspend( SuspendStmt * stmt ) {
     688                assert(in_generator);
     689                // Target code is :
     690                //   gen.__generator_state = X;
     691                //   { THEN }
     692                //   return;
     693                //   __gen_X:;
     694
     695                // Save the location and delete the old statement, we only need the location from this point on
     696                auto loc = stmt->location;
     697
     698                // Build the label and get its index
     699                auto label = make_label();
     700
     701                // Create the context saving statement
     702                auto save = new ExprStmt( new UntypedExpr(
     703                        new NameExpr( "?=?" ),
     704                        {
     705                                new UntypedMemberExpr(
     706                                        new NameExpr("__generator_state"),
     707                                        new VariableExpr( in_generator )
     708                                ),
     709                                new ConstantExpr(
     710                                        Constant::from_int( label.idx )
     711                                )
     712                        }
     713                ));
     714                assert(save->expr);
     715                save->location = loc;
     716                stmtsToAddBefore.push_back( save );
     717
     718                // if we have a then add it here
     719                auto then = stmt->then;
     720                stmt->then = nullptr;
     721                delete stmt;
     722                if(then) stmtsToAddBefore.push_back( then );
     723
     724                // Create the return statement
     725                auto ret = new ReturnStmt( nullptr );
     726                ret->location = loc;
     727                stmtsToAddBefore.push_back( ret );
     728
     729                // Create the null statement with the created label
     730                auto noop = new NullStmt({ label.obj });
     731                noop->location = loc;
     732
     733                // Return the null statement to take the place of the previous statement
     734                return noop;
     735        }
     736
     737        Statement * SuspendKeyword::make_coroutine_suspend( SuspendStmt * stmt ) {
     738                if(stmt->then) SemanticError( stmt->location, "Compound statement following coroutines is not implemented.");
     739
     740                // Save the location and delete the old statement, we only need the location from this point on
     741                auto loc = stmt->location;
     742                delete stmt;
     743
     744                // Create the call expression
     745                if(!decl_suspend) SemanticError( loc, "suspend keyword applied to coroutines requires coroutines to be in scope, add #include <coroutine.hfa>\n");
     746                auto expr = new UntypedExpr( VariableExpr::functionPointer( decl_suspend ) );
     747                expr->location = loc;
     748
     749                // Change this statement into a regular expr
     750                assert(expr);
     751                auto nstmt = new ExprStmt( expr );
     752                nstmt->location = loc;
     753                return nstmt;
     754        }
     755
    436756
    437757        //=============================================================================================
     
    501821        void MutexKeyword::postvisit(StructDecl* decl) {
    502822
    503                 if( decl->name == "monitor_desc" && decl->body ) {
     823                if( decl->name == "$monitor" && decl->body ) {
    504824                        assert( !monitor_decl );
    505825                        monitor_decl = decl;
     
    597917                );
    598918
    599                 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     919                //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    600920                body->push_front( new DeclStmt( monitors) );
    601921        }
     
    658978                );
    659979
    660                 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     980                //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    661981                body->push_front( new DeclStmt( monitors) );
    662982        }
     
    666986        //=============================================================================================
    667987        void ThreadStarter::previsit( StructDecl * decl ) {
    668                 if( decl->name == "thread_desc" && decl->body ) {
     988                if( decl->name == "$thread" && decl->body ) {
    669989                        assert( !thread_decl );
    670990                        thread_decl = decl;
     
    7011021                                new UntypedExpr(
    7021022                                        new NameExpr( "__thrd_start" ),
    703                                         { new VariableExpr( param ) }
     1023                                        { new VariableExpr( param ), new NameExpr("main") }
    7041024                                )
    7051025                        )
  • src/Concurrency/Waitfor.cc

    r71d6bd8 r7030dab  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 7
     13// Update Count     : 12
    1414//
    1515
     
    2323#include "Common/PassVisitor.h"    // for PassVisitor
    2424#include "Common/SemanticError.h"  // for SemanticError
     25#include "Common/UniqueName.h"     // for UniqueName
    2526#include "Common/utility.h"        // for deleteAll, map_range
    2627#include "CodeGen/OperatorTable.h" // for isConstructor
    2728#include "InitTweak/InitTweak.h"   // for getPointerBase
    28 #include "Parser/LinkageSpec.h"    // for Cforall
    2929#include "ResolvExpr/Resolver.h"   // for findVoidExpression
     30#include "SynTree/LinkageSpec.h"   // for Cforall
    3031#include "SynTree/Constant.h"      // for Constant
    3132#include "SynTree/Declaration.h"   // for StructDecl, FunctionDecl, ObjectDecl
     
    4142void foo() {
    4243        while( true ) {
    43                 when( a < 1 ) waitfor( f, a ) { bar(); }
     44                when( a < 1 ) waitfor( f : a ) { bar(); }
    4445                or timeout( swagl() );
    45                 or waitfor( g, a ) { baz(); }
    46                 or waitfor( ^?{}, a ) { break; }
     46                or waitfor( g : a ) { baz(); }
     47                or waitfor( ^?{} : a ) { break; }
    4748                or waitfor( ^?{} ) { break; }
    4849        }
     
    243244                        decl_mask = decl;
    244245                }
    245                 else if( decl->name == "monitor_desc" ) {
     246                else if( decl->name == "$monitor" ) {
    246247                        assert( !decl_monitor );
    247248                        decl_monitor = decl;
  • src/ControlStruct/ExceptTranslate.cc

    r71d6bd8 r7030dab  
    99// Author           : Andrew Beach
    1010// Created On       : Wed Jun 14 16:49:00 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 18:15:29 2019
    13 // Update Count     : 11
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Mar 27 11:58:00 2020
     13// Update Count     : 13
    1414//
    1515
     
    2424#include "Common/SemanticError.h"     // for SemanticError
    2525#include "Common/utility.h"           // for CodeLocation
    26 #include "Parser/LinkageSpec.h"       // for Cforall
     26#include "SynTree/LinkageSpec.h"      // for Cforall
    2727#include "SynTree/Attribute.h"        // for Attribute
    2828#include "SynTree/Constant.h"         // for Constant
     
    211211                        ThrowStmt *throwStmt ) {
    212212                // __throw_terminate( `throwStmt->get_name()` ); }
    213                 return create_given_throw( "__cfaabi_ehm__throw_terminate", throwStmt );
     213                return create_given_throw( "__cfaehm_throw_terminate", throwStmt );
    214214        }
    215215
     
    232232                        ) ) );
    233233                result->push_back( new ExprStmt(
    234                         new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) )
     234                        new UntypedExpr( new NameExpr( "__cfaehm_rethrow_terminate" ) )
    235235                        ) );
    236236                delete throwStmt;
     
    241241                        ThrowStmt *throwStmt ) {
    242242                // __throw_resume( `throwStmt->get_name` );
    243                 return create_given_throw( "__cfaabi_ehm__throw_resume", throwStmt );
     243                return create_given_throw( "__cfaehm_throw_resume", throwStmt );
    244244        }
    245245
     
    309309                        local_except->get_attributes().push_back( new Attribute(
    310310                                "cleanup",
    311                                 { new NameExpr( "__cfaabi_ehm__cleanup_terminate" ) }
     311                                { new NameExpr( "__cfaehm_cleanup_terminate" ) }
    312312                                ) );
    313313
     
    429429                        FunctionDecl * terminate_catch,
    430430                        FunctionDecl * terminate_match ) {
    431                 // { __cfaabi_ehm__try_terminate(`try`, `catch`, `match`); }
     431                // { __cfaehm_try_terminate(`try`, `catch`, `match`); }
    432432
    433433                UntypedExpr * caller = new UntypedExpr( new NameExpr(
    434                         "__cfaabi_ehm__try_terminate" ) );
     434                        "__cfaehm_try_terminate" ) );
    435435                std::list<Expression *>& args = caller->get_args();
    436436                args.push_back( nameOf( try_wrapper ) );
     
    486486
    487487                // struct __try_resume_node __resume_node
    488                 //      __attribute__((cleanup( __cfaabi_ehm__try_resume_cleanup )));
     488                //      __attribute__((cleanup( __cfaehm_try_resume_cleanup )));
    489489                // ** unwinding of the stack here could cause problems **
    490490                // ** however I don't think that can happen currently **
    491                 // __cfaabi_ehm__try_resume_setup( &__resume_node, resume_handler );
     491                // __cfaehm_try_resume_setup( &__resume_node, resume_handler );
    492492
    493493                std::list< Attribute * > attributes;
     
    495495                        std::list< Expression * > attr_params;
    496496                        attr_params.push_back( new NameExpr(
    497                                 "__cfaabi_ehm__try_resume_cleanup" ) );
     497                                "__cfaehm_try_resume_cleanup" ) );
    498498                        attributes.push_back( new Attribute( "cleanup", attr_params ) );
    499499                }
     
    514514
    515515                UntypedExpr *setup = new UntypedExpr( new NameExpr(
    516                         "__cfaabi_ehm__try_resume_setup" ) );
     516                        "__cfaehm_try_resume_setup" ) );
    517517                setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) );
    518518                setup->get_args().push_back( nameOf( resume_handler ) );
     
    539539        ObjectDecl * ExceptionMutatorCore::create_finally_hook(
    540540                        FunctionDecl * finally_wrapper ) {
    541                 // struct __cfaabi_ehm__cleanup_hook __finally_hook
     541                // struct __cfaehm_cleanup_hook __finally_hook
    542542                //      __attribute__((cleanup( finally_wrapper )));
    543543
     
    593593                        // Skip children?
    594594                        return;
    595                 } else if ( structDecl->get_name() == "__cfaabi_ehm__base_exception_t" ) {
     595                } else if ( structDecl->get_name() == "__cfaehm_base_exception_t" ) {
    596596                        assert( nullptr == except_decl );
    597597                        except_decl = structDecl;
    598598                        init_func_types();
    599                 } else if ( structDecl->get_name() == "__cfaabi_ehm__try_resume_node" ) {
     599                } else if ( structDecl->get_name() == "__cfaehm_try_resume_node" ) {
    600600                        assert( nullptr == node_decl );
    601601                        node_decl = structDecl;
    602                 } else if ( structDecl->get_name() == "__cfaabi_ehm__cleanup_hook" ) {
     602                } else if ( structDecl->get_name() == "__cfaehm_cleanup_hook" ) {
    603603                        assert( nullptr == hook_decl );
    604604                        hook_decl = structDecl;
  • src/ControlStruct/LabelFixer.cc

    r71d6bd8 r7030dab  
    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 : Mon Mar 11 22:26:02 2019
    13 // Update Count     : 159
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Jan 21 10:32:00 2020
     13// Update Count     : 160
    1414//
    1515
     
    2121#include "ControlStruct/LabelGenerator.h"  // for LabelGenerator
    2222#include "LabelFixer.h"
    23 #include "MLEMutator.h"                    // for MLEMutator
     23#include "MLEMutator.h"                    // for MultiLevelExitMutator
    2424#include "SynTree/Declaration.h"           // for FunctionDecl
    2525#include "SynTree/Expression.h"            // for NameExpr, Expression, Unty...
     
    4444
    4545        void LabelFixer::postvisit( FunctionDecl * functionDecl ) {
    46                 PassVisitor<MLEMutator> mlemut( resolveJumps(), generator );
    47                 functionDecl->acceptMutator( mlemut );
     46                PassVisitor<MultiLevelExitMutator> mlem( resolveJumps(), generator );
     47                // We start in the body so we can stop when we hit another FunctionDecl.
     48                maybeMutate( functionDecl->statements, mlem );
    4849        }
    4950
     
    7576
    7677
    77         // sets the definition of the labelTable entry to be the provided statement for every label in the list
    78         // parameter. Happens for every kind of statement
     78        // Sets the definition of the labelTable entry to be the provided statement for every label in
     79        // the list parameter. Happens for every kind of statement.
    7980        Label LabelFixer::setLabelsDef( std::list< Label > & llabel, Statement * definition ) {
    8081                assert( definition != 0 );
    8182                assert( llabel.size() > 0 );
    82 
    83                 Entry * e = new Entry( definition );
    8483
    8584                for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) {
     
    8786                        l.set_statement( definition ); // attach statement to the label to be used later
    8887                        if ( labelTable.find( l ) == labelTable.end() ) {
    89                                 // all labels on this statement need to use the same entry, so this should only be created once
     88                                // All labels on this statement need to use the same entry,
     89                                // so this should only be created once.
    9090                                // undefined and unused until now, add an entry
    91                                 labelTable[ l ] =  e;
     91                                labelTable[ l ] = new Entry( definition );
    9292                        } else if ( labelTable[ l ]->defined() ) {
    9393                                // defined twice, error
    94                                 SemanticError( l.get_statement()->location, "Duplicate definition of label: " + l.get_name() );
    95                         }       else {
     94                                SemanticError( l.get_statement()->location,
     95                                        "Duplicate definition of label: " + l.get_name() );
     96                        } else {
    9697                                // used previously, but undefined until now -> link with this entry
     98                                // Question: Is changing objects important?
    9799                                delete labelTable[ l ];
    98                                 labelTable[ l ] = e;
     100                                labelTable[ l ] = new Entry( definition );
    99101                        } // if
    100102                } // for
    101103
    102                 // produce one of the labels attached to this statement to be temporarily used as the canonical label
     104                // Produce one of the labels attached to this statement to be temporarily used as the
     105                // canonical label.
    103106                return labelTable[ llabel.front() ]->get_label();
    104107        }
  • src/ControlStruct/MLEMutator.cc

    r71d6bd8 r7030dab  
    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 : Tue Oct 22 17:22:44 2019
    13 // Update Count     : 220
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jan 22 11:50:00 2020
     13// Update Count     : 223
    1414//
    1515
     
    3333
    3434namespace ControlStruct {
    35         MLEMutator::~MLEMutator() {
     35        MultiLevelExitMutator::~MultiLevelExitMutator() {
    3636                delete targetTable;
    3737                targetTable = 0;
    3838        }
    3939        namespace {
    40                 bool isLoop( const MLEMutator::Entry & e ) { return dynamic_cast< WhileStmt * >( e.get_controlStructure() ) || dynamic_cast< ForStmt * >( e.get_controlStructure() ); }
    41                 bool isSwitch( const MLEMutator::Entry & e ) { return dynamic_cast< SwitchStmt *>( e.get_controlStructure() ); }
    42 
    43                 bool isBreakTarget( const MLEMutator::Entry & e ) { return isLoop( e ) || isSwitch( e ) || dynamic_cast< CompoundStmt *>( e.get_controlStructure() ); }
    44                 bool isContinueTarget( const MLEMutator::Entry & e ) { return isLoop( e ); }
    45                 bool isFallthroughTarget( const MLEMutator::Entry & e ) { return dynamic_cast< CaseStmt *>( e.get_controlStructure() );; }
    46                 bool isFallthroughDefaultTarget( const MLEMutator::Entry & e ) { return isSwitch( e ); }
     40                bool isLoop( const MultiLevelExitMutator::Entry & e ) {
     41                        return dynamic_cast< WhileStmt * >( e.get_controlStructure() )
     42                                || dynamic_cast< ForStmt * >( e.get_controlStructure() );
     43                }
     44                bool isSwitch( const MultiLevelExitMutator::Entry & e ) {
     45                        return dynamic_cast< SwitchStmt *>( e.get_controlStructure() );
     46                }
     47
     48                bool isBreakTarget( const MultiLevelExitMutator::Entry & e ) {
     49                        return isLoop( e ) || isSwitch( e )
     50                                || dynamic_cast< CompoundStmt *>( e.get_controlStructure() );
     51                }
     52                bool isContinueTarget( const MultiLevelExitMutator::Entry & e ) {
     53                        return isLoop( e );
     54                }
     55                bool isFallthroughTarget( const MultiLevelExitMutator::Entry & e ) {
     56                        return dynamic_cast< CaseStmt *>( e.get_controlStructure() );
     57                }
     58                bool isFallthroughDefaultTarget( const MultiLevelExitMutator::Entry & e ) {
     59                        return isSwitch( e );
     60                }
    4761        } // namespace
     62
     63        void MultiLevelExitMutator::premutate( FunctionDecl * ) {
     64                visit_children = false;
     65        }
    4866
    4967        // break labels have to come after the statement they break out of, so mutate a statement, then if they inform us
    5068        // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the
    5169        // body of statements
    52         void MLEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
     70        void MultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
    5371                SemanticErrorException errors;
    5472
     
    8199        }
    82100
    83         void MLEMutator::premutate( CompoundStmt *cmpndStmt ) {
     101        void MultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) {
    84102                visit_children = false;
    85103                bool labeledBlock = !(cmpndStmt->labels.empty());
     
    118136                        }
    119137                }
    120                 assertf( false, "Could not find label '%s' on statement %s", originalTarget.get_name().c_str(), toString( stmt ).c_str() );
    121         }
    122 
    123 
    124         Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ) {
     138                assertf( false, "Could not find label '%s' on statement %s",
     139                        originalTarget.get_name().c_str(), toString( stmt ).c_str() );
     140        }
     141
     142
     143        Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt )
     144                        throw ( SemanticErrorException ) {
    125145                std::string originalTarget = branchStmt->originalTarget;
    126146
     
    230250        }
    231251
    232         Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     252        Statement *MultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     253                // only generate these when needed
     254                if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop;
     255
    233256                // ensure loop body is a block
    234                 CompoundStmt *newBody;
    235                 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {
    236                         newBody = new CompoundStmt();
    237                         newBody->get_kids().push_back( bodyLoop );
    238                 } // if
    239 
    240                 // only generate these when needed
     257                CompoundStmt * newBody = new CompoundStmt();
     258                newBody->get_kids().push_back( bodyLoop );
    241259
    242260                if ( e.isContUsed() ) {
     
    255273
    256274        template< typename LoopClass >
    257         void MLEMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
     275        void MultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
    258276                // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine
    259277                // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested
     
    266284
    267285        template< typename LoopClass >
    268         Statement * MLEMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
     286        Statement * MultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
    269287                assert( ! enclosingControlStructures.empty() );
    270288                Entry &e = enclosingControlStructures.back();
     
    277295        }
    278296
    279         void MLEMutator::premutate( WhileStmt * whileStmt ) {
     297        void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {
    280298                return prehandleLoopStmt( whileStmt );
    281299        }
    282300
    283         void MLEMutator::premutate( ForStmt * forStmt ) {
     301        void MultiLevelExitMutator::premutate( ForStmt * forStmt ) {
    284302                return prehandleLoopStmt( forStmt );
    285303        }
    286304
    287         Statement * MLEMutator::postmutate( WhileStmt * whileStmt ) {
     305        Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {
    288306                return posthandleLoopStmt( whileStmt );
    289307        }
    290308
    291         Statement * MLEMutator::postmutate( ForStmt * forStmt ) {
     309        Statement * MultiLevelExitMutator::postmutate( ForStmt * forStmt ) {
    292310                return posthandleLoopStmt( forStmt );
    293311        }
    294312
    295         void MLEMutator::premutate( IfStmt * ifStmt ) {
     313        void MultiLevelExitMutator::premutate( IfStmt * ifStmt ) {
    296314                // generate a label for breaking out of a labeled if
    297315                bool labeledBlock = !(ifStmt->get_labels().empty());
     
    303321        }
    304322
    305         Statement * MLEMutator::postmutate( IfStmt * ifStmt ) {
     323        Statement * MultiLevelExitMutator::postmutate( IfStmt * ifStmt ) {
    306324                bool labeledBlock = !(ifStmt->get_labels().empty());
    307325                if ( labeledBlock ) {
     
    313331        }
    314332
    315         void MLEMutator::premutate( TryStmt * tryStmt ) {
     333        void MultiLevelExitMutator::premutate( TryStmt * tryStmt ) {
    316334                // generate a label for breaking out of a labeled if
    317335                bool labeledBlock = !(tryStmt->get_labels().empty());
     
    323341        }
    324342
    325         Statement * MLEMutator::postmutate( TryStmt * tryStmt ) {
     343        Statement * MultiLevelExitMutator::postmutate( TryStmt * tryStmt ) {
    326344                bool labeledBlock = !(tryStmt->get_labels().empty());
    327345                if ( labeledBlock ) {
     
    333351        }
    334352
    335         void MLEMutator::premutate( CaseStmt *caseStmt ) {
     353        void MultiLevelExitMutator::premutate( FinallyStmt * ) {
     354                GuardAction([this, old = std::move(enclosingControlStructures)]() {
     355                        enclosingControlStructures = std::move(old);
     356                });
     357                enclosingControlStructures = std::list<Entry>();
     358                GuardValue( inFinally );
     359                inFinally = true;
     360        }
     361
     362        void MultiLevelExitMutator::premutate( ReturnStmt *returnStmt ) {
     363                if ( inFinally ) {
     364                        SemanticError( returnStmt->location, "'return' may not appear in a finally clause" );
     365                }
     366        }
     367
     368        void MultiLevelExitMutator::premutate( CaseStmt *caseStmt ) {
    336369                visit_children = false;
    337370
     
    372405        }
    373406
    374         void MLEMutator::premutate( SwitchStmt *switchStmt ) {
     407        void MultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) {
    375408                // generate a label for breaking out of a labeled switch
    376409                Label brkLabel = generator->newLabel("switchBreak", switchStmt);
     
    398431        }
    399432
    400         Statement * MLEMutator::postmutate( SwitchStmt * switchStmt ) {
     433        Statement * MultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) {
    401434                Entry &e = enclosingControlStructures.back();
    402435                assert ( e == switchStmt );
  • src/ControlStruct/MLEMutator.h

    r71d6bd8 r7030dab  
    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 : Tue Oct 22 17:22:47 2019
    13 // Update Count     : 45
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jan 22 11:50:00 2020
     13// Update Count     : 48
    1414//
    1515
     
    3030        class LabelGenerator;
    3131
    32         class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting, public WithGuards {
     32        class MultiLevelExitMutator : public WithVisitorRef<MultiLevelExitMutator>,
     33                        public WithShortCircuiting, public WithGuards {
    3334          public:
    3435                class Entry;
    35                 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
    36                 ~MLEMutator();
     36                MultiLevelExitMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) :
     37                        targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
     38                ~MultiLevelExitMutator();
     39
     40                void premutate( FunctionDecl * );
    3741
    3842                void premutate( CompoundStmt *cmpndStmt );
     
    4751                void premutate( SwitchStmt *switchStmt );
    4852                Statement * postmutate( SwitchStmt *switchStmt );
     53                void premutate( ReturnStmt *returnStmt );
    4954                void premutate( TryStmt *tryStmt );
    5055                Statement * postmutate( TryStmt *tryStmt );
     56                void premutate( FinallyStmt *finallyStmt );
    5157
    5258                Statement *mutateLoop( Statement *bodyLoop, Entry &e );
     
    110116                Label breakLabel;
    111117                LabelGenerator *generator;
     118                bool inFinally = false;
    112119
    113120                template< typename LoopClass >
  • src/ControlStruct/Mutate.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:39:08 2016
    13 // Update Count     : 9
     12// Last Modified On : Sun Feb 16 03:22:07 2020
     13// Update Count     : 10
    1414//
    1515
     
    3737                mutateAll( translationUnit, formut );
    3838        }
    39 } // namespace CodeGen
     39} // namespace ControlStruct
    4040
    4141// Local Variables: //
  • src/GenPoly/Box.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 21 15:49:59 2017
    13 // Update Count     : 346
     12// Last Modified On : Fri Dec 13 23:40:34 2019
     13// Update Count     : 347
    1414//
    1515
     
    3737#include "InitTweak/InitTweak.h"         // for getFunctionName, isAssignment
    3838#include "Lvalue.h"                      // for generalizedLvalue
    39 #include "Parser/LinkageSpec.h"          // for C, Spec, Cforall, Intrinsic
    4039#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass
    4140#include "ResolvExpr/typeops.h"          // for typesCompatible
     
    4443#include "SymTab/Indexer.h"              // for Indexer
    4544#include "SymTab/Mangler.h"              // for Mangler
     45#include "SynTree/LinkageSpec.h"         // for C, Spec, Cforall, Intrinsic
    4646#include "SynTree/Attribute.h"           // for Attribute
    4747#include "SynTree/Constant.h"            // for Constant
  • src/GenPoly/Lvalue.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:11:18 2017
    13 // Update Count     : 5
     12// Last Modified On : Fri Dec 13 23:14:38 2019
     13// Update Count     : 7
    1414//
    1515
     
    1717#include <string>                        // for string
    1818
     19#include "Common/UniqueName.h"
    1920#include "Common/PassVisitor.h"
    2021#include "GenPoly.h"                     // for isPolyType
     
    2223
    2324#include "InitTweak/InitTweak.h"
    24 #include "Parser/LinkageSpec.h"          // for Spec, isBuiltin, Intrinsic
    2525#include "ResolvExpr/TypeEnvironment.h"  // for AssertionSet, OpenVarSet
    2626#include "ResolvExpr/Unify.h"            // for unify
    2727#include "ResolvExpr/typeops.h"
    2828#include "SymTab/Indexer.h"              // for Indexer
     29#include "SynTree/LinkageSpec.h"         // for Spec, isBuiltin, Intrinsic
    2930#include "SynTree/Declaration.h"         // for Declaration, FunctionDecl
    3031#include "SynTree/Expression.h"          // for Expression, ConditionalExpr
     
    6061                }
    6162
    62                 struct ReferenceConversions final : public WithStmtsToAdd {
     63                struct ReferenceConversions final : public WithStmtsToAdd, public WithGuards {
    6364                        Expression * postmutate( CastExpr * castExpr );
    6465                        Expression * postmutate( AddressExpr * addrExpr );
     
    7172
    7273                struct FixIntrinsicResult final : public WithGuards {
     74                        enum {
     75                                NoSkip,
     76                                Skip,
     77                                SkipInProgress
     78                        } skip = NoSkip;
     79
     80                        void premutate( AsmExpr * ) { GuardValue( skip ); skip = Skip; }
     81                        void premutate( ApplicationExpr * ) { GuardValue( skip ); skip = (skip == Skip) ? SkipInProgress : NoSkip; }
     82
     83
    7384                        Expression * postmutate( ApplicationExpr * appExpr );
    7485                        void premutate( FunctionDecl * funcDecl );
     
    162173
    163174                Expression * FixIntrinsicResult::postmutate( ApplicationExpr * appExpr ) {
    164                         if ( isIntrinsicReference( appExpr ) ) {
     175                        if ( skip != SkipInProgress && isIntrinsicReference( appExpr ) ) {
    165176                                // eliminate reference types from intrinsic applications - now they return lvalues
    166177                                ReferenceType * result = strict_dynamic_cast< ReferenceType * >( appExpr->result );
  • src/GenPoly/Specialize.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:53:59 2017
    13 // Update Count     : 31
     12// Last Modified On : Fri Dec 13 23:40:49 2019
     13// Update Count     : 32
    1414//
    1515
     
    2727#include "GenPoly.h"                     // for getFunctionType
    2828#include "InitTweak/InitTweak.h"         // for isIntrinsicCallExpr
    29 #include "Parser/LinkageSpec.h"          // for C
    3029#include "ResolvExpr/FindOpenVars.h"     // for findOpenVars
    3130#include "ResolvExpr/TypeEnvironment.h"  // for OpenVarSet, AssertionSet
    3231#include "Specialize.h"
     32#include "SynTree/LinkageSpec.h"         // for C
    3333#include "SynTree/Attribute.h"           // for Attribute
    3434#include "SynTree/Declaration.h"         // for FunctionDecl, DeclarationWit...
  • src/InitTweak/FixGlobalInit.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 04 15:14:56 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:53:11 2017
    13 // Update Count     : 18
     12// Last Modified On : Fri Dec 13 23:41:10 2019
     13// Update Count     : 19
    1414//
    1515
     
    2323#include "Common/UniqueName.h"     // for UniqueName
    2424#include "InitTweak.h"             // for isIntrinsicSingleArgCallStmt
    25 #include "Parser/LinkageSpec.h"    // for C
     25#include "SynTree/LinkageSpec.h"   // for C
    2626#include "SynTree/Attribute.h"     // for Attribute
    2727#include "SynTree/Constant.h"      // for Constant
  • src/InitTweak/FixInit.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 18:15:56 2019
    13 // Update Count     : 76
     12// Last Modified On : Sun Feb 16 04:17:07 2020
     13// Update Count     : 82
    1414//
    1515#include "FixInit.h"
     
    3838#include "GenPoly/GenPoly.h"           // for getFunctionType
    3939#include "InitTweak.h"                 // for getFunctionName, getCallArg
    40 #include "Parser/LinkageSpec.h"        // for C, Spec, Cforall, isBuiltin
    4140#include "ResolvExpr/Resolver.h"       // for findVoidExpression
    4241#include "ResolvExpr/typeops.h"        // for typesCompatible
     
    4443#include "SymTab/Indexer.h"            // for Indexer
    4544#include "SymTab/Mangler.h"            // for Mangler
     45#include "SynTree/LinkageSpec.h"       // for C, Spec, Cforall, isBuiltin
    4646#include "SynTree/Attribute.h"         // for Attribute
    4747#include "SynTree/Constant.h"          // for Constant
     
    745745                }
    746746
    747                 // to prevent warnings (‘_unq0’ may be used uninitialized in this function),
     747                // to prevent warnings ('_unq0' may be used uninitialized in this function),
    748748                // insert an appropriate zero initializer for UniqueExpr temporaries.
    749749                Initializer * makeInit( Type * t ) {
  • src/InitTweak/FixInit.h

    r71d6bd8 r7030dab  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:31:06 2017
    13 // Update Count     : 6
     12// Last Modified On : Sun Feb 16 07:54:50 2020
     13// Update Count     : 8
    1414//
    1515
     
    2222
    2323namespace InitTweak {
    24   /// replace constructor initializers with expression statements
    25   /// and unwrap basic C-style initializers
     24        /// replace constructor initializers with expression statements and unwrap basic C-style initializers
    2625        void fix( std::list< Declaration * > & translationUnit, bool inLibrary );
    2726} // namespace
  • src/InitTweak/GenInit.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:12:36 2017
    13 // Update Count     : 183
     12// Last Modified On : Fri Dec 13 23:15:10 2019
     13// Update Count     : 184
    1414//
    1515#include "GenInit.h"
     
    3434#include "GenPoly/ScopedSet.h"         // for ScopedSet, ScopedSet<>::const_iter...
    3535#include "InitTweak.h"                 // for isConstExpr, InitExpander, checkIn...
    36 #include "Parser/LinkageSpec.h"        // for isOverridable, C
    3736#include "ResolvExpr/Resolver.h"
    3837#include "SymTab/Autogen.h"            // for genImplicitCall
    3938#include "SymTab/Mangler.h"            // for Mangler
     39#include "SynTree/LinkageSpec.h"       // for isOverridable, C
    4040#include "SynTree/Declaration.h"       // for ObjectDecl, DeclarationWithType
    4141#include "SynTree/Expression.h"        // for VariableExpr, UntypedExpr, Address...
  • src/InitTweak/InitTweak.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Fri May 13 11:26:36 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:21:48 2019
    13 // Update Count     : 7
     12// Last Modified On : Fri Dec 13 23:15:52 2019
     13// Update Count     : 8
    1414//
    1515
     
    3333#include "GenPoly/GenPoly.h"       // for getFunctionType
    3434#include "InitTweak.h"
    35 #include "Parser/LinkageSpec.h"    // for Spec, isBuiltin, Intrinsic
    3635#include "ResolvExpr/typeops.h"    // for typesCompatibleIgnoreQualifiers
    3736#include "SymTab/Autogen.h"
    3837#include "SymTab/Indexer.h"        // for Indexer
     38#include "SynTree/LinkageSpec.h"   // for Spec, isBuiltin, Intrinsic
    3939#include "SynTree/Attribute.h"     // for Attribute
    4040#include "SynTree/Constant.h"      // for Constant
  • src/MakeLibCfa.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 10:33:33 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Feb 17 21:08:09 2019
    13 // Update Count     : 41
     12// Last Modified On : Sun Feb 16 03:49:49 2020
     13// Update Count     : 45
    1414//
    1515
     
    2323#include "Common/SemanticError.h"   // for SemanticError
    2424#include "Common/UniqueName.h"      // for UniqueName
    25 #include "Parser/LinkageSpec.h"     // for Spec, Intrinsic, C
     25#include "SynTree/LinkageSpec.h"    // for Spec, Intrinsic, C
    2626#include "SynTree/Declaration.h"    // for FunctionDecl, ObjectDecl, Declara...
    2727#include "SynTree/Expression.h"     // for NameExpr, UntypedExpr, VariableExpr
     
    9696
    9797                        FunctionDecl *funcDecl = origFuncDecl->clone();
    98                         CodeGen::OperatorInfo opInfo;
    99                         bool lookResult = CodeGen::operatorLookup( funcDecl->get_name(), opInfo );
    100                         assert( lookResult );
     98                        const CodeGen::OperatorInfo * opInfo;
     99                        opInfo = CodeGen::operatorLookup( funcDecl->get_name() );
     100                        assert( opInfo );
    101101                        assert( ! funcDecl->get_statements() );
    102102                        // build a recursive call - this is okay, as the call will actually be codegen'd using operator syntax
     
    120120
    121121                        Statement * stmt = nullptr;
    122                         switch ( opInfo.type ) {
     122                        switch ( opInfo->type ) {
    123123                          case CodeGen::OT_INDEX:
    124124                          case CodeGen::OT_CALL:
  • src/Makefile.in

    r71d6bd8 r7030dab  
    213213        SymTab/Indexer.$(OBJEXT) SymTab/Mangler.$(OBJEXT) \
    214214        SymTab/ManglerCommon.$(OBJEXT) SymTab/Validate.$(OBJEXT)
    215 am__objects_7 = SynTree/Type.$(OBJEXT) SynTree/VoidType.$(OBJEXT) \
    216         SynTree/BasicType.$(OBJEXT) SynTree/PointerType.$(OBJEXT) \
    217         SynTree/ArrayType.$(OBJEXT) SynTree/ReferenceType.$(OBJEXT) \
    218         SynTree/FunctionType.$(OBJEXT) \
    219         SynTree/ReferenceToType.$(OBJEXT) SynTree/TupleType.$(OBJEXT) \
    220         SynTree/TypeofType.$(OBJEXT) SynTree/AttrType.$(OBJEXT) \
    221         SynTree/VarArgsType.$(OBJEXT) SynTree/ZeroOneType.$(OBJEXT) \
    222         SynTree/Constant.$(OBJEXT) SynTree/Expression.$(OBJEXT) \
    223         SynTree/TupleExpr.$(OBJEXT) SynTree/CommaExpr.$(OBJEXT) \
    224         SynTree/TypeExpr.$(OBJEXT) SynTree/ApplicationExpr.$(OBJEXT) \
    225         SynTree/AddressExpr.$(OBJEXT) SynTree/Statement.$(OBJEXT) \
    226         SynTree/CompoundStmt.$(OBJEXT) SynTree/DeclStmt.$(OBJEXT) \
     215am__objects_7 = SynTree/AddressExpr.$(OBJEXT) \
     216        SynTree/AggregateDecl.$(OBJEXT) \
     217        SynTree/ApplicationExpr.$(OBJEXT) SynTree/ArrayType.$(OBJEXT) \
     218        SynTree/AttrType.$(OBJEXT) SynTree/Attribute.$(OBJEXT) \
     219        SynTree/BasicType.$(OBJEXT) SynTree/CommaExpr.$(OBJEXT) \
     220        SynTree/CompoundStmt.$(OBJEXT) SynTree/Constant.$(OBJEXT) \
     221        SynTree/DeclReplacer.$(OBJEXT) SynTree/DeclStmt.$(OBJEXT) \
    227222        SynTree/Declaration.$(OBJEXT) \
    228223        SynTree/DeclarationWithType.$(OBJEXT) \
    229         SynTree/ObjectDecl.$(OBJEXT) SynTree/FunctionDecl.$(OBJEXT) \
    230         SynTree/AggregateDecl.$(OBJEXT) \
    231         SynTree/NamedTypeDecl.$(OBJEXT) SynTree/TypeDecl.$(OBJEXT) \
    232         SynTree/Initializer.$(OBJEXT) \
    233         SynTree/TypeSubstitution.$(OBJEXT) SynTree/Attribute.$(OBJEXT) \
    234         SynTree/DeclReplacer.$(OBJEXT)
     224        SynTree/Expression.$(OBJEXT) SynTree/FunctionDecl.$(OBJEXT) \
     225        SynTree/FunctionType.$(OBJEXT) SynTree/Initializer.$(OBJEXT) \
     226        SynTree/LinkageSpec.$(OBJEXT) SynTree/NamedTypeDecl.$(OBJEXT) \
     227        SynTree/ObjectDecl.$(OBJEXT) SynTree/PointerType.$(OBJEXT) \
     228        SynTree/ReferenceToType.$(OBJEXT) \
     229        SynTree/ReferenceType.$(OBJEXT) SynTree/Statement.$(OBJEXT) \
     230        SynTree/TupleExpr.$(OBJEXT) SynTree/TupleType.$(OBJEXT) \
     231        SynTree/Type.$(OBJEXT) SynTree/TypeDecl.$(OBJEXT) \
     232        SynTree/TypeExpr.$(OBJEXT) SynTree/TypeSubstitution.$(OBJEXT) \
     233        SynTree/TypeofType.$(OBJEXT) SynTree/VarArgsType.$(OBJEXT) \
     234        SynTree/VoidType.$(OBJEXT) SynTree/ZeroOneType.$(OBJEXT)
    235235am__objects_8 = CompilationState.$(OBJEXT) $(am__objects_1) \
    236236        $(am__objects_2) Concurrency/Keywords.$(OBJEXT) \
    237237        $(am__objects_3) $(am__objects_4) GenPoly/GenPoly.$(OBJEXT) \
    238238        GenPoly/Lvalue.$(OBJEXT) InitTweak/GenInit.$(OBJEXT) \
    239         InitTweak/InitTweak.$(OBJEXT) Parser/LinkageSpec.$(OBJEXT) \
    240         $(am__objects_5) $(am__objects_6) SymTab/Demangle.$(OBJEXT) \
    241         $(am__objects_7) Tuples/TupleAssignment.$(OBJEXT) \
     239        InitTweak/InitTweak.$(OBJEXT) $(am__objects_5) \
     240        $(am__objects_6) SymTab/Demangle.$(OBJEXT) $(am__objects_7) \
     241        Tuples/TupleAssignment.$(OBJEXT) \
    242242        Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \
    243243        Tuples/Tuples.$(OBJEXT) Validate/HandleAttributes.$(OBJEXT) \
     
    262262        InitTweak/GenInit.$(OBJEXT) InitTweak/FixInit.$(OBJEXT) \
    263263        InitTweak/FixGlobalInit.$(OBJEXT) \
    264         InitTweak/InitTweak.$(OBJEXT) Parser/parser.$(OBJEXT) \
    265         Parser/lex.$(OBJEXT) Parser/TypedefTable.$(OBJEXT) \
    266         Parser/ParseNode.$(OBJEXT) Parser/DeclarationNode.$(OBJEXT) \
    267         Parser/ExpressionNode.$(OBJEXT) Parser/StatementNode.$(OBJEXT) \
    268         Parser/InitializerNode.$(OBJEXT) Parser/TypeData.$(OBJEXT) \
    269         Parser/LinkageSpec.$(OBJEXT) Parser/parserutility.$(OBJEXT) \
     264        InitTweak/InitTweak.$(OBJEXT) Parser/DeclarationNode.$(OBJEXT) \
     265        Parser/ExpressionNode.$(OBJEXT) \
     266        Parser/InitializerNode.$(OBJEXT) Parser/ParseNode.$(OBJEXT) \
     267        Parser/StatementNode.$(OBJEXT) Parser/TypeData.$(OBJEXT) \
     268        Parser/TypedefTable.$(OBJEXT) Parser/lex.$(OBJEXT) \
     269        Parser/parser.$(OBJEXT) Parser/parserutility.$(OBJEXT) \
    270270        $(am__objects_5) ResolvExpr/AlternativePrinter.$(OBJEXT) \
    271271        $(am__objects_6) $(am__objects_7) \
     
    560560        InitTweak/GenInit.cc InitTweak/FixInit.cc \
    561561        InitTweak/FixGlobalInit.cc InitTweak/InitTweak.cc \
    562         Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \
    563         Parser/ParseNode.cc Parser/DeclarationNode.cc \
    564         Parser/ExpressionNode.cc Parser/StatementNode.cc \
    565         Parser/InitializerNode.cc Parser/TypeData.cc \
    566         Parser/LinkageSpec.cc Parser/parserutility.cc \
    567         $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc \
    568         $(SRC_SYMTAB) $(SRC_SYNTREE) Tuples/TupleAssignment.cc \
    569         Tuples/TupleExpansion.cc Tuples/Explode.cc Tuples/Tuples.cc \
     562        Parser/DeclarationNode.cc Parser/ExpressionNode.cc \
     563        Parser/InitializerNode.cc Parser/ParseNode.cc \
     564        Parser/StatementNode.cc Parser/TypeData.cc \
     565        Parser/TypedefTable.cc Parser/lex.ll Parser/parser.yy \
     566        Parser/parserutility.cc $(SRC_RESOLVEXPR) \
     567        ResolvExpr/AlternativePrinter.cc $(SRC_SYMTAB) $(SRC_SYNTREE) \
     568        Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \
     569        Tuples/Explode.cc Tuples/Tuples.cc \
    570570        Validate/HandleAttributes.cc Validate/FindSpecialDecls.cc \
    571571        Virtual/ExpandCasts.cc
     
    573573        Concurrency/Keywords.cc $(SRC_COMMON) $(SRC_CONTROLSTRUCT) \
    574574        GenPoly/GenPoly.cc GenPoly/Lvalue.cc InitTweak/GenInit.cc \
    575         InitTweak/InitTweak.cc Parser/LinkageSpec.cc $(SRC_RESOLVEXPR) \
    576         $(SRC_SYMTAB) SymTab/Demangle.cc $(SRC_SYNTREE) \
    577         Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \
    578         Tuples/Explode.cc Tuples/Tuples.cc \
     575        InitTweak/InitTweak.cc $(SRC_RESOLVEXPR) $(SRC_SYMTAB) \
     576        SymTab/Demangle.cc $(SRC_SYNTREE) Tuples/TupleAssignment.cc \
     577        Tuples/TupleExpansion.cc Tuples/Explode.cc Tuples/Tuples.cc \
    579578        Validate/HandleAttributes.cc Validate/FindSpecialDecls.cc
    580579MAINTAINERCLEANFILES = ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}}
     
    665664
    666665SRC_SYNTREE = \
    667       SynTree/Type.cc \
    668       SynTree/VoidType.cc \
     666      SynTree/AddressExpr.cc \
     667      SynTree/AggregateDecl.cc \
     668      SynTree/ApplicationExpr.cc \
     669      SynTree/ArrayType.cc \
     670      SynTree/AttrType.cc \
     671      SynTree/Attribute.cc \
    669672      SynTree/BasicType.cc \
    670       SynTree/PointerType.cc \
    671       SynTree/ArrayType.cc \
    672       SynTree/ReferenceType.cc \
    673       SynTree/FunctionType.cc \
    674       SynTree/ReferenceToType.cc \
    675       SynTree/TupleType.cc \
    676       SynTree/TypeofType.cc \
    677       SynTree/AttrType.cc \
    678       SynTree/VarArgsType.cc \
    679       SynTree/ZeroOneType.cc \
     673      SynTree/CommaExpr.cc \
     674      SynTree/CompoundStmt.cc \
    680675      SynTree/Constant.cc \
    681       SynTree/Expression.cc \
    682       SynTree/TupleExpr.cc \
    683       SynTree/CommaExpr.cc \
    684       SynTree/TypeExpr.cc \
    685       SynTree/ApplicationExpr.cc \
    686       SynTree/AddressExpr.cc \
    687       SynTree/Statement.cc \
    688       SynTree/CompoundStmt.cc \
     676      SynTree/DeclReplacer.cc \
    689677      SynTree/DeclStmt.cc \
    690678      SynTree/Declaration.cc \
    691679      SynTree/DeclarationWithType.cc \
     680      SynTree/Expression.cc \
     681      SynTree/FunctionDecl.cc \
     682      SynTree/FunctionType.cc \
     683      SynTree/Initializer.cc \
     684      SynTree/LinkageSpec.cc \
     685      SynTree/NamedTypeDecl.cc \
    692686      SynTree/ObjectDecl.cc \
    693       SynTree/FunctionDecl.cc \
    694       SynTree/AggregateDecl.cc \
    695       SynTree/NamedTypeDecl.cc \
     687      SynTree/PointerType.cc \
     688      SynTree/ReferenceToType.cc \
     689      SynTree/ReferenceType.cc \
     690      SynTree/Statement.cc \
     691      SynTree/TupleExpr.cc \
     692      SynTree/TupleType.cc \
     693      SynTree/Type.cc \
    696694      SynTree/TypeDecl.cc \
    697       SynTree/Initializer.cc \
     695      SynTree/TypeExpr.cc \
    698696      SynTree/TypeSubstitution.cc \
    699       SynTree/Attribute.cc \
    700       SynTree/DeclReplacer.cc
     697      SynTree/TypeofType.cc \
     698      SynTree/VarArgsType.cc \
     699      SynTree/VoidType.cc \
     700      SynTree/ZeroOneType.cc
    701701
    702702
     
    873873InitTweak/InitTweak.$(OBJEXT): InitTweak/$(am__dirstamp) \
    874874        InitTweak/$(DEPDIR)/$(am__dirstamp)
    875 Parser/$(am__dirstamp):
    876         @$(MKDIR_P) Parser
    877         @: > Parser/$(am__dirstamp)
    878 Parser/$(DEPDIR)/$(am__dirstamp):
    879         @$(MKDIR_P) Parser/$(DEPDIR)
    880         @: > Parser/$(DEPDIR)/$(am__dirstamp)
    881 Parser/LinkageSpec.$(OBJEXT): Parser/$(am__dirstamp) \
    882         Parser/$(DEPDIR)/$(am__dirstamp)
    883875ResolvExpr/$(am__dirstamp):
    884876        @$(MKDIR_P) ResolvExpr
     
    961953        @$(MKDIR_P) SynTree/$(DEPDIR)
    962954        @: > SynTree/$(DEPDIR)/$(am__dirstamp)
     955SynTree/AddressExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
     956        SynTree/$(DEPDIR)/$(am__dirstamp)
     957SynTree/AggregateDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
     958        SynTree/$(DEPDIR)/$(am__dirstamp)
     959SynTree/ApplicationExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
     960        SynTree/$(DEPDIR)/$(am__dirstamp)
     961SynTree/ArrayType.$(OBJEXT): SynTree/$(am__dirstamp) \
     962        SynTree/$(DEPDIR)/$(am__dirstamp)
     963SynTree/AttrType.$(OBJEXT): SynTree/$(am__dirstamp) \
     964        SynTree/$(DEPDIR)/$(am__dirstamp)
     965SynTree/Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \
     966        SynTree/$(DEPDIR)/$(am__dirstamp)
     967SynTree/BasicType.$(OBJEXT): SynTree/$(am__dirstamp) \
     968        SynTree/$(DEPDIR)/$(am__dirstamp)
     969SynTree/CommaExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
     970        SynTree/$(DEPDIR)/$(am__dirstamp)
     971SynTree/CompoundStmt.$(OBJEXT): SynTree/$(am__dirstamp) \
     972        SynTree/$(DEPDIR)/$(am__dirstamp)
     973SynTree/Constant.$(OBJEXT): SynTree/$(am__dirstamp) \
     974        SynTree/$(DEPDIR)/$(am__dirstamp)
     975SynTree/DeclReplacer.$(OBJEXT): SynTree/$(am__dirstamp) \
     976        SynTree/$(DEPDIR)/$(am__dirstamp)
     977SynTree/DeclStmt.$(OBJEXT): SynTree/$(am__dirstamp) \
     978        SynTree/$(DEPDIR)/$(am__dirstamp)
     979SynTree/Declaration.$(OBJEXT): SynTree/$(am__dirstamp) \
     980        SynTree/$(DEPDIR)/$(am__dirstamp)
     981SynTree/DeclarationWithType.$(OBJEXT): SynTree/$(am__dirstamp) \
     982        SynTree/$(DEPDIR)/$(am__dirstamp)
     983SynTree/Expression.$(OBJEXT): SynTree/$(am__dirstamp) \
     984        SynTree/$(DEPDIR)/$(am__dirstamp)
     985SynTree/FunctionDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
     986        SynTree/$(DEPDIR)/$(am__dirstamp)
     987SynTree/FunctionType.$(OBJEXT): SynTree/$(am__dirstamp) \
     988        SynTree/$(DEPDIR)/$(am__dirstamp)
     989SynTree/Initializer.$(OBJEXT): SynTree/$(am__dirstamp) \
     990        SynTree/$(DEPDIR)/$(am__dirstamp)
     991SynTree/LinkageSpec.$(OBJEXT): SynTree/$(am__dirstamp) \
     992        SynTree/$(DEPDIR)/$(am__dirstamp)
     993SynTree/NamedTypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
     994        SynTree/$(DEPDIR)/$(am__dirstamp)
     995SynTree/ObjectDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
     996        SynTree/$(DEPDIR)/$(am__dirstamp)
     997SynTree/PointerType.$(OBJEXT): SynTree/$(am__dirstamp) \
     998        SynTree/$(DEPDIR)/$(am__dirstamp)
     999SynTree/ReferenceToType.$(OBJEXT): SynTree/$(am__dirstamp) \
     1000        SynTree/$(DEPDIR)/$(am__dirstamp)
     1001SynTree/ReferenceType.$(OBJEXT): SynTree/$(am__dirstamp) \
     1002        SynTree/$(DEPDIR)/$(am__dirstamp)
     1003SynTree/Statement.$(OBJEXT): SynTree/$(am__dirstamp) \
     1004        SynTree/$(DEPDIR)/$(am__dirstamp)
     1005SynTree/TupleExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
     1006        SynTree/$(DEPDIR)/$(am__dirstamp)
     1007SynTree/TupleType.$(OBJEXT): SynTree/$(am__dirstamp) \
     1008        SynTree/$(DEPDIR)/$(am__dirstamp)
    9631009SynTree/Type.$(OBJEXT): SynTree/$(am__dirstamp) \
    9641010        SynTree/$(DEPDIR)/$(am__dirstamp)
     1011SynTree/TypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
     1012        SynTree/$(DEPDIR)/$(am__dirstamp)
     1013SynTree/TypeExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
     1014        SynTree/$(DEPDIR)/$(am__dirstamp)
     1015SynTree/TypeSubstitution.$(OBJEXT): SynTree/$(am__dirstamp) \
     1016        SynTree/$(DEPDIR)/$(am__dirstamp)
     1017SynTree/TypeofType.$(OBJEXT): SynTree/$(am__dirstamp) \
     1018        SynTree/$(DEPDIR)/$(am__dirstamp)
     1019SynTree/VarArgsType.$(OBJEXT): SynTree/$(am__dirstamp) \
     1020        SynTree/$(DEPDIR)/$(am__dirstamp)
    9651021SynTree/VoidType.$(OBJEXT): SynTree/$(am__dirstamp) \
    9661022        SynTree/$(DEPDIR)/$(am__dirstamp)
    967 SynTree/BasicType.$(OBJEXT): SynTree/$(am__dirstamp) \
    968         SynTree/$(DEPDIR)/$(am__dirstamp)
    969 SynTree/PointerType.$(OBJEXT): SynTree/$(am__dirstamp) \
    970         SynTree/$(DEPDIR)/$(am__dirstamp)
    971 SynTree/ArrayType.$(OBJEXT): SynTree/$(am__dirstamp) \
    972         SynTree/$(DEPDIR)/$(am__dirstamp)
    973 SynTree/ReferenceType.$(OBJEXT): SynTree/$(am__dirstamp) \
    974         SynTree/$(DEPDIR)/$(am__dirstamp)
    975 SynTree/FunctionType.$(OBJEXT): SynTree/$(am__dirstamp) \
    976         SynTree/$(DEPDIR)/$(am__dirstamp)
    977 SynTree/ReferenceToType.$(OBJEXT): SynTree/$(am__dirstamp) \
    978         SynTree/$(DEPDIR)/$(am__dirstamp)
    979 SynTree/TupleType.$(OBJEXT): SynTree/$(am__dirstamp) \
    980         SynTree/$(DEPDIR)/$(am__dirstamp)
    981 SynTree/TypeofType.$(OBJEXT): SynTree/$(am__dirstamp) \
    982         SynTree/$(DEPDIR)/$(am__dirstamp)
    983 SynTree/AttrType.$(OBJEXT): SynTree/$(am__dirstamp) \
    984         SynTree/$(DEPDIR)/$(am__dirstamp)
    985 SynTree/VarArgsType.$(OBJEXT): SynTree/$(am__dirstamp) \
    986         SynTree/$(DEPDIR)/$(am__dirstamp)
    9871023SynTree/ZeroOneType.$(OBJEXT): SynTree/$(am__dirstamp) \
    988         SynTree/$(DEPDIR)/$(am__dirstamp)
    989 SynTree/Constant.$(OBJEXT): SynTree/$(am__dirstamp) \
    990         SynTree/$(DEPDIR)/$(am__dirstamp)
    991 SynTree/Expression.$(OBJEXT): SynTree/$(am__dirstamp) \
    992         SynTree/$(DEPDIR)/$(am__dirstamp)
    993 SynTree/TupleExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
    994         SynTree/$(DEPDIR)/$(am__dirstamp)
    995 SynTree/CommaExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
    996         SynTree/$(DEPDIR)/$(am__dirstamp)
    997 SynTree/TypeExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
    998         SynTree/$(DEPDIR)/$(am__dirstamp)
    999 SynTree/ApplicationExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
    1000         SynTree/$(DEPDIR)/$(am__dirstamp)
    1001 SynTree/AddressExpr.$(OBJEXT): SynTree/$(am__dirstamp) \
    1002         SynTree/$(DEPDIR)/$(am__dirstamp)
    1003 SynTree/Statement.$(OBJEXT): SynTree/$(am__dirstamp) \
    1004         SynTree/$(DEPDIR)/$(am__dirstamp)
    1005 SynTree/CompoundStmt.$(OBJEXT): SynTree/$(am__dirstamp) \
    1006         SynTree/$(DEPDIR)/$(am__dirstamp)
    1007 SynTree/DeclStmt.$(OBJEXT): SynTree/$(am__dirstamp) \
    1008         SynTree/$(DEPDIR)/$(am__dirstamp)
    1009 SynTree/Declaration.$(OBJEXT): SynTree/$(am__dirstamp) \
    1010         SynTree/$(DEPDIR)/$(am__dirstamp)
    1011 SynTree/DeclarationWithType.$(OBJEXT): SynTree/$(am__dirstamp) \
    1012         SynTree/$(DEPDIR)/$(am__dirstamp)
    1013 SynTree/ObjectDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
    1014         SynTree/$(DEPDIR)/$(am__dirstamp)
    1015 SynTree/FunctionDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
    1016         SynTree/$(DEPDIR)/$(am__dirstamp)
    1017 SynTree/AggregateDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
    1018         SynTree/$(DEPDIR)/$(am__dirstamp)
    1019 SynTree/NamedTypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
    1020         SynTree/$(DEPDIR)/$(am__dirstamp)
    1021 SynTree/TypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \
    1022         SynTree/$(DEPDIR)/$(am__dirstamp)
    1023 SynTree/Initializer.$(OBJEXT): SynTree/$(am__dirstamp) \
    1024         SynTree/$(DEPDIR)/$(am__dirstamp)
    1025 SynTree/TypeSubstitution.$(OBJEXT): SynTree/$(am__dirstamp) \
    1026         SynTree/$(DEPDIR)/$(am__dirstamp)
    1027 SynTree/Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \
    1028         SynTree/$(DEPDIR)/$(am__dirstamp)
    1029 SynTree/DeclReplacer.$(OBJEXT): SynTree/$(am__dirstamp) \
    10301024        SynTree/$(DEPDIR)/$(am__dirstamp)
    10311025Tuples/$(am__dirstamp):
     
    11441138InitTweak/FixGlobalInit.$(OBJEXT): InitTweak/$(am__dirstamp) \
    11451139        InitTweak/$(DEPDIR)/$(am__dirstamp)
     1140Parser/$(am__dirstamp):
     1141        @$(MKDIR_P) Parser
     1142        @: > Parser/$(am__dirstamp)
     1143Parser/$(DEPDIR)/$(am__dirstamp):
     1144        @$(MKDIR_P) Parser/$(DEPDIR)
     1145        @: > Parser/$(DEPDIR)/$(am__dirstamp)
     1146Parser/DeclarationNode.$(OBJEXT): Parser/$(am__dirstamp) \
     1147        Parser/$(DEPDIR)/$(am__dirstamp)
     1148Parser/ExpressionNode.$(OBJEXT): Parser/$(am__dirstamp) \
     1149        Parser/$(DEPDIR)/$(am__dirstamp)
     1150Parser/InitializerNode.$(OBJEXT): Parser/$(am__dirstamp) \
     1151        Parser/$(DEPDIR)/$(am__dirstamp)
     1152Parser/ParseNode.$(OBJEXT): Parser/$(am__dirstamp) \
     1153        Parser/$(DEPDIR)/$(am__dirstamp)
     1154Parser/StatementNode.$(OBJEXT): Parser/$(am__dirstamp) \
     1155        Parser/$(DEPDIR)/$(am__dirstamp)
     1156Parser/TypeData.$(OBJEXT): Parser/$(am__dirstamp) \
     1157        Parser/$(DEPDIR)/$(am__dirstamp)
     1158Parser/TypedefTable.$(OBJEXT): Parser/$(am__dirstamp) \
     1159        Parser/$(DEPDIR)/$(am__dirstamp)
     1160Parser/lex.$(OBJEXT): Parser/$(am__dirstamp) \
     1161        Parser/$(DEPDIR)/$(am__dirstamp)
    11461162Parser/parser.hh: Parser/parser.cc
    11471163        @if test ! -f $@; then rm -f Parser/parser.cc; else :; fi
    11481164        @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) Parser/parser.cc; else :; fi
    11491165Parser/parser.$(OBJEXT): Parser/$(am__dirstamp) \
    1150         Parser/$(DEPDIR)/$(am__dirstamp)
    1151 Parser/lex.$(OBJEXT): Parser/$(am__dirstamp) \
    1152         Parser/$(DEPDIR)/$(am__dirstamp)
    1153 Parser/TypedefTable.$(OBJEXT): Parser/$(am__dirstamp) \
    1154         Parser/$(DEPDIR)/$(am__dirstamp)
    1155 Parser/ParseNode.$(OBJEXT): Parser/$(am__dirstamp) \
    1156         Parser/$(DEPDIR)/$(am__dirstamp)
    1157 Parser/DeclarationNode.$(OBJEXT): Parser/$(am__dirstamp) \
    1158         Parser/$(DEPDIR)/$(am__dirstamp)
    1159 Parser/ExpressionNode.$(OBJEXT): Parser/$(am__dirstamp) \
    1160         Parser/$(DEPDIR)/$(am__dirstamp)
    1161 Parser/StatementNode.$(OBJEXT): Parser/$(am__dirstamp) \
    1162         Parser/$(DEPDIR)/$(am__dirstamp)
    1163 Parser/InitializerNode.$(OBJEXT): Parser/$(am__dirstamp) \
    1164         Parser/$(DEPDIR)/$(am__dirstamp)
    1165 Parser/TypeData.$(OBJEXT): Parser/$(am__dirstamp) \
    11661166        Parser/$(DEPDIR)/$(am__dirstamp)
    11671167Parser/parserutility.$(OBJEXT): Parser/$(am__dirstamp) \
     
    12751275@AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/ExpressionNode.Po@am__quote@
    12761276@AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/InitializerNode.Po@am__quote@
    1277 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/LinkageSpec.Po@am__quote@
    12781277@AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/ParseNode.Po@am__quote@
    12791278@AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/StatementNode.Po@am__quote@
     
    13341333@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/FunctionType.Po@am__quote@
    13351334@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/Initializer.Po@am__quote@
     1335@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/LinkageSpec.Po@am__quote@
    13361336@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/NamedTypeDecl.Po@am__quote@
    13371337@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/ObjectDecl.Po@am__quote@
  • src/Parser/DeclarationNode.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:17:10 2019
    13 // Update Count     : 1116
     12// Last Modified On : Mon Dec 16 15:32:22 2019
     13// Update Count     : 1133
    1414//
    1515
     
    2424#include "Common/UniqueName.h"     // for UniqueName
    2525#include "Common/utility.h"        // for maybeClone, maybeBuild, CodeLocation
    26 #include "Parser/LinkageSpec.h"    // for Spec, linkageName, Cforall
    2726#include "Parser/ParseNode.h"      // for DeclarationNode, ExpressionNode
     27#include "SynTree/LinkageSpec.h"   // for Spec, linkageName, Cforall
    2828#include "SynTree/Attribute.h"     // for Attribute
    2929#include "SynTree/Declaration.h"   // for TypeDecl, ObjectDecl, Declaration
     
    4747const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
    4848const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" };
    49 const char * DeclarationNode::aggregateNames[] = { "struct", "union", "trait", "coroutine", "monitor", "thread", "NoAggregateNames" };
    50 const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };
    5149const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" };
    5250
     
    5957
    6058//      variable.name = nullptr;
    61         variable.tyClass = NoTypeClass;
     59        variable.tyClass = TypeDecl::NUMBER_OF_KINDS;
    6260        variable.assertions = nullptr;
    6361        variable.initializer = nullptr;
     
    135133
    136134        if ( linkage != LinkageSpec::Cforall ) {
    137                 os << LinkageSpec::linkageName( linkage ) << " ";
     135                os << LinkageSpec::name( linkage ) << " ";
    138136        } // if
    139137
     
    267265}
    268266
    269 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     267DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    270268        DeclarationNode * newnode = new DeclarationNode;
    271269        newnode->type = new TypeData( TypeData::Aggregate );
     
    313311} // DeclarationNode::newFromTypeGen
    314312
    315 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, const string * name ) {
     313DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) {
    316314        DeclarationNode * newnode = new DeclarationNode;
    317315        newnode->type = nullptr;
     
    328326        newnode->type = new TypeData( TypeData::Aggregate );
    329327        newnode->type->aggregate.name = name;
    330         newnode->type->aggregate.kind = Trait;
     328        newnode->type->aggregate.kind = AggregateDecl::Trait;
    331329        newnode->type->aggregate.params = params;
    332330        newnode->type->aggregate.fields = asserts;
     
    338336        newnode->type = new TypeData( TypeData::AggregateInst );
    339337        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    340         newnode->type->aggInst.aggregate->aggregate.kind = Trait;
     338        newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait;
    341339        newnode->type->aggInst.aggregate->aggregate.name = name;
    342340        newnode->type->aggInst.params = params;
     
    671669
    672670DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
    673         if ( variable.tyClass != NoTypeClass ) {
     671        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    674672                if ( variable.assertions ) {
    675673                        variable.assertions->appendList( assertions );
     
    876874
    877875DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
    878         assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." );
     876        assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
    879877        variable.initializer = init;
    880878        return this;
     
    10751073        } // if
    10761074
    1077         if ( variable.tyClass != NoTypeClass ) {
     1075        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    10781076                // otype is internally converted to dtype + otype parameters
    10791077                static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype };
    1080                 assertf( sizeof(kindMap)/sizeof(kindMap[0]) == NoTypeClass, "DeclarationNode::build: kindMap is out of sync." );
     1078                static_assert( sizeof(kindMap)/sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
    10811079                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1082                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == Otype, variable.initializer ? variable.initializer->buildType() : nullptr );
     1080                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype, variable.initializer ? variable.initializer->buildType() : nullptr );
    10831081                buildList( variable.assertions, ret->get_assertions() );
    10841082                return ret;
  • src/Parser/ExpressionNode.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 20:57:55 2019
    13 // Update Count     : 978
     12// Last Modified On : Wed Dec 18 21:14:58 2019
     13// Update Count     : 981
    1414//
    1515
     
    265265        static const BasicType::Kind kind[2][12] = {
    266266                { BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::uuFloat80, BasicType::uuFloat128, BasicType::uFloat16, BasicType::uFloat32, BasicType::uFloat32x, BasicType::uFloat64, BasicType::uFloat64x, BasicType::uFloat128, BasicType::uFloat128x },
    267                 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, (BasicType::Kind)-1, (BasicType::Kind)-1, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex },
     267                { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::NUMBER_OF_BASIC_TYPES, BasicType::NUMBER_OF_BASIC_TYPES, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex },
    268268        };
    269269
     
    374374
    375375Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) {
    376         if ( str[str.size()-1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str );
     376        if ( str[str.size() - 1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str );
    377377        Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );
    378378        delete &str;
     
    434434} // build_cast
    435435
    436 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ) {
     436Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ) {
    437437        return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target );
    438438}
  • src/Parser/ParseNode.h

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:17:10 2019
    13 // Update Count     : 876
     12// Last Modified On : Fri Feb  7 17:56:02 2020
     13// Update Count     : 891
    1414//
    1515
     
    2828#include "Common/UniqueName.h"     // for UniqueName
    2929#include "Common/utility.h"        // for maybeClone, maybeBuild
    30 #include "Parser/LinkageSpec.h"    // for Spec
     30#include "SynTree/LinkageSpec.h"   // for Spec
     31#include "SynTree/Declaration.h"   // for Aggregate
    3132#include "SynTree/Expression.h"    // for Expression, ConstantExpr (ptr only)
    3233#include "SynTree/Label.h"         // for Label
     
    184185
    185186Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
    186 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node );
     187Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node );
    187188Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
    188189Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
     
    217218        enum Length { Short, Long, LongLong, NoLength };
    218219        static const char * lengthNames[];
    219         enum Aggregate { Struct, Union, Exception, Trait, Coroutine, Monitor, Thread, NoAggregate };
    220         static const char * aggregateNames[];
    221         enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
    222         static const char * typeClassNames[];
    223220        enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType };
    224221        static const char * builtinTypeNames[];
     
    237234        static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * );
    238235        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    239         static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
     236        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    240237        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
    241238        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    242239        static DeclarationNode * newName( const std::string * );
    243240        static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params );
    244         static DeclarationNode * newTypeParam( TypeClass, const std::string * );
     241        static DeclarationNode * newTypeParam( TypeDecl::Kind, const std::string * );
    245242        static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts );
    246243        static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params );
     
    312309        struct Variable_t {
    313310//              const std::string * name;
    314                 DeclarationNode::TypeClass tyClass;
     311                TypeDecl::Kind tyClass;
    315312                DeclarationNode * assertions;
    316313                DeclarationNode * initializer;
     
    431428Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    432429Statement * build_directive( std::string * directive );
     430SuspendStmt * build_suspend( StatementNode *, SuspendStmt::Type = SuspendStmt::None);
    433431WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when );
    434432WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing );
     
    452450                                * out++ = result;
    453451                        } else {
    454                                 assertf(false, "buildList unknown type");
     452                                SemanticError( cur->location, "type specifier declaration in forall clause is currently unimplemented." );
    455453                        } // if
    456454                } catch( SemanticErrorException & e ) {
  • src/Parser/ParserTypes.h

    r71d6bd8 r7030dab  
    1010// Created On       : Sat Sep 22 08:58:10 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:33:28 2017
    13 // Update Count     : 350
     12// Last Modified On : Sat Feb 15 11:04:40 2020
     13// Update Count     : 351
    1414//
    1515
     
    2727// current location in the input
    2828extern int yylineno;
    29 extern char *yyfilename;
     29extern char * yyfilename;
    3030
    3131struct Location {
    32     char *file;
     32    char * file;
    3333    int line;
    3434}; // Location
    3535
    3636struct Token {
    37     std::string *str;                                                                   // must be pointer as used in union
     37    std::string * str;                                                                  // must be pointer as used in union
    3838    Location loc;
    3939
  • src/Parser/StatementNode.cc

    r71d6bd8 r7030dab  
    249249} // build_finally
    250250
     251SuspendStmt * build_suspend( StatementNode * then, SuspendStmt::Type type ) {
     252        auto node = new SuspendStmt();
     253
     254        node->type = type;
     255
     256        std::list< Statement * > stmts;
     257        buildMoveList< Statement, StatementNode >( then, stmts );
     258        if(!stmts.empty()) {
     259                assert( stmts.size() == 1 );
     260                node->then = dynamic_cast< CompoundStmt * >( stmts.front() );
     261        }
     262
     263        return node;
     264}
     265
    251266WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) {
    252267        auto node = new WaitForStmt();
  • src/Parser/TypeData.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 18:16:23 2019
    13 // Update Count     : 649
     12// Last Modified On : Mon Dec 16 07:56:46 2019
     13// Update Count     : 662
    1414//
    1515
     
    6767          case Aggregate:
    6868                // aggregate = new Aggregate_t;
    69                 aggregate.kind = DeclarationNode::NoAggregate;
     69                aggregate.kind = AggregateDecl::NoAggregate;
    7070                aggregate.name = nullptr;
    7171                aggregate.params = nullptr;
     
    345345                break;
    346346          case Aggregate:
    347                 os << DeclarationNode::aggregateNames[ aggregate.kind ] << ' ' << *aggregate.name << endl;
     347                os << AggregateDecl::aggrString( aggregate.kind ) << ' ' << *aggregate.name << endl;
    348348                if ( aggregate.params ) {
    349349                        os << string( indent + 2, ' ' ) << "with type parameters" << endl;
     
    489489        for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i, n = (DeclarationNode*)n->get_next() ) {
    490490                TypeDecl * td = static_cast<TypeDecl *>(*i);
    491                 if ( n->variable.tyClass == DeclarationNode::Otype ) {
     491                if ( n->variable.tyClass == TypeDecl::Otype ) {
    492492                        // add assertion parameters to `type' tyvars in reverse order
    493493                        // add dtor:  void ^?{}(T *)
     
    522522        switch ( td->kind ) {
    523523          case TypeData::Unknown:
    524                         // fill in implicit int
    525                         return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
     524                // fill in implicit int
     525                return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
    526526          case TypeData::Basic:
    527                         return buildBasicType( td );
     527                return buildBasicType( td );
    528528          case TypeData::Pointer:
    529                         return buildPointer( td );
     529                return buildPointer( td );
    530530          case TypeData::Array:
    531                         return buildArray( td );
     531                return buildArray( td );
    532532          case TypeData::Reference:
    533                         return buildReference( td );
     533                return buildReference( td );
    534534          case TypeData::Function:
    535                         return buildFunction( td );
     535                return buildFunction( td );
    536536          case TypeData::AggregateInst:
    537                         return buildAggInst( td );
     537                return buildAggInst( td );
    538538          case TypeData::EnumConstant:
    539                         // the name gets filled in later -- by SymTab::Validate
    540                         return new EnumInstType( buildQualifiers( td ), "" );
     539                // the name gets filled in later -- by SymTab::Validate
     540                return new EnumInstType( buildQualifiers( td ), "" );
    541541          case TypeData::SymbolicInst:
    542                         return buildSymbolicInst( td );
     542                return buildSymbolicInst( td );
    543543          case TypeData::Tuple:
    544                         return buildTuple( td );
     544                return buildTuple( td );
    545545          case TypeData::Typeof:
    546546          case TypeData::Basetypeof:
    547                         return buildTypeof( td );
     547                return buildTypeof( td );
    548548          case TypeData::Builtin:
    549                         if (td->builtintype == DeclarationNode::Zero) {
    550                                 return new ZeroType( noQualifiers );
    551                         }
    552                         else if (td->builtintype == DeclarationNode::One) {
    553                                 return new OneType( noQualifiers );
    554                         }
    555                         else {
    556                                 return new VarArgsType( buildQualifiers( td ) );
    557                         }
     549                switch ( td->builtintype ) {
     550                  case DeclarationNode::Zero:
     551                        return new ZeroType( noQualifiers );
     552                  case DeclarationNode::One:
     553                        return new OneType( noQualifiers );
     554                  default:
     555                        return new VarArgsType( buildQualifiers( td ) );
     556                } // switch
    558557          case TypeData::GlobalScope:
    559                         return new GlobalScopeType();
    560                 case TypeData::Qualified:
    561                         return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
     558                return new GlobalScopeType();
     559          case TypeData::Qualified:
     560                return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
    562561          case TypeData::Symbolic:
    563562          case TypeData::Enum:
    564563          case TypeData::Aggregate:
    565                         assert( false );
     564                assert( false );
    566565        } // switch
    567566
     
    768767        AggregateDecl * at;
    769768        switch ( td->aggregate.kind ) {
    770           case DeclarationNode::Struct:
    771           case DeclarationNode::Coroutine:
    772           case DeclarationNode::Monitor:
    773           case DeclarationNode::Thread:
     769          case AggregateDecl::Struct:
     770          case AggregateDecl::Coroutine:
     771          case AggregateDecl::Generator:
     772          case AggregateDecl::Monitor:
     773          case AggregateDecl::Thread:
    774774                at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage );
    775775                buildForall( td->aggregate.params, at->get_parameters() );
    776776                break;
    777           case DeclarationNode::Union:
     777          case AggregateDecl::Union:
    778778                at = new UnionDecl( *td->aggregate.name, attributes, linkage );
    779779                buildForall( td->aggregate.params, at->get_parameters() );
    780780                break;
    781           case DeclarationNode::Trait:
     781          case AggregateDecl::Trait:
    782782                at = new TraitDecl( *td->aggregate.name, attributes, linkage );
    783783                buildList( td->aggregate.params, at->get_parameters() );
     
    809809                          AggregateDecl * typedecl = buildAggregate( type, attributes, linkage );
    810810                          switch ( type->aggregate.kind ) {
    811                                 case DeclarationNode::Struct:
    812                                 case DeclarationNode::Coroutine:
    813                                 case DeclarationNode::Monitor:
    814                                 case DeclarationNode::Thread:
     811                                case AggregateDecl::Struct:
     812                                case AggregateDecl::Coroutine:
     813                                case AggregateDecl::Monitor:
     814                                case AggregateDecl::Thread:
    815815                                  ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
    816816                                  break;
    817                                 case DeclarationNode::Union:
     817                                case AggregateDecl::Union:
    818818                                  ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
    819819                                  break;
    820                                 case DeclarationNode::Trait:
     820                                case AggregateDecl::Trait:
    821821                                  assert( false );
    822822                                  //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
     
    827827                  } else {
    828828                          switch ( type->aggregate.kind ) {
    829                                 case DeclarationNode::Struct:
    830                                 case DeclarationNode::Coroutine:
    831                                 case DeclarationNode::Monitor:
    832                                 case DeclarationNode::Thread:
     829                                case AggregateDecl::Struct:
     830                                case AggregateDecl::Coroutine:
     831                                case AggregateDecl::Monitor:
     832                                case AggregateDecl::Thread:
    833833                                  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    834834                                  break;
    835                                 case DeclarationNode::Union:
     835                                case AggregateDecl::Union:
    836836                                  ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    837837                                  break;
    838                                 case DeclarationNode::Trait:
     838                                case AggregateDecl::Trait:
    839839                                  ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    840840                                  break;
     
    863863          case TypeData::Aggregate: {
    864864                  switch ( type->aggregate.kind ) {
    865                         case DeclarationNode::Struct:
    866                         case DeclarationNode::Coroutine:
    867                         case DeclarationNode::Monitor:
    868                         case DeclarationNode::Thread:
     865                        case AggregateDecl::Struct:
     866                        case AggregateDecl::Coroutine:
     867                        case AggregateDecl::Monitor:
     868                        case AggregateDecl::Thread:
    869869                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    870870                          break;
    871                         case DeclarationNode::Union:
     871                        case AggregateDecl::Union:
    872872                          ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    873873                          break;
    874                         case DeclarationNode::Trait:
     874                        case AggregateDecl::Trait:
    875875                          ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    876876                          break;
  • src/Parser/TypeData.h

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov  1 20:56:46 2018
    13 // Update Count     : 196
     12// Last Modified On : Fri Dec 13 23:42:35 2019
     13// Update Count     : 199
    1414//
    1515
     
    2121
    2222#include "ParseNode.h"           // for DeclarationNode, DeclarationNode::Ag...
    23 #include "Parser/LinkageSpec.h" // for Spec
     23#include "SynTree/LinkageSpec.h" // for Spec
    2424#include "SynTree/Type.h"        // for Type, ReferenceToType (ptr only)
    2525#include "SynTree/SynTree.h"     // for Visitor Nodes
     
    3030
    3131        struct Aggregate_t {
    32                 DeclarationNode::Aggregate kind;
     32                AggregateDecl::Aggregate kind;
    3333                const std::string * name = nullptr;
    3434                DeclarationNode * params = nullptr;
  • src/Parser/TypedefTable.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 25 15:32:35 2018
    13 // Update Count     : 258
     12// Last Modified On : Sat Feb 15 08:06:36 2020
     13// Update Count     : 259
    1414//
    1515
     
    4747} // TypedefTable::~TypedefTable
    4848
    49 bool TypedefTable::exists( const string & identifier ) {
     49bool TypedefTable::exists( const string & identifier ) const {
    5050        return kindTable.find( identifier ) != kindTable.end();
    5151} // TypedefTable::exists
    5252
    53 bool TypedefTable::existsCurr( const string & identifier ) {
     53bool TypedefTable::existsCurr( const string & identifier ) const {
    5454        return kindTable.findAt( kindTable.currentScope() - 1, identifier ) != kindTable.end();
    5555} // TypedefTable::exists
  • src/Parser/TypedefTable.h

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 25 15:33:55 2018
    13 // Update Count     : 114
     12// Last Modified On : Sat Feb 15 08:06:37 2020
     13// Update Count     : 117
    1414//
    1515
     
    3030        ~TypedefTable();
    3131
    32         bool exists( const std::string & identifier );
    33         bool existsCurr( const std::string & identifier );
     32        bool exists( const std::string & identifier ) const;
     33        bool existsCurr( const std::string & identifier ) const;
    3434        int isKind( const std::string & identifier ) const;
    3535        void makeTypedef( const std::string & name, int kind = TYPEDEFname );
  • src/Parser/lex.ll

    r71d6bd8 r7030dab  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sun Aug  4 20:53:47 2019
    13  * Update Count     : 719
     12 * Last Modified On : Sat Feb 15 11:05:50 2020
     13 * Update Count     : 737
    1414 */
    1515
     
    4343#include "TypedefTable.h"
    4444
     45string * build_postfix_name( string * name );
     46
    4547char *yyfilename;
    4648string *strtext;                                                                                // accumulate parts of character and string constant value
     
    6365#define FLOATXX(v) KEYWORD_RETURN(v);
    6466#else
    65 #define FLOATXX(v) IDENTIFIER_RETURN(); 
     67#define FLOATXX(v) IDENTIFIER_RETURN();
    6668#endif // HAVE_KEYWORDS_FLOATXX
    6769
     
    299301_Static_assert  { KEYWORD_RETURN(STATICASSERT); }               // C11
    300302struct                  { KEYWORD_RETURN(STRUCT); }
    301         /* suspend                      { KEYWORD_RETURN(SUSPEND); }                    // CFA */
     303suspend                 { KEYWORD_RETURN(SUSPEND); }                    // CFA
    302304switch                  { KEYWORD_RETURN(SWITCH); }
    303305thread                  { KEYWORD_RETURN(THREAD); }                             // C11
     
    330332                                /* identifier */
    331333{identifier}    { IDENTIFIER_RETURN(); }
    332 "`"{identifier}"`" {                                                                    // CFA
    333         yytext[yyleng - 1] = '\0'; yytext += 1;                         // SKULLDUGGERY: remove backquotes (ok to shorten?)
     334"``"{identifier} {                                                                              // CFA
     335        yytext[yyleng] = '\0'; yytext += 2;                                     // SKULLDUGGERY: remove backquotes (ok to shorten?)
    334336        IDENTIFIER_RETURN();
    335337}
     
    432434"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    433435"^?{}"                  { IDENTIFIER_RETURN(); }
    434 "?`"{identifier} { IDENTIFIER_RETURN(); }                               // postfix operator
     436"?`"{identifier} {                                                                              // postfix operator
     437        yylval.tok.str = new string( &yytext[2] );                      // remove ?`
     438        yylval.tok.str = build_postfix_name( yylval.tok.str ); // add prefix
     439        RETURN_LOCN( typedefTable.isKind( *yylval.tok.str ) );
     440}
    435441"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    436442        /*
  • src/Parser/module.mk

    r71d6bd8 r7030dab  
    1111## Created On       : Sat May 16 15:29:09 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Wed Jun 28 21:58:29 2017
    14 ## Update Count     : 104
     13## Last Modified On : Sat Dec 14 07:34:47 2019
     14## Update Count     : 107
    1515###############################################################################
    1616
     
    1919AM_YFLAGS = -d -t -v
    2020
    21 SRC += Parser/parser.yy \
    22        Parser/lex.ll \
    23        Parser/TypedefTable.cc \
    24        Parser/ParseNode.cc \
     21SRC += \
    2522       Parser/DeclarationNode.cc \
    2623       Parser/ExpressionNode.cc \
     24       Parser/InitializerNode.cc \
     25       Parser/ParseNode.cc \
    2726       Parser/StatementNode.cc \
    28        Parser/InitializerNode.cc \
    2927       Parser/TypeData.cc \
    30        Parser/LinkageSpec.cc \
     28       Parser/TypedefTable.cc \
     29       Parser/lex.ll \
     30       Parser/parser.yy \
    3131       Parser/parserutility.cc
    3232
    33 SRCDEMANGLE += \
    34         Parser/LinkageSpec.cc
    35 
    36 
    3733MOSTLYCLEANFILES += Parser/lex.cc Parser/parser.cc Parser/parser.hh Parser/parser.output
  • src/Parser/parser.yy

    r71d6bd8 r7030dab  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 21:48:23 2019
    13 // Update Count     : 4364
     12// Last Modified On : Fri Mar  6 17:26:45 2020
     13// Update Count     : 4474
    1414//
    1515
     
    5151using namespace std;
    5252
     53#include "SynTree/Declaration.h"
    5354#include "ParseNode.h"
    5455#include "TypedefTable.h"
    5556#include "TypeData.h"
    56 #include "LinkageSpec.h"
     57#include "SynTree/LinkageSpec.h"
    5758#include "Common/SemanticError.h"                                               // error_str
    5859#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     
    165166} // rebindForall
    166167
    167 NameExpr * build_postfix_name( const string * name ) {
    168         NameExpr * new_name = build_varref( new string( "?`" + *name ) );
    169         delete name;
    170         return new_name;
     168string * build_postfix_name( string * name ) {
     169        *name = string("__postfix_func_") + *name;
     170        return name;
    171171} // build_postfix_name
    172172
     
    210210        } // if
    211211} // forCtrl
    212 
    213212
    214213bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
     
    237236        ExpressionNode * en;
    238237        DeclarationNode * decl;
    239         DeclarationNode::Aggregate aggKey;
    240         DeclarationNode::TypeClass tclass;
     238        AggregateDecl::Aggregate aggKey;
     239        TypeDecl::Kind tclass;
    241240        StatementNode * sn;
    242241        WaitForStmt * wfs;
     
    279278%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    280279%token SIZEOF OFFSETOF
    281 // %token SUSPEND RESUME                                                                        // CFA
     280// %token RESUME                                                                        // CFA
     281%token SUSPEND                                                                  // CFA
    282282%token ATTRIBUTE EXTENSION                                                              // GCC
    283283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    323323%type<op> ptrref_operator                               unary_operator                          assignment_operator
    324324%type<en> primary_expression                    postfix_expression                      unary_expression
    325 %type<en> cast_expression                               exponential_expression          multiplicative_expression       additive_expression
     325%type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
    326326%type<en> shift_expression                              relational_expression           equality_expression
    327327%type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
     
    365365%type<decl> abstract_parameter_declaration
    366366
    367 %type<aggKey> aggregate_key
     367%type<aggKey> aggregate_key aggregate_data aggregate_control
    368368%type<decl> aggregate_type aggregate_type_nobody
    369369
     
    579579        | '(' compound_statement ')'                                            // GCC, lambda expression
    580580                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    581         | constant '`' IDENTIFIER                                                       // CFA, postfix call
    582                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
    583         | string_literal '`' IDENTIFIER                                         // CFA, postfix call
    584                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }
    585         | IDENTIFIER '`' IDENTIFIER                                                     // CFA, postfix call
    586                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); }
    587         | tuple '`' IDENTIFIER                                                          // CFA, postfix call
    588                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
    589         | '(' comma_expression ')' '`' IDENTIFIER                       // CFA, postfix call
    590                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    591581        | type_name '.' identifier                                                      // CFA, nested type
    592582                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    642632        | postfix_expression '(' argument_expression_list ')'
    643633                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
     634        | postfix_expression '`' identifier                                     // CFA, postfix call
     635                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
     636        | constant '`' identifier                                                       // CFA, postfix call
     637                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
     638        | string_literal '`' identifier                                         // CFA, postfix call
     639                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
    644640        | postfix_expression '.' identifier
    645641                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
     
    650646        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
    651647                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     648        | postfix_expression '.' aggregate_control
     649                { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }
    652650        | postfix_expression ARROW identifier
    653651                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    664662        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    665663                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    666         | '^' primary_expression '{' argument_expression_list '}' // CFA
     664        | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call
    667665                {
    668666                        Token fn;
     
    677675        | argument_expression
    678676        | argument_expression_list ',' argument_expression
    679                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     677                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    680678        ;
    681679
     
    689687field_name_list:                                                                                // CFA, tuple field selector
    690688        field
    691         | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     689        | field_name_list ',' field                                     { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    692690        ;
    693691
     
    793791        | '(' type_no_function ')' cast_expression
    794792                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    795                 // keyword cast cannot be grouped because of reduction in aggregate_key
    796         | '(' GENERATOR '&' ')' cast_expression                         // CFA
    797                 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
    798         | '(' COROUTINE '&' ')' cast_expression                         // CFA
    799                 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
    800         | '(' THREAD '&' ')' cast_expression                            // CFA
    801                 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); }
    802         | '(' MONITOR '&' ')' cast_expression                           // CFA
    803                 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); }
     793        | '(' aggregate_control '&' ')' cast_expression         // CFA
     794                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    804795                // VIRTUAL cannot be opt because of look ahead issues
    805796        | '(' VIRTUAL ')' cast_expression                                       // CFA
     
    928919        conditional_expression
    929920        | unary_expression assignment_operator assignment_expression
    930                 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
     921                {
     922                        if ( $2 == OperKinds::AtAssn ) {
     923                                SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr;
     924                        } else {
     925                                $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) );
     926                        } // if
     927                }
    931928        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
    932929                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
     
    965962                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    966963        | '[' push assignment_expression pop ',' tuple_expression_list ']'
    967                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
     964                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); }
    968965        ;
    969966
     
    971968        assignment_expression_opt
    972969        | tuple_expression_list ',' assignment_expression_opt
    973                 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     970                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    974971        ;
    975972
     
    11951192                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11961193                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1194        | '=' comma_expression                                                                  // CFA
     1195                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1196                                                OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11971197        | comma_expression inclexcl comma_expression            // CFA
    11981198                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12021202                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12031203                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1204        | comma_expression ';' '=' comma_expression                             // CFA
     1205                { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1206                                                OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    12041207        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    12051208                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12631266        | RETURN '{' initializer_list_opt comma_opt '}' ';'
    12641267                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    1265         // | SUSPEND ';'
    1266         //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
    1267         // | SUSPEND compound_statement ';'
    1268         //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1268        | SUSPEND ';'
     1269                { $$ = new StatementNode( build_suspend( nullptr ) ); }
     1270        | SUSPEND compound_statement
     1271                { $$ = new StatementNode( build_suspend( $2 ) ); }
     1272        | SUSPEND COROUTINE ';'
     1273                { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); }
     1274        | SUSPEND COROUTINE compound_statement
     1275                { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); }
     1276        | SUSPEND GENERATOR ';'
     1277                { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); }
     1278        | SUSPEND GENERATOR compound_statement
     1279                { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); }
    12691280        | THROW assignment_expression_opt ';'                           // handles rethrow
    12701281                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    13061317        WAITFOR '(' cast_expression ')'
    13071318                { $$ = $3; }
    1308         | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1309                 { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     1319//      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1320//              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     1321        | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
     1322                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
     1323        ;
     1324
     1325cast_expression_list:
     1326        cast_expression
     1327        | cast_expression_list ',' cast_expression
     1328                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    13101329        ;
    13111330
     
    14181437        asm_operand
    14191438        | asm_operands_list ',' asm_operand
    1420                 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     1439                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    14211440        ;
    14221441
     
    14341453                { $$ = new ExpressionNode( $1 ); }
    14351454        | asm_clobbers_list_opt ',' string_literal
    1436                 // set_last returns ParseNode *
    1437                 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
     1455                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
    14381456        ;
    14391457
     
    15861604                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    15871605                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1588         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1606        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    15891607                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1590                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    1591         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    1592                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1608                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
     1609        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
     1610                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
    15931611        ;
    15941612
     
    20592077
    20602078aggregate_key:
     2079        aggregate_data
     2080        | aggregate_control
     2081        ;
     2082
     2083aggregate_data:
    20612084        STRUCT
    2062                 { yyy = true; $$ = DeclarationNode::Struct; }
     2085                { yyy = true; $$ = AggregateDecl::Struct; }
    20632086        | UNION
    2064                 { yyy = true; $$ = DeclarationNode::Union; }
    2065         | EXCEPTION
    2066                 { yyy = true; $$ = DeclarationNode::Exception; }
    2067         | GENERATOR
    2068                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     2087                { yyy = true; $$ = AggregateDecl::Union; }
     2088        | EXCEPTION                                                                                     // CFA
     2089                { yyy = true; $$ = AggregateDecl::Exception; }
     2090        ;
     2091
     2092aggregate_control:                                                                              // CFA
     2093        GENERATOR
     2094                { yyy = true; $$ = AggregateDecl::Generator; }
     2095        | MONITOR GENERATOR
     2096                { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20692097        | COROUTINE
    2070                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     2098                { yyy = true; $$ = AggregateDecl::Coroutine; }
    20712099        | MONITOR
    2072                 { yyy = true; $$ = DeclarationNode::Monitor; }
     2100                { yyy = true; $$ = AggregateDecl::Monitor; }
     2101        | MONITOR COROUTINE
     2102                { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20732103        | THREAD
    2074                 { yyy = true; $$ = DeclarationNode::Thread; }
     2104                { yyy = true; $$ = AggregateDecl::Thread; }
     2105        | MONITOR THREAD
     2106                { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20752107        ;
    20762108
     
    20962128                        distInl( $3 );
    20972129                }
     2130        | INLINE aggregate_control ';'                                          // CFA
     2131                { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
    20982132        | typedef_declaration ';'                                                       // CFA
    20992133        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
     
    23482382        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    23492383        | initializer_list_opt ',' designation initializer
    2350                 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
     2384                { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
    23512385        ;
    23522386
     
    23702404        designator
    23712405        | designator_list designator
    2372                 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
     2406                { $$ = (ExpressionNode *)($1->set_last( $2 )); }
    23732407        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    23742408        ;
     
    24262460        | type_specifier identifier_parameter_declarator
    24272461        | assertion_list
    2428                 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
     2462                { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    24292463        ;
    24302464
    24312465type_class:                                                                                             // CFA
    24322466        OTYPE
    2433                 { $$ = DeclarationNode::Otype; }
     2467                { $$ = TypeDecl::Otype; }
    24342468        | DTYPE
    2435                 { $$ = DeclarationNode::Dtype; }
     2469                { $$ = TypeDecl::Dtype; }
    24362470        | FTYPE
    2437                 { $$ = DeclarationNode::Ftype; }
     2471                { $$ = TypeDecl::Ftype; }
    24382472        | TTYPE
    2439                 { $$ = DeclarationNode::Ttype; }
     2473                { $$ = TypeDecl::Ttype; }
    24402474        ;
    24412475
     
    24672501                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    24682502        | type_list ',' type
    2469                 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
     2503                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }
    24702504        | type_list ',' assignment_expression
    24712505                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     
    25782612                {
    25792613                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2580                         linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
     2614                        linkage = LinkageSpec::update( yylloc, linkage, $2 );
    25812615                }
    25822616          '{' up external_definition_list_opt down '}'
  • src/ResolvExpr/AdjustExprType.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sat May 16 23:41:42 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:34:53 2016
    13 // Update Count     : 4
     12// Last Modified On : Wed Dec 11 21:43:56 2019
     13// Update Count     : 6
    1414//
    1515
     
    134134                        // replace known function-type-variables with pointer-to-function
    135135                        if ( const ast::EqvClass * eqvClass = tenv.lookup( inst->name ) ) {
    136                                 if ( eqvClass->data.kind == ast::TypeVar::Ftype ) {
     136                                if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) {
    137137                                        return new ast::PointerType{ inst };
    138138                                }
    139139                        } else if ( const ast::NamedTypeDecl * ntDecl = symtab.lookupType( inst->name ) ) {
    140140                                if ( auto tyDecl = dynamic_cast< const ast::TypeDecl * >( ntDecl ) ) {
    141                                         if ( tyDecl->kind == ast::TypeVar::Ftype ) {
     141                                        if ( tyDecl->kind == ast::TypeDecl::Ftype ) {
    142142                                                return new ast::PointerType{ inst };
    143143                                        }
  • src/ResolvExpr/AlternativeFinder.cc

    r71d6bd8 r7030dab  
    6969                void postvisit( CastExpr * castExpr );
    7070                void postvisit( VirtualCastExpr * castExpr );
     71                void postvisit( KeywordCastExpr * castExpr );
    7172                void postvisit( UntypedMemberExpr * memberExpr );
    7273                void postvisit( MemberExpr * memberExpr );
     
    12551256        }
    12561257
     1258        void AlternativeFinder::Finder::postvisit( KeywordCastExpr * castExpr ) {
     1259                assertf( castExpr->get_result(), "Cast target should have been set in Validate." );
     1260                auto ref = dynamic_cast<ReferenceType*>(castExpr->get_result());
     1261                assert(ref);
     1262                auto inst = dynamic_cast<StructInstType*>(ref->base);
     1263                assert(inst);
     1264                auto target = inst->baseStruct;
     1265
     1266                AlternativeFinder finder( indexer, env );
     1267
     1268                auto pick_alternatives = [target, this](AltList & found, bool expect_ref) {
     1269                        for(auto & alt : found) {
     1270                                Type * expr = alt.expr->get_result();
     1271                                if(expect_ref) {
     1272                                        auto res = dynamic_cast<ReferenceType*>(expr);
     1273                                        if(!res) { continue; }
     1274                                        expr = res->base;
     1275                                }
     1276
     1277                                if(auto insttype = dynamic_cast<TypeInstType*>(expr)) {
     1278                                        auto td = alt.env.lookup(insttype->name);
     1279                                        if(!td) { continue; }
     1280                                        expr = td->type;
     1281                                }
     1282
     1283                                if(auto base = dynamic_cast<StructInstType*>(expr)) {
     1284                                        if(base->baseStruct == target) {
     1285                                                alternatives.push_back(
     1286                                                        std::move(alt)
     1287                                                );
     1288                                        }
     1289                                }
     1290                        }
     1291                };
     1292
     1293                try {
     1294                        // Attempt 1 : turn (thread&)X into ($thread&)X.__thrd
     1295                        // Clone is purely for memory management
     1296                        std::unique_ptr<Expression> tech1 { new UntypedMemberExpr(new NameExpr(castExpr->concrete_target.field), castExpr->arg->clone()) };
     1297
     1298                        // don't prune here, since it's guaranteed all alternatives will have the same type
     1299                        finder.findWithoutPrune( tech1.get() );
     1300                        pick_alternatives(finder.alternatives, false);
     1301
     1302                        return;
     1303                } catch(SemanticErrorException & ) {}
     1304
     1305                // Fallback : turn (thread&)X into ($thread&)get_thread(X)
     1306                std::unique_ptr<Expression> fallback { UntypedExpr::createDeref( new UntypedExpr(new NameExpr(castExpr->concrete_target.getter), { castExpr->arg->clone() })) };
     1307                // don't prune here, since it's guaranteed all alternatives will have the same type
     1308                finder.findWithoutPrune( fallback.get() );
     1309
     1310                pick_alternatives(finder.alternatives, true);
     1311
     1312                // Whatever happens here, we have no more fallbacks
     1313        }
     1314
    12571315        namespace {
    12581316                /// Gets name from untyped member expression (member must be NameExpr)
  • src/ResolvExpr/PtrsCastable.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sun May 17 11:48:00 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:36:18 2016
    13 // Update Count     : 8
     12// Last Modified On : Wed Dec 11 21:48:33 2019
     13// Update Count     : 9
    1414//
    1515
     
    176176                        if ( const ast::NamedTypeDecl * named = symtab.lookupType( inst->name ) ) {
    177177                                if ( auto tyDecl = dynamic_cast< const ast::TypeDecl * >( named ) ) {
    178                                         if ( tyDecl->kind == ast::TypeVar::Ftype ) {
     178                                        if ( tyDecl->kind == ast::TypeDecl::Ftype ) {
    179179                                                return -1;
    180180                                        }
    181181                                }
    182182                        } else if ( const ast::EqvClass * eqvClass = env.lookup( inst->name ) ) {
    183                                 if ( eqvClass->data.kind == ast::TypeVar::Ftype ) {
     183                                if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) {
    184184                                        return -1;
    185185                                }
  • src/ResolvExpr/Resolver.cc

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 29 11:00:00 2019
    13 // Update Count     : 241
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Mar 27 11:58:00 2020
     13// Update Count     : 242
    1414//
    1515
     
    8484                void previsit( ThrowStmt * throwStmt );
    8585                void previsit( CatchStmt * catchStmt );
     86                void postvisit( CatchStmt * catchStmt );
    8687                void previsit( WaitForStmt * stmt );
    8788
     
    559560                // TODO: Replace *exception type with &exception type.
    560561                if ( throwStmt->get_expr() ) {
    561                         const StructDecl * exception_decl = indexer.lookupStruct( "__cfaabi_ehm__base_exception_t" );
     562                        const StructDecl * exception_decl = indexer.lookupStruct( "__cfaehm_base_exception_t" );
    562563                        assert( exception_decl );
    563564                        Type * exceptType = new PointerType( noQualifiers, new StructInstType( noQualifiers, const_cast<StructDecl *>(exception_decl) ) );
     
    567568
    568569        void Resolver_old::previsit( CatchStmt * catchStmt ) {
     570                // Until we are very sure this invarent (ifs that move between passes have thenPart)
     571                // holds, check it. This allows a check for when to decode the mangling.
     572                if ( IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ) ) {
     573                        assert( ifStmt->thenPart );
     574                }
     575                // Encode the catchStmt so the condition can see the declaration.
    569576                if ( catchStmt->cond ) {
    570                         findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer );
     577                        IfStmt * ifStmt = new IfStmt( catchStmt->cond, nullptr, catchStmt->body );
     578                        catchStmt->cond = nullptr;
     579                        catchStmt->body = ifStmt;
     580                }
     581        }
     582
     583        void Resolver_old::postvisit( CatchStmt * catchStmt ) {
     584                // Decode the catchStmt so everything is stored properly.
     585                IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body );
     586                if ( nullptr != ifStmt && nullptr == ifStmt->thenPart ) {
     587                        assert( ifStmt->condition );
     588                        assert( ifStmt->elsePart );
     589                        catchStmt->cond = ifStmt->condition;
     590                        catchStmt->body = ifStmt->elsePart;
     591                        ifStmt->condition = nullptr;
     592                        ifStmt->elsePart = nullptr;
     593                        delete ifStmt;
    571594                }
    572595        }
     
    14541477                if ( throwStmt->expr ) {
    14551478                        const ast::StructDecl * exceptionDecl =
    1456                                 symtab.lookupStruct( "__cfaabi_ehm__base_exception_t" );
     1479                                symtab.lookupStruct( "__cfaehm_base_exception_t" );
    14571480                        assert( exceptionDecl );
    14581481                        ast::ptr< ast::Type > exceptType =
     
    14661489
    14671490        const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) {
     1491                // TODO: This will need a fix for the decl/cond scoping problem.
    14681492                if ( catchStmt->cond ) {
    14691493                        ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool };
  • src/ResolvExpr/Unify.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:27:10 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Sep  4 10:00:00 2019
    13 // Update Count     : 44
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:43:05 2019
     13// Update Count     : 46
    1414//
    1515
     
    3434#include "Common/PassVisitor.h"     // for PassVisitor
    3535#include "FindOpenVars.h"           // for findOpenVars
    36 #include "Parser/LinkageSpec.h"     // for C
     36#include "SynTree/LinkageSpec.h"    // for C
    3737#include "SynTree/Constant.h"       // for Constant
    3838#include "SynTree/Declaration.h"    // for TypeDecl, TypeDecl::Data, Declarati...
     
    771771                                if ( const ast::EqvClass * clz = tenv.lookup( typeInst->name ) ) {
    772772                                        // expand ttype parameter into its actual type
    773                                         if ( clz->data.kind == ast::TypeVar::Ttype && clz->bound ) {
     773                                        if ( clz->data.kind == ast::TypeDecl::Ttype && clz->bound ) {
    774774                                                return clz->bound;
    775775                                        }
  • src/SymTab/Autogen.h

    r71d6bd8 r7030dab  
    1010// Created On       : Sun May 17 21:53:34 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:50:25 2017
    13 // Update Count     : 15
     12// Last Modified On : Fri Dec 13 16:38:06 2019
     13// Update Count     : 16
    1414//
    1515
     
    3535#include "SynTree/Expression.h"   // for NameExpr, ConstantExpr, UntypedExpr...
    3636#include "SynTree/Type.h"         // for Type, ArrayType, Type::Qualifiers
     37#include "SynTree/Statement.h"    // for CompoundStmt, DeclStmt, ExprStmt
    3738
    3839class CompoundStmt;
  • src/SymTab/Demangle.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Thu Jul 19 12:52:41 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 30 13:46:33 2019
    13 // Update Count     : 3
     12// Last Modified On : Tue Feb 11 15:09:18 2020
     13// Update Count     : 10
    1414//
    1515
     
    1919#include "CodeGen/GenType.h"
    2020#include "Common/PassVisitor.h"
     21#include "Common/utility.h"                                                             // isPrefix
    2122#include "Mangler.h"
    2223#include "SynTree/Type.h"
     
    366367                                // type variable types
    367368                                for (size_t k = 0; k < TypeDecl::NUMBER_OF_KINDS; ++k) {
    368                                         static const std::string typeVariableNames[] = { "DT", "FT", "TT", };
     369                                        static const std::string typeVariableNames[] = { "DT", "OT", "FT", "TT", };
    369370                                        static_assert(
    370371                                                sizeof(typeVariableNames)/sizeof(typeVariableNames[0]) == TypeDecl::NUMBER_OF_KINDS,
     
    416417
    417418                        bool StringView::isPrefix(const std::string & pref) {
    418                                 if ( pref.size() > str.size()-idx ) return false;
    419                                 auto its = std::mismatch( pref.begin(), pref.end(), std::next(str.begin(), idx) );
    420                                 if (its.first == pref.end()) {
     419                                // if ( pref.size() > str.size()-idx ) return false;
     420                                // auto its = std::mismatch( pref.begin(), pref.end(), std::next(str.begin(), idx) );
     421                                // if (its.first == pref.end()) {
     422                                //      idx += pref.size();
     423                                //      return true;
     424                                // }
     425
     426                                // This update is untested because there are no tests for this code.
     427                                if ( ::isPrefix( str, pref, idx ) ) {
    421428                                        idx += pref.size();
    422429                                        return true;
     
    429436                                PRINT( std::cerr << "====== " << str.size() << " " << str << std::endl; )
    430437                                if (str.size() < 2+Encoding::manglePrefix.size()) return false; // +2 for at least _1 suffix
    431                                 if (! isPrefix(Encoding::manglePrefix) || ! isdigit(str.back())) return false;
     438                                if ( ! isPrefix(Encoding::manglePrefix) || ! isdigit(str.back() ) ) return false;
    432439
    433440                                // get name
  • src/SymTab/Indexer.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:37:33 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Fri Mar  8 13:55:00 2019
    13 // Update Count     : 21
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:43:19 2019
     13// Update Count     : 22
    1414//
    1515
     
    3131#include "InitTweak/InitTweak.h"   // for isConstructor, isCopyFunction, isC...
    3232#include "Mangler.h"               // for Mangler
    33 #include "Parser/LinkageSpec.h"    // for isMangled, isOverridable, Spec
    3433#include "ResolvExpr/typeops.h"    // for typesCompatible
     34#include "SynTree/LinkageSpec.h"   // for isMangled, isOverridable, Spec
    3535#include "SynTree/Constant.h"      // for Constant
    3636#include "SynTree/Declaration.h"   // for DeclarationWithType, FunctionDecl
  • src/SymTab/Mangler.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sun May 17 21:40:29 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 30 13:46:10 2019
    13 // Update Count     : 26
     12// Last Modified On : Sat Feb 15 13:55:12 2020
     13// Update Count     : 33
    1414//
    1515#include "Mangler.h"
     
    2626#include "Common/SemanticError.h"        // for SemanticError
    2727#include "Common/utility.h"              // for toString
    28 #include "Parser/LinkageSpec.h"          // for Spec, isOverridable, AutoGen, Int...
    2928#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
     29#include "SynTree/LinkageSpec.h"         // for Spec, isOverridable, AutoGen, Int...
    3030#include "SynTree/Declaration.h"         // for TypeDecl, DeclarationWithType
    3131#include "SynTree/Expression.h"          // for TypeExpr, Expression, operator<<
     
    128128                                } // if
    129129                                mangleName << Encoding::manglePrefix;
    130                                 CodeGen::OperatorInfo opInfo;
    131                                 if ( operatorLookup( declaration->get_name(), opInfo ) ) {
    132                                         mangleName << opInfo.outputName.size() << opInfo.outputName;
     130                                const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( declaration->get_name() );
     131                                if ( opInfo ) {
     132                                        mangleName << opInfo->outputName.size() << opInfo->outputName;
    133133                                } else {
    134134                                        mangleName << declaration->name.size() << declaration->name;
     
    471471                        } // if
    472472                        mangleName << Encoding::manglePrefix;
    473                         CodeGen::OperatorInfo opInfo;
    474                         if ( operatorLookup( decl->name, opInfo ) ) {
    475                                 mangleName << opInfo.outputName.size() << opInfo.outputName;
     473                        const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( decl->name );
     474                        if ( opInfo ) {
     475                                mangleName << opInfo->outputName.size() << opInfo->outputName;
    476476                        } else {
    477477                                mangleName << decl->name.size() << decl->name;
     
    654654                        // aside from the assert false.
    655655                        assertf(false, "Mangler_new should not visit typedecl: %s", toCString(decl));
    656                         assertf( decl->kind < ast::TypeVar::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind );
     656                        assertf( decl->kind < ast::TypeDecl::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind );
    657657                        mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) << decl->name;
    658658                }
     
    674674                                        for ( const ast::TypeDecl * decl : ptype->forall ) {
    675675                                                switch ( decl->kind ) {
    676                                                 case ast::TypeVar::Kind::Dtype:
     676                                                case ast::TypeDecl::Kind::Dtype:
    677677                                                        dcount++;
    678678                                                        break;
    679                                                 case ast::TypeVar::Kind::Ftype:
     679                                                case ast::TypeDecl::Kind::Ftype:
    680680                                                        fcount++;
    681681                                                        break;
    682                                                 case ast::TypeVar::Kind::Ttype:
     682                                                case ast::TypeDecl::Kind::Ttype:
    683683                                                        vcount++;
    684684                                                        break;
  • src/SymTab/ManglerCommon.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Sun May 17 21:44:03 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 14 17:06:37 2019
    13 // Update Count     : 26
     12// Last Modified On : Fri Dec 13 14:54:38 2019
     13// Update Count     : 28
    1414//
    1515
     
    104104                        const std::string typeVariables[] = {
    105105                                "BD", // dtype
     106                                "BO", // otype
    106107                                "BF", // ftype
    107108                                "BT", // ttype
  • src/SymTab/Validate.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  7 6:42:00 2019
    13 // Update Count     : 360
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:43:34 2019
     13// Update Count     : 363
    1414//
    1515
     
    6969#include "InitTweak/GenInit.h"         // for fixReturnStatements
    7070#include "InitTweak/InitTweak.h"       // for isCtorDtorAssign
    71 #include "Parser/LinkageSpec.h"        // for C
    7271#include "ResolvExpr/typeops.h"        // for typesCompatible
    7372#include "ResolvExpr/Resolver.h"       // for findSingleExpression
    7473#include "ResolvExpr/ResolveTypeof.h"  // for resolveTypeof
    7574#include "SymTab/Autogen.h"            // for SizeType
     75#include "SynTree/LinkageSpec.h"       // for C
    7676#include "SynTree/Attribute.h"         // for noAttributes, Attribute
    7777#include "SynTree/Constant.h"          // for Constant
     
    311311                        Stats::Heap::newPass("validate-A");
    312312                        Stats::Time::BlockGuard guard("validate-A");
     313                        VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    313314                        acceptAll( translationUnit, hoistDecls );
    314315                        ReplaceTypedef::replaceTypedef( translationUnit );
     
    336337                        Stats::Time::BlockGuard guard("validate-C");
    337338                        acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old
    338                         VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    339339                        ReturnChecker::checkFunctionReturns( translationUnit );
    340340                        InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
     
    375375                        Stats::Heap::newPass("validate-F");
    376376                        Stats::Time::BlockGuard guard("validate-F");
    377                         Stats::Time::TimeBlock("Fix Object Type", [&]() {
    378                                 FixObjectType::fix( translationUnit );
    379                         });
    380                         Stats::Time::TimeBlock("Array Length", [&]() {
    381                                 ArrayLength::computeLength( translationUnit );
    382                         });
    383                         Stats::Time::TimeBlock("Find Special Declarations", [&]() {
    384                                 Validate::findSpecialDecls( translationUnit );
    385                         });
    386                         Stats::Time::TimeBlock("Fix Label Address", [&]() {
    387                                 mutateAll( translationUnit, labelAddrFixer );
    388                         });
    389                         Stats::Time::TimeBlock("Handle Attributes", [&]() {
    390                                 Validate::handleAttributes( translationUnit );
    391                         });
     377                        Stats::Time::TimeCall("Fix Object Type",
     378                                FixObjectType::fix, translationUnit);
     379                        Stats::Time::TimeCall("Array Length",
     380                                ArrayLength::computeLength, translationUnit);
     381                        Stats::Time::TimeCall("Find Special Declarations",
     382                                Validate::findSpecialDecls, translationUnit);
     383                        Stats::Time::TimeCall("Fix Label Address",
     384                                mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer);
     385                        Stats::Time::TimeCall("Handle Attributes",
     386                                Validate::handleAttributes, translationUnit);
    392387                }
    393388        }
     
    10491044                Type * designatorType = tyDecl->base->stripDeclarator();
    10501045                if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    1051                         declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) );
     1046                        declsToAddBefore.push_back( new StructDecl( aggDecl->name, AggregateDecl::Struct, noAttributes, tyDecl->linkage ) );
    10521047                } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    10531048                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
     
    11871182                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    11881183                        if ( params.size() == 0 ) {
    1189                                 SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
     1184                                SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." );
    11901185                        }
    11911186                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    11921187                        if ( ! refType ) {
    1193                                 SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
     1188                                SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." );
    11941189                        }
    11951190                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    1196                                 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
     1191                                if(!returnVals.front()->get_type()->isVoid()) {
     1192                                        SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." );
     1193                                }
    11971194                        }
    11981195                }
  • src/SynTree/AggregateDecl.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 23:56:39 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug  4 14:22:00 2017
    13 // Update Count     : 22
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 16 15:07:20 2019
     13// Update Count     : 31
    1414//
    1515
     
    2121#include "Common/utility.h"      // for printAll, cloneAll, deleteAll
    2222#include "Declaration.h"         // for AggregateDecl, TypeDecl, Declaration
    23 #include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
     23#include "Initializer.h"
     24#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
    2425#include "Type.h"                // for Type, Type::StorageClasses
    2526
     27
     28// These must harmonize with the corresponding AggregateDecl::Aggregate enumerations.
     29static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" };
     30
     31const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) {
     32        return aggregateNames[aggr];
     33}
    2634
    2735AggregateDecl::AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, Type::StorageClasses(), linkage ), body( false ), attributes( attributes ) {
     
    4755        os << typeString() << " " << name << ":";
    4856        if ( get_linkage() != LinkageSpec::Cforall ) {
    49                 os << " " << LinkageSpec::linkageName( linkage );
     57                os << " " << LinkageSpec::name( linkage );
    5058        } // if
    5159        os << " with body " << has_body();
     
    7886}
    7987
    80 std::string StructDecl::typeString() const { return "struct"; }
     88const char * StructDecl::typeString() const { return aggrString( kind ); }
    8189
    82 std::string UnionDecl::typeString() const { return "union"; }
     90const char * UnionDecl::typeString() const { return aggrString( Union ); }
    8391
    84 std::string EnumDecl::typeString() const { return "enum"; }
     92const char * EnumDecl::typeString() const { return aggrString( Enum ); }
    8593
    86 std::string TraitDecl::typeString() const { return "trait"; }
     94const char * TraitDecl::typeString() const { return aggrString( Trait ); }
    8795
    8896bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) {
  • src/SynTree/Attribute.h

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:14 2017
    13 // Update Count     : 39
     12// Last Modified On : Thu Feb 13 21:34:08 2020
     13// Update Count     : 40
    1414//
    1515
     
    3838        virtual ~Attribute();
    3939
    40         std::string get_name() const { return name; }
     40        const std::string & get_name() const { return name; }
    4141        void set_name( const std::string & newValue ) { name = newValue; }
    4242        std::list< Expression * > & get_parameters() { return parameters; }
  • src/SynTree/Declaration.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  9 14:38:00 2017
    13 // Update Count     : 25
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:39:56 2019
     13// Update Count     : 36
    1414//
    1515
     
    2424#include "SynTree/Statement.h"       // for AsmStmt
    2525#include "SynTree/SynTree.h"         // for UniqueId
     26#include "SynTree/Expression.h"
    2627#include "Type.h"                    // for Type, Type::StorageClasses
    2728
     29// To canonicalize declarations
    2830static UniqueId lastUniqueId = 0;
    2931
  • src/SynTree/Declaration.h

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May  2 10:47:00 2019
    13 // Update Count     : 135
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:11:22 2019
     13// Update Count     : 157
    1414//
    1515
     
    2424#include "BaseSyntaxNode.h"      // for BaseSyntaxNode
    2525#include "Mutator.h"             // for Mutator
    26 #include "Parser/LinkageSpec.h"  // for Spec, Cforall
    27 #include "Parser/ParseNode.h"    // for DeclarationNode, DeclarationNode::Ag...
     26#include "LinkageSpec.h"         // for Spec, Cforall
    2827#include "SynTree.h"             // for UniqueId
    2928#include "SynTree/Type.h"        // for Type, Type::StorageClasses, Type::Fu...
     
    4443        bool extension = false;
    4544
    46         Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
    47         Declaration( const Declaration &other );
     45        Declaration( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
     46        Declaration( const Declaration & other );
    4847        virtual ~Declaration();
    4948
    50         const std::string &get_name() const { return name; }
     49        const std::string & get_name() const { return name; }
    5150        void set_name( std::string newValue ) { name = newValue; }
    5251
     
    5958
    6059        bool get_extension() const { return extension; }
    61         Declaration *set_extension( bool exten ) { extension = exten; return this; }
     60        Declaration * set_extension( bool exten ) { extension = exten; return this; }
    6261
    6362        void fixUniqueId( void );
    64         virtual Declaration *clone() const override = 0;
     63        virtual Declaration * clone() const override = 0;
    6564        virtual void accept( Visitor & v ) override = 0;
    6665        virtual void accept( Visitor & v ) const override = 0;
    67         virtual Declaration *acceptMutator( Mutator &m ) override = 0;
    68         virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
    69         virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0;
     66        virtual Declaration * acceptMutator( Mutator & m ) override = 0;
     67        virtual void print( std::ostream & os, Indenter indent = {} ) const override = 0;
     68        virtual void printShort( std::ostream & os, Indenter indent = {} ) const = 0;
    7069
    7170        UniqueId uniqueId;
     
    8180        int scopeLevel = 0;
    8281
    83         Expression *asmName;
     82        Expression * asmName;
    8483        std::list< Attribute * > attributes;
    8584        bool isDeleted = false;
    8685
    87         DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
    88         DeclarationWithType( const DeclarationWithType &other );
     86        DeclarationWithType( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
     87        DeclarationWithType( const DeclarationWithType & other );
    8988        virtual ~DeclarationWithType();
    9089
     
    9796        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
    9897
    99         Expression *get_asmName() const { return asmName; }
    100         DeclarationWithType * set_asmName( Expression *newValue ) { asmName = newValue; return this; }
     98        Expression * get_asmName() const { return asmName; }
     99        DeclarationWithType * set_asmName( Expression * newValue ) { asmName = newValue; return this; }
    101100
    102101        std::list< Attribute * >& get_attributes() { return attributes; }
     
    106105        //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
    107106
    108         virtual DeclarationWithType *clone() const override = 0;
    109         virtual DeclarationWithType *acceptMutator( Mutator &m )  override = 0;
     107        virtual DeclarationWithType * clone() const override = 0;
     108        virtual DeclarationWithType * acceptMutator( Mutator & m )  override = 0;
    110109
    111110        virtual Type * get_type() const = 0;
     
    119118        typedef DeclarationWithType Parent;
    120119  public:
    121         Type *type;
    122         Initializer *init;
    123         Expression *bitfieldWidth;
    124 
    125         ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
     120        Type * type;
     121        Initializer * init;
     122        Expression * bitfieldWidth;
     123
     124        ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression * bitfieldWidth, Type * type, Initializer * init,
    126125                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
    127         ObjectDecl( const ObjectDecl &other );
     126        ObjectDecl( const ObjectDecl & other );
    128127        virtual ~ObjectDecl();
    129128
    130129        virtual Type * get_type() const override { return type; }
    131         virtual void set_type(Type *newType) override { type = newType; }
    132 
    133         Initializer *get_init() const { return init; }
    134         void set_init( Initializer *newValue ) { init = newValue; }
    135 
    136         Expression *get_bitfieldWidth() const { return bitfieldWidth; }
    137         void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
     130        virtual void set_type(Type * newType) override { type = newType; }
     131
     132        Initializer * get_init() const { return init; }
     133        void set_init( Initializer * newValue ) { init = newValue; }
     134
     135        Expression * get_bitfieldWidth() const { return bitfieldWidth; }
     136        void set_bitfieldWidth( Expression * newValue ) { bitfieldWidth = newValue; }
    138137
    139138        static ObjectDecl * newObject( const std::string & name, Type * type, Initializer * init );
    140139
    141         virtual ObjectDecl *clone() const override { return new ObjectDecl( *this ); }
    142         virtual void accept( Visitor & v ) override { v.visit( this ); }
    143         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    144         virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    145         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    146         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     140        virtual ObjectDecl * clone() const override { return new ObjectDecl( *this ); }
     141        virtual void accept( Visitor & v ) override { v.visit( this ); }
     142        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     143        virtual DeclarationWithType * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     144        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     145        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    147146};
    148147
     
    150149        typedef DeclarationWithType Parent;
    151150  public:
    152         FunctionType *type;
    153         CompoundStmt *statements;
     151        FunctionType * type;
     152        CompoundStmt * statements;
    154153        std::list< Expression * > withExprs;
    155154
    156         FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
     155        FunctionDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType * type, CompoundStmt * statements,
    157156                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
    158         FunctionDecl( const FunctionDecl &other );
     157        FunctionDecl( const FunctionDecl & other );
    159158        virtual ~FunctionDecl();
    160159
     
    163162
    164163        FunctionType * get_functionType() const { return type; }
    165         void set_functionType( FunctionType *newValue ) { type = newValue; }
    166         CompoundStmt *get_statements() const { return statements; }
    167         void set_statements( CompoundStmt *newValue ) { statements = newValue; }
     164        void set_functionType( FunctionType * newValue ) { type = newValue; }
     165        CompoundStmt * get_statements() const { return statements; }
     166        void set_statements( CompoundStmt * newValue ) { statements = newValue; }
    168167        bool has_body() const { return NULL != statements; }
    169168
    170169        static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements );
    171170
    172         virtual FunctionDecl *clone() const override { return new FunctionDecl( *this ); }
    173         virtual void accept( Visitor & v ) override { v.visit( this ); }
    174         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    175         virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    176         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    177         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     171        virtual FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
     172        virtual void accept( Visitor & v ) override { v.visit( this ); }
     173        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     174        virtual DeclarationWithType * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     175        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     176        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    178177};
    179178
     
    181180        typedef Declaration Parent;
    182181  public:
    183         Type *base;
    184         std::list< TypeDecl* > parameters;
    185         std::list< DeclarationWithType* > assertions;
    186 
    187         NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
    188         NamedTypeDecl( const NamedTypeDecl &other );
     182        Type * base;
     183        std::list< TypeDecl * > parameters;
     184        std::list< DeclarationWithType * > assertions;
     185
     186        NamedTypeDecl( const std::string & name, Type::StorageClasses scs, Type * type );
     187        NamedTypeDecl( const NamedTypeDecl & other );
    189188        virtual ~NamedTypeDecl();
    190189
    191         Type *get_base() const { return base; }
    192         void set_base( Type *newValue ) { base = newValue; }
    193         std::list< TypeDecl* >& get_parameters() { return parameters; }
    194         std::list< DeclarationWithType* >& get_assertions() { return assertions; }
    195 
    196         virtual std::string typeString() const = 0;
    197 
    198         virtual NamedTypeDecl *clone() const override = 0;
    199         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    200         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     190        Type * get_base() const { return base; }
     191        void set_base( Type * newValue ) { base = newValue; }
     192        std::list< TypeDecl* > & get_parameters() { return parameters; }
     193        std::list< DeclarationWithType * >& get_assertions() { return assertions; }
     194
     195        virtual const char * typeString() const = 0;
     196
     197        virtual NamedTypeDecl * clone() const override = 0;
     198        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     199        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    201200};
    202201
     
    204203        typedef NamedTypeDecl Parent;
    205204  public:
    206         enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS };
    207 
     205        enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS };
     206
     207        Kind kind;
     208        bool sized;
    208209        Type * init;
    209         bool sized;
    210210
    211211        /// Data extracted from a type decl
    212212        struct Data {
    213                 TypeDecl::Kind kind;
     213                Kind kind;
    214214                bool isComplete;
    215215
    216                 Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
    217                 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
     216                Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {}
     217                Data( const TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
    218218                Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
    219                 Data( const Data& d1, const Data& d2 )
    220                 : kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {}
    221 
    222                 bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; }
    223                 bool operator!=(const Data & other) const { return !(*this == other);}
     219                Data( const Data & d1, const Data & d2 )
     220                        : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
     221
     222                bool operator==( const Data & other ) const { return kind == other.kind && isComplete == other.isComplete; }
     223                bool operator!=( const Data & other ) const { return !(*this == other);}
    224224        };
    225225
    226         TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init = nullptr );
    227         TypeDecl( const TypeDecl &other );
     226        TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init = nullptr );
     227        TypeDecl( const TypeDecl & other );
    228228        virtual ~TypeDecl();
    229229
     
    237237        TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; }
    238238
    239         virtual std::string typeString() const override;
    240         virtual std::string genTypeString() const;
    241 
    242         virtual TypeDecl *clone() const override { return new TypeDecl( *this ); }
    243         virtual void accept( Visitor & v ) override { v.visit( this ); }
    244         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    245         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    246         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    247 
    248         Kind kind;
     239        virtual const char * typeString() const override;
     240        virtual const char * genTypeString() const;
     241
     242        virtual TypeDecl * clone() const override { return new TypeDecl( *this ); }
     243        virtual void accept( Visitor & v ) override { v.visit( this ); }
     244        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     245        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     246        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    249247};
    250248
     
    252250        typedef NamedTypeDecl Parent;
    253251  public:
    254         TypedefDecl( const std::string &name, CodeLocation location, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall )
     252        TypedefDecl( const std::string & name, CodeLocation location, Type::StorageClasses scs, Type * type, LinkageSpec::Spec spec = LinkageSpec::Cforall )
    255253                : Parent( name, scs, type ) { set_linkage( spec ); this->location = location; }
    256254
    257         TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    258 
    259         virtual std::string typeString() const override;
    260 
    261         virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); }
    262         virtual void accept( Visitor & v ) override { v.visit( this ); }
    263         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    264         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     255        TypedefDecl( const TypedefDecl & other ) : Parent( other ) {}
     256
     257        virtual const char * typeString() const override;
     258
     259        virtual TypedefDecl * clone() const override { return new TypedefDecl( *this ); }
     260        virtual void accept( Visitor & v ) override { v.visit( this ); }
     261        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     262        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    265263  private:
    266264};
     
    269267        typedef Declaration Parent;
    270268  public:
     269        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     270        static const char * aggrString( Aggregate aggr );
     271
    271272        std::list<Declaration*> members;
    272273        std::list<TypeDecl*> parameters;
     
    275276        AggregateDecl * parent = nullptr;
    276277
    277         AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
    278         AggregateDecl( const AggregateDecl &other );
     278        AggregateDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
     279        AggregateDecl( const AggregateDecl & other );
    279280        virtual ~AggregateDecl();
    280281
     
    288289        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    289290
    290         virtual void print( std::ostream &os, Indenter indent = {} ) const override final;
    291         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     291        virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
     292        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    292293  protected:
    293         virtual std::string typeString() const = 0;
     294        virtual const char * typeString() const = 0;
    294295};
    295296
     
    297298        typedef AggregateDecl Parent;
    298299  public:
    299         StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {}
    300         StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {}
    301 
    302         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    303         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    304         bool is_thread() { return kind == DeclarationNode::Thread; }
    305 
    306         virtual StructDecl *clone() const override { return new StructDecl( *this ); }
    307         virtual void accept( Visitor & v ) override { v.visit( this ); }
    308         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    309         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    310         DeclarationNode::Aggregate kind;
    311   private:
    312         virtual std::string typeString() const override;
     300        StructDecl( const std::string & name, Aggregate kind = Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {}
     301        StructDecl( const StructDecl & other ) : Parent( other ), kind( other.kind ) {}
     302
     303        bool is_coroutine() { return kind == Coroutine; }
     304        bool is_generator() { return kind == Generator; }
     305        bool is_monitor  () { return kind == Monitor  ; }
     306        bool is_thread   () { return kind == Thread   ; }
     307
     308        virtual StructDecl * clone() const override { return new StructDecl( *this ); }
     309        virtual void accept( Visitor & v ) override { v.visit( this ); }
     310        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     311        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     312        Aggregate kind;
     313  private:
     314        virtual const char * typeString() const override;
    313315};
    314316
     
    316318        typedef AggregateDecl Parent;
    317319  public:
    318         UnionDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
    319         UnionDecl( const UnionDecl &other ) : Parent( other ) {}
    320 
    321         virtual UnionDecl *clone() const override { return new UnionDecl( *this ); }
    322         virtual void accept( Visitor & v ) override { v.visit( this ); }
    323         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    324         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    325   private:
    326         virtual std::string typeString() const override;
     320        UnionDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
     321        UnionDecl( const UnionDecl & other ) : Parent( other ) {}
     322
     323        virtual UnionDecl * clone() const override { return new UnionDecl( *this ); }
     324        virtual void accept( Visitor & v ) override { v.visit( this ); }
     325        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     326        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     327  private:
     328        virtual const char * typeString() const override;
    327329};
    328330
     
    330332        typedef AggregateDecl Parent;
    331333  public:
    332         EnumDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
    333         EnumDecl( const EnumDecl &other ) : Parent( other ) {}
     334        EnumDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
     335        EnumDecl( const EnumDecl & other ) : Parent( other ) {}
    334336
    335337        bool valueOf( Declaration * enumerator, long long int & value );
    336338
    337         virtual EnumDecl *clone() const override { return new EnumDecl( *this ); }
    338         virtual void accept( Visitor & v ) override { v.visit( this ); }
    339         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    340         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     339        virtual EnumDecl * clone() const override { return new EnumDecl( *this ); }
     340        virtual void accept( Visitor & v ) override { v.visit( this ); }
     341        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     342        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    341343  private:
    342344        std::unordered_map< std::string, long long int > enumValues;
    343         virtual std::string typeString() const override;
     345        virtual const char * typeString() const override;
    344346};
    345347
     
    347349        typedef AggregateDecl Parent;
    348350  public:
    349         TraitDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) {
     351        TraitDecl( const std::string & name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) {
    350352                assertf( attributes.empty(), "attribute unsupported for traits" );
    351353        }
    352         TraitDecl( const TraitDecl &other ) : Parent( other ) {}
    353 
    354         virtual TraitDecl *clone() const override { return new TraitDecl( *this ); }
    355         virtual void accept( Visitor & v ) override { v.visit( this ); }
    356         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    357         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    358   private:
    359         virtual std::string typeString() const override;
     354        TraitDecl( const TraitDecl & other ) : Parent( other ) {}
     355
     356        virtual TraitDecl * clone() const override { return new TraitDecl( *this ); }
     357        virtual void accept( Visitor & v ) override { v.visit( this ); }
     358        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     359        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     360  private:
     361        virtual const char * typeString() const override;
    360362};
    361363
     
    379381class AsmDecl : public Declaration {
    380382  public:
    381         AsmStmt *stmt;
    382 
    383         AsmDecl( AsmStmt *stmt );
    384         AsmDecl( const AsmDecl &other );
     383        AsmStmt * stmt;
     384
     385        AsmDecl( AsmStmt * stmt );
     386        AsmDecl( const AsmDecl & other );
    385387        virtual ~AsmDecl();
    386388
    387         AsmStmt *get_stmt() { return stmt; }
    388         void set_stmt( AsmStmt *newValue ) { stmt = newValue; }
    389 
    390         virtual AsmDecl *clone() const override { return new AsmDecl( *this ); }
    391         virtual void accept( Visitor & v ) override { v.visit( this ); }
    392         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    393         virtual AsmDecl *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    394         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    395         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     389        AsmStmt * get_stmt() { return stmt; }
     390        void set_stmt( AsmStmt * newValue ) { stmt = newValue; }
     391
     392        virtual AsmDecl * clone() const override { return new AsmDecl( *this ); }
     393        virtual void accept( Visitor & v ) override { v.visit( this ); }
     394        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     395        virtual AsmDecl * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     396        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     397        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    396398};
    397399
     
    408410        virtual void accept( Visitor & v ) override { v.visit( this ); }
    409411        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    410         virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    411         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    412         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     412        virtual StaticAssertDecl * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     413        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     414        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    413415};
    414416
  • src/SynTree/DeclarationWithType.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:34:35 2017
    13 // Update Count     : 25
     12// Last Modified On : Fri Dec 13 23:45:16 2019
     13// Update Count     : 26
    1414//
    1515
     
    2020#include "Common/utility.h"      // for cloneAll, deleteAll, maybeClone
    2121#include "Declaration.h"         // for DeclarationWithType, Declaration
    22 #include "Parser/LinkageSpec.h"  // for Spec
    23 #include "SynTree/Expression.h"  // for ConstantExpr
     22#include "LinkageSpec.h"         // for Spec
     23#include "Expression.h"          // for ConstantExpr
    2424#include "Type.h"                // for Type, Type::FuncSpecifiers, Type::St...
    2525
  • src/SynTree/Expression.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 15 13:43:00 2019
    13 // Update Count     : 64
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 07:55:15 2019
     13// Update Count     : 70
    1414//
    1515
     
    2222
    2323#include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
    24 #include "Declaration.h"             // for ObjectDecl, DeclarationWithType
    2524#include "Expression.h"              // for Expression, ImplicitCopyCtorExpr
    2625#include "InitTweak/InitTweak.h"     // for getCallArg, getPointerBase
     
    294293}
    295294
    296 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) {
     295KeywordCastExpr::KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ) : Expression(), arg(arg), target( target ) {
    297296}
    298297
     
    304303}
    305304
    306 const std::string & KeywordCastExpr::targetString() const {
    307         static const std::string targetStrs[] = {
    308                 "coroutine", "thread", "monitor"
    309         };
    310         static_assert(
    311                 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
    312                 "Each KeywordCastExpr::Target should have a corresponding string representation"
    313         );
    314         return targetStrs[(unsigned long)target];
     305const char * KeywordCastExpr::targetString() const {
     306        return AggregateDecl::aggrString( target );
    315307}
    316308
  • src/SynTree/Expression.h

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 15 13:46:00 2019
    13 // Update Count     : 54
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:50:19 2019
     13// Update Count     : 60
    1414//
    1515
     
    2828#include "Label.h"                // for Label
    2929#include "Mutator.h"              // for Mutator
     30#include "Declaration.h"          // for Aggregate
    3031#include "SynTree.h"              // for UniqueId
    3132#include "Visitor.h"              // for Visitor
     
    229230public:
    230231        Expression * arg;
    231         enum Target {
    232                 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS
    233         } target;
    234 
    235         KeywordCastExpr( Expression * arg, Target target );
     232        struct Concrete {
     233                std::string field;
     234                std::string getter;
     235        };
     236        AggregateDecl::Aggregate target;
     237        Concrete concrete_target;
     238
     239        KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target );
    236240        KeywordCastExpr( const KeywordCastExpr & other );
    237241        virtual ~KeywordCastExpr();
    238242
    239         const std::string & targetString() const;
     243        const char * targetString() const;
    240244
    241245        virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
  • src/SynTree/FunctionDecl.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:33:41 2017
    13 // Update Count     : 74
     12// Last Modified On : Mon Dec 16 15:11:20 2019
     13// Update Count     : 77
    1414//
    1515
     
    2323#include "Common/utility.h"      // for maybeClone, printAll
    2424#include "Declaration.h"         // for FunctionDecl, FunctionDecl::Parent
    25 #include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
     25#include "Expression.h"
     26#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
    2627#include "Statement.h"           // for CompoundStmt
    2728#include "Type.h"                // for Type, FunctionType, Type::FuncSpecif...
     
    7273        } // if
    7374        if ( linkage != LinkageSpec::Cforall ) {
    74                 os << LinkageSpec::linkageName( linkage ) << " ";
     75                os << LinkageSpec::name( linkage ) << " ";
    7576        } // if
    7677
  • src/SynTree/LinkageSpec.h

    r71d6bd8 r7030dab  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:24:28 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 10 16:02:34 2019
    13 // Update Count     : 18
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Mar  2 16:13:00 2020
     13// Update Count     : 21
    1414//
    1515
     
    1818#include <string>
    1919
    20 #include "Common/CodeLocation.h"
     20struct CodeLocation;
    2121
    2222namespace LinkageSpec {
    23         // All linkage specs are some combination of these flags:
    24         enum { Mangle = 1 << 0, Generate = 1 << 1, Overrideable = 1 << 2, Builtin = 1 << 3, GccBuiltin = 1 << 4, NoOfSpecs = 1 << 5, };
     23        // Bitflags for linkage specifiers
     24        enum {
     25                Mangle = 1 << 0,
     26                Generate = 1 << 1,
     27                Overrideable = 1 << 2,
     28                Builtin = 1 << 3,
     29                GccBuiltin = 1 << 4,
     30        };
    2531
     32        // Bitflag type for storage classes
    2633        union Spec {
    2734                unsigned int val;
     
    4249
    4350
    44         Spec linkageUpdate( CodeLocation location, Spec old_spec, const std::string * cmd );
    45         /* If cmd = "C" returns a Spec that is old_spec with is_mangled = false
    46          * If cmd = "Cforall" returns old_spec Spec with is_mangled = true
    47          */
     51        Spec update( CodeLocation location, Spec spec, const std::string * cmd );
     52        // If cmd = "C" returns a Spec that is old_spec with is_mangled = false
     53        // If cmd = "Cforall" returns old_spec Spec with is_mangled = true
    4854
    49         std::string linkageName( Spec );
     55        std::string name( Spec );
    5056
    5157        // To Update: LinkageSpec::isXyz( cur_spec ) -> cur_spec.is_xyz
  • src/SynTree/Mutator.h

    r71d6bd8 r7030dab  
    5151        virtual Statement * mutate( CatchStmt * catchStmt ) = 0;
    5252        virtual Statement * mutate( FinallyStmt * catchStmt ) = 0;
     53        virtual Statement * mutate( SuspendStmt * suspendStmt ) = 0;
    5354        virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0;
    5455        virtual Declaration * mutate( WithStmt * withStmt ) = 0;
  • src/SynTree/NamedTypeDecl.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  9 13:28:00 2017
    13 // Update Count     : 14
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 16 15:11:40 2019
     13// Update Count     : 17
    1414//
    1515
     
    2020#include "Common/utility.h"      // for printAll, cloneAll, deleteAll, maybe...
    2121#include "Declaration.h"         // for NamedTypeDecl, DeclarationWithType
    22 #include "Parser/LinkageSpec.h"  // for Spec, Cforall, linkageName
     22#include "LinkageSpec.h"         // for Spec, Cforall, linkageName
    2323#include "Type.h"                // for Type, Type::StorageClasses
    2424
     
    4444
    4545        if ( linkage != LinkageSpec::Cforall ) {
    46                 os << LinkageSpec::linkageName( linkage ) << " ";
     46                os << LinkageSpec::name( linkage ) << " ";
    4747        } // if
    4848        get_storageClasses().print( os );
     
    7878}
    7979
    80 std::string TypedefDecl::typeString() const { return "typedef"; }
     80const char * TypedefDecl::typeString() const { return "typedef"; }
    8181
    8282// Local Variables: //
  • src/SynTree/ObjectDecl.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:34:27 2017
    13 // Update Count     : 59
     12// Last Modified On : Mon Dec 16 15:12:03 2019
     13// Update Count     : 61
    1414//
    1515
     
    2323#include "Expression.h"          // for Expression
    2424#include "Initializer.h"         // for Initializer
    25 #include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
     25#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
    2626#include "Type.h"                // for Type, Type::StorageClasses, Type::Fu...
    2727
     
    4848
    4949        if ( linkage != LinkageSpec::Cforall ) {
    50                 os << LinkageSpec::linkageName( linkage ) << " ";
     50                os << LinkageSpec::name( linkage ) << " ";
    5151        } // if
    5252
  • src/SynTree/Statement.cc

    r71d6bd8 r7030dab  
    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 : Sun Sep  3 20:46:44 2017
    13 // Update Count     : 68
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jan 20 16:03:00 2020
     13// Update Count     : 71
    1414//
    1515
     
    4646Statement::~Statement() {}
    4747
    48 ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}
    49 
    50 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     48ExprStmt::ExprStmt( Expression * expr ) : Statement(), expr( expr ) {}
     49
     50ExprStmt::ExprStmt( const ExprStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    5151
    5252ExprStmt::~ExprStmt() {
     
    5454}
    5555
    56 void ExprStmt::print( std::ostream &os, Indenter indent ) const {
     56void ExprStmt::print( std::ostream & os, Indenter indent ) const {
    5757        os << "Expression Statement:" << endl << indent+1;
    5858        expr->print( os, indent+1 );
     
    6060
    6161
    62 AsmStmt::AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
     62AsmStmt::AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    6363
    6464AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
     
    7575}
    7676
    77 void AsmStmt::print( std::ostream &os, Indenter indent ) const {
     77void AsmStmt::print( std::ostream & os, Indenter indent ) const {
    7878        os << "Assembler Statement:" << endl;
    7979        os << indent+1 << "instruction: " << endl << indent;
     
    9696DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {}
    9797
    98 void DirectiveStmt::print( std::ostream &os, Indenter ) const {
     98void DirectiveStmt::print( std::ostream & os, Indenter ) const {
    9999        os << "GCC Directive:" << directive << endl;
    100100}
    101101
    102102
    103 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
     103const char * BranchStmt::brType[] = {
     104        "Goto", "Break", "Continue", "Fall Through", "Fall Through Default",
     105};
    104106
    105107BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
     
    111113}
    112114
    113 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) :
     115BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) :
    114116        Statement(), computedTarget( computedTarget ), type( type ) {
    115117        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
     
    118120}
    119121
    120 void BranchStmt::print( std::ostream &os, Indenter indent ) const {
     122void BranchStmt::print( std::ostream & os, Indenter indent ) const {
     123        assert(type < 5);
    121124        os << "Branch (" << brType[type] << ")" << endl ;
    122125        if ( target != "" ) os << indent+1 << "with target: " << target << endl;
     
    125128}
    126129
    127 ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {}
     130ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {}
    128131
    129132ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    133136}
    134137
    135 void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
     138void ReturnStmt::print( std::ostream & os, Indenter indent ) const {
    136139        os << "Return Statement, returning: ";
    137140        if ( expr != nullptr ) {
     
    142145}
    143146
    144 IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
     147IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ):
    145148        Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    146149
     
    157160}
    158161
    159 void IfStmt::print( std::ostream &os, Indenter indent ) const {
     162void IfStmt::print( std::ostream & os, Indenter indent ) const {
    160163        os << "If on condition: " << endl;
    161164        os << indent+1;
     
    176179        thenPart->print( os, indent+1 );
    177180
    178         if ( elsePart != 0 ) {
     181        if ( elsePart != nullptr ) {
    179182                os << indent << "... else: " << endl;
    180183                os << indent+1;
     
    183186}
    184187
    185 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ):
     188SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ):
    186189        Statement(), condition( condition ), statements( statements ) {
    187190}
     
    198201}
    199202
    200 void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
     203void SwitchStmt::print( std::ostream & os, Indenter indent ) const {
    201204        os << "Switch on condition: ";
    202205        condition->print( os );
     
    208211}
    209212
    210 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :
     213CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) :
    211214        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    212         if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " );
     215        if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " );
    213216}
    214217
     
    229232}
    230233
    231 void CaseStmt::print( std::ostream &os, Indenter indent ) const {
     234void CaseStmt::print( std::ostream & os, Indenter indent ) const {
    232235        if ( isDefault() ) os << indent << "Default ";
    233236        else {
     
    243246}
    244247
    245 WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):
     248WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ):
    246249        Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) {
    247250}
     
    256259}
    257260
    258 void WhileStmt::print( std::ostream &os, Indenter indent ) const {
     261void WhileStmt::print( std::ostream & os, Indenter indent ) const {
    259262        os << "While on condition: " << endl ;
    260263        condition->print( os, indent+1 );
     
    262265        os << indent << "... with body: " << endl;
    263266
    264         if ( body != 0 ) body->print( os, indent+1 );
    265 }
    266 
    267 ForStmt::ForStmt( std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
     267        if ( body != nullptr ) body->print( os, indent+1 );
     268}
     269
     270ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ):
    268271        Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    269272}
     
    282285}
    283286
    284 void ForStmt::print( std::ostream &os, Indenter indent ) const {
     287void ForStmt::print( std::ostream & os, Indenter indent ) const {
    285288        Statement::print( os, indent ); // print labels
    286289
     
    305308        }
    306309
    307         if ( body != 0 ) {
     310        if ( body != nullptr ) {
    308311                os << "\n" << indent << "... with body: \n" << indent+1;
    309312                body->print( os, indent+1 );
     
    317320}
    318321
    319 ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
     322ThrowStmt::ThrowStmt( const ThrowStmt & other ) :
    320323        Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
    321324}
     
    326329}
    327330
    328 void ThrowStmt::print( std::ostream &os, Indenter indent) const {
     331void ThrowStmt::print( std::ostream & os, Indenter indent) const {
    329332        if ( target ) os << "Non-Local ";
    330333        os << "Throw Statement, raising: ";
     
    336339}
    337340
    338 TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
     341TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) :
    339342        Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    340343}
    341344
    342 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
     345TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
    343346        cloneAll( other.handlers, handlers );
    344347}
     
    350353}
    351354
    352 void TryStmt::print( std::ostream &os, Indenter indent ) const {
     355void TryStmt::print( std::ostream & os, Indenter indent ) const {
    353356        os << "Try Statement" << endl;
    354357        os << indent << "... with block:" << endl << indent+1;
     
    363366
    364367        // finally block
    365         if ( finallyBlock != 0 ) {
     368        if ( finallyBlock != nullptr ) {
    366369                os << indent << "... and finally:" << endl << indent+1;
    367370                finallyBlock->print( os, indent+1 );
     
    369372}
    370373
    371 CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
     374CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) :
    372375        Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    373376                assertf( decl, "Catch clause must have a declaration." );
     
    383386}
    384387
    385 void CatchStmt::print( std::ostream &os, Indenter indent ) const {
     388void CatchStmt::print( std::ostream & os, Indenter indent ) const {
    386389        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
    387390
     
    401404
    402405
    403 FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) {
     406FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) {
    404407}
    405408
     
    411414}
    412415
    413 void FinallyStmt::print( std::ostream &os, Indenter indent ) const {
     416void FinallyStmt::print( std::ostream & os, Indenter indent ) const {
    414417        os << "Finally Statement" << endl;
    415418        os << indent << "... with block:" << endl << indent+1;
    416419        block->print( os, indent+1 );
     420}
     421
     422SuspendStmt::SuspendStmt( const SuspendStmt & other )
     423        : Statement( other )
     424        , then( maybeClone(other.then) )
     425{}
     426
     427SuspendStmt::~SuspendStmt() {
     428        delete then;
     429}
     430
     431void SuspendStmt::print( std::ostream & os, Indenter indent ) const {
     432        os << "Suspend Statement";
     433        switch (type) {
     434                case None     : os << " with implicit target"; break;
     435                case Generator: os << " for generator"       ; break;
     436                case Coroutine: os << " for coroutine"       ; break;
     437        }
     438        os << endl;
     439        indent += 1;
     440
     441        if(then) {
     442                os << indent << " with post statement :" << endl;
     443                then->print( os, indent + 1);
     444        }
    417445}
    418446
     
    458486}
    459487
    460 void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
     488void WaitForStmt::print( std::ostream & os, Indenter indent ) const {
    461489        os << "Waitfor Statement" << endl;
    462490        indent += 1;
     
    514542}
    515543
    516 void NullStmt::print( std::ostream &os, Indenter indent ) const {
     544void NullStmt::print( std::ostream & os, Indenter indent ) const {
    517545        os << "Null Statement" << endl;
    518546        Statement::print( os, indent );
     
    530558}
    531559
    532 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
     560void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const {
    533561        os << "Implicit Ctor Dtor Statement" << endl;
    534562        os << indent << "... with Ctor/Dtor: ";
  • src/SynTree/Statement.h

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 12 09:01:53 2019
    13 // Update Count     : 83
     12// Last Modified On : Fri Jan 10 14:13:24 2020
     13// Update Count     : 85
    1414//
    1515
     
    257257        Statement * body;
    258258
    259         ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0 );
     259        ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr );
    260260        ForStmt( const ForStmt & other );
    261261        virtual ~ForStmt();
     
    357357        FinallyStmt * finallyBlock;
    358358
    359         TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0 );
     359        TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = nullptr );
    360360        TryStmt( const TryStmt & other );
    361361        virtual ~TryStmt();
     
    422422};
    423423
     424class SuspendStmt : public Statement {
     425  public:
     426        CompoundStmt * then = nullptr;
     427        enum Type { None, Coroutine, Generator } type = None;
     428
     429        SuspendStmt() = default;
     430        SuspendStmt( const SuspendStmt & );
     431        virtual ~SuspendStmt();
     432
     433        virtual SuspendStmt * clone() const override { return new SuspendStmt( *this ); }
     434        virtual void accept( Visitor & v ) override { v.visit( this ); }
     435        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     436        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     437        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     438};
     439
    424440class WaitForStmt : public Statement {
    425441  public:
  • src/SynTree/SynTree.h

    r71d6bd8 r7030dab  
    5454class CatchStmt;
    5555class FinallyStmt;
     56class SuspendStmt;
    5657class WaitForStmt;
    5758class WithStmt;
  • src/SynTree/TupleType.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  1 17:10:58 2017
    13 // Update Count     : 3
     12// Last Modified On : Fri Dec 13 23:44:38 2019
     13// Update Count     : 4
    1414//
    1515
     
    2020#include "Declaration.h"         // for Declaration, ObjectDecl
    2121#include "Initializer.h"         // for ListInit
    22 #include "Parser/LinkageSpec.h"  // for Cforall
     22#include "LinkageSpec.h"         // for Cforall
    2323#include "Type.h"                // for TupleType, Type, Type::Qualifiers
    2424
  • src/SynTree/Type.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 21:05:07 2019
    13 // Update Count     : 45
     12// Last Modified On : Sun Dec 15 16:52:37 2019
     13// Update Count     : 49
    1414//
    1515#include "Type.h"
     
    2424using namespace std;
    2525
     26// GENERATED START, DO NOT EDIT
     27// GENERATED BY BasicTypes-gen.cc
    2628const char * BasicType::typeNames[] = {
    2729        "_Bool",
     
    4547        "float",
    4648        "float _Complex",
    47         //"float _Imaginary",
    4849        "_Float32x",
    4950        "_Float32x _Complex",
     
    5253        "double",
    5354        "double _Complex",
    54         //"double _Imaginary",
    5555        "_Float64x",
    5656        "_Float64x _Complex",
     
    6161        "long double",
    6262        "long double _Complex",
    63         //"long double _Imaginary",
    6463        "_Float128x",
    6564        "_Float128x _Complex",
    6665};
    67 static_assert(
    68         sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
    69         "Each basic type name should have a corresponding kind enum value"
    70 );
     66// GENERATED END
    7167
    7268Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
  • src/SynTree/TypeDecl.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  9 14:35:00 2017
    13 // Update Count     : 6
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 15:26:14 2019
     13// Update Count     : 21
    1414//
    1515
     
    2121#include "Type.h"            // for Type, Type::StorageClasses
    2222
    23 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), init( init ), sized( kind == Ttype || sized ), kind( kind ) {
     23TypeDecl::TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), kind( kind ), sized( kind == Ttype || sized ), init( init ) {
    2424}
    2525
    26 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) {
     26TypeDecl::TypeDecl( const TypeDecl & other ) : Parent( other ), kind( other.kind ), sized( other.sized ), init( maybeClone( other.init ) ) {
    2727}
    2828
    2929TypeDecl::~TypeDecl() {
    30   delete init;
     30        delete init;
    3131}
    3232
    33 std::string TypeDecl::typeString() const {
    34         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
    35         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "typeString: kindNames is out of sync." );
    36         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    37         return (isComplete() ? "sized " : "") + kindNames[ kind ];
     33const char * TypeDecl::typeString() const {
     34        static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" };
     35        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
     36        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
     37        return isComplete() ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    3838}
    3939
    40 std::string TypeDecl::genTypeString() const {
    41         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
    42         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    43         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     40const char * TypeDecl::genTypeString() const {
     41        static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" };
     42        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." );
     43        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    4444        return kindNames[ kind ];
    4545}
    4646
    4747void TypeDecl::print( std::ostream &os, Indenter indent ) const {
    48   NamedTypeDecl::print( os, indent );
    49   if ( init ) {
    50     os << std::endl << indent << "with type initializer: ";
    51     init->print( os, indent + 1 );
    52   }
     48        NamedTypeDecl::print( os, indent );
     49        if ( init ) {
     50                os << std::endl << indent << "with type initializer: ";
     51                init->print( os, indent + 1 );
     52        } // if
    5353}
    5454
    55 
    5655std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) {
    57   return os << data.kind << ", " << data.isComplete;
     56        return os << data.kind << ", " << data.isComplete;
    5857}
    5958
  • src/SynTree/Visitor.h

    r71d6bd8 r7030dab  
    7878        virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); }
    7979        virtual void visit( const FinallyStmt * finallyStmt ) = 0;
     80        virtual void visit( SuspendStmt * node ) { visit( const_cast<const SuspendStmt *>(node) ); }
     81        virtual void visit( const SuspendStmt * suspendStmt ) = 0;
    8082        virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); }
    8183        virtual void visit( const WaitForStmt * waitforStmt ) = 0;
  • src/SynTree/module.mk

    r71d6bd8 r7030dab  
    1111## Created On       : Mon Jun  1 17:49:17 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Mon Jun  1 17:54:09 2015
    14 ## Update Count     : 1
     13## Last Modified On : Sat Dec 14 07:26:43 2019
     14## Update Count     : 2
    1515###############################################################################
    1616
    1717SRC_SYNTREE = \
    18       SynTree/Type.cc \
    19       SynTree/VoidType.cc \
     18      SynTree/AddressExpr.cc \
     19      SynTree/AggregateDecl.cc \
     20      SynTree/ApplicationExpr.cc \
     21      SynTree/ArrayType.cc \
     22      SynTree/AttrType.cc \
     23      SynTree/Attribute.cc \
    2024      SynTree/BasicType.cc \
    21       SynTree/PointerType.cc \
    22       SynTree/ArrayType.cc \
    23       SynTree/ReferenceType.cc \
    24       SynTree/FunctionType.cc \
    25       SynTree/ReferenceToType.cc \
    26       SynTree/TupleType.cc \
    27       SynTree/TypeofType.cc \
    28       SynTree/AttrType.cc \
    29       SynTree/VarArgsType.cc \
    30       SynTree/ZeroOneType.cc \
     25      SynTree/CommaExpr.cc \
     26      SynTree/CompoundStmt.cc \
    3127      SynTree/Constant.cc \
    32       SynTree/Expression.cc \
    33       SynTree/TupleExpr.cc \
    34       SynTree/CommaExpr.cc \
    35       SynTree/TypeExpr.cc \
    36       SynTree/ApplicationExpr.cc \
    37       SynTree/AddressExpr.cc \
    38       SynTree/Statement.cc \
    39       SynTree/CompoundStmt.cc \
     28      SynTree/DeclReplacer.cc \
    4029      SynTree/DeclStmt.cc \
    4130      SynTree/Declaration.cc \
    4231      SynTree/DeclarationWithType.cc \
     32      SynTree/Expression.cc \
     33      SynTree/FunctionDecl.cc \
     34      SynTree/FunctionType.cc \
     35      SynTree/Initializer.cc \
     36      SynTree/LinkageSpec.cc \
     37      SynTree/NamedTypeDecl.cc \
    4338      SynTree/ObjectDecl.cc \
    44       SynTree/FunctionDecl.cc \
    45       SynTree/AggregateDecl.cc \
    46       SynTree/NamedTypeDecl.cc \
     39      SynTree/PointerType.cc \
     40      SynTree/ReferenceToType.cc \
     41      SynTree/ReferenceType.cc \
     42      SynTree/Statement.cc \
     43      SynTree/TupleExpr.cc \
     44      SynTree/TupleType.cc \
     45      SynTree/Type.cc \
    4746      SynTree/TypeDecl.cc \
    48       SynTree/Initializer.cc \
     47      SynTree/TypeExpr.cc \
    4948      SynTree/TypeSubstitution.cc \
    50       SynTree/Attribute.cc \
    51       SynTree/DeclReplacer.cc
     49      SynTree/TypeofType.cc \
     50      SynTree/VarArgsType.cc \
     51      SynTree/VoidType.cc \
     52      SynTree/ZeroOneType.cc
    5253
    5354SRC += $(SRC_SYNTREE)
  • src/Tuples/TupleAssignment.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:43:03 2017
    13 // Update Count     : 8
     12// Last Modified On : Fri Dec 13 23:45:33 2019
     13// Update Count     : 9
    1414//
    1515
     
    3434#include "InitTweak/GenInit.h"             // for genCtorInit
    3535#include "InitTweak/InitTweak.h"           // for getPointerBase, isAssignment
    36 #include "Parser/LinkageSpec.h"            // for Cforall
    3736#include "ResolvExpr/Alternative.h"        // for AltList, Alternative
    3837#include "ResolvExpr/AlternativeFinder.h"  // for AlternativeFinder, simpleC...
     
    4140#include "ResolvExpr/TypeEnvironment.h"    // for TypeEnvironment
    4241#include "ResolvExpr/typeops.h"            // for combos
     42#include "SynTree/LinkageSpec.h"           // for Cforall
    4343#include "SynTree/Declaration.h"           // for ObjectDecl
    4444#include "SynTree/Expression.h"            // for Expression, CastExpr, Name...
  • src/Tuples/TupleExpansion.cc

    r71d6bd8 r7030dab  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  4 15:38:00 2019
    13 // Update Count     : 23
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:45:51 2019
     13// Update Count     : 24
    1414//
    1515
     
    2727#include "Common/utility.h"       // for CodeLocation
    2828#include "InitTweak/InitTweak.h"  // for getFunction
    29 #include "Parser/LinkageSpec.h"   // for Spec, C, Intrinsic
     29#include "SynTree/LinkageSpec.h"  // for Spec, C, Intrinsic
    3030#include "SynTree/Constant.h"     // for Constant
    3131#include "SynTree/Declaration.h"  // for StructDecl, DeclarationWithType
     
    361361        const ast::TypeInstType * isTtype( const ast::Type * type ) {
    362362                if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    363                         if ( inst->base && inst->base->kind == ast::TypeVar::Ttype ) {
     363                        if ( inst->base && inst->base->kind == ast::TypeDecl::Ttype ) {
    364364                                return inst;
    365365                        }
  • src/cfa.make

    r71d6bd8 r7030dab  
    1 
    2 
    31CFACOMPILE = $(CFACC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(CFAFLAGS) $(AM_CFLAGS) $(CFLAGS)
    42LTCFACOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
    53        $(LIBTOOLFLAGS) --mode=compile $(CFACC) $(DEFS) \
    6         $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(CFAFLAGS) \
    7         $(AM_CFLAGS) $(CFLAGS)
     4        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(AM_CFLAGS) $(CFAFLAGS) $(CFLAGS)
    85
    96AM_V_CFA = $(am__v_CFA_@AM_V@)
     
    2219        $(am__mv) $$depbase.Tpo $$depbase.Plo
    2320
    24 AM_V_JAVAC = $(am__v_JAVAC_@AM_V@)
    25 am__v_JAVAC_ = $(am__v_JAVAC_@AM_DEFAULT_V@)
    26 am__v_JAVAC_0 = @echo "  JAVAC   " $@;
    27 am__v_JAVAC_1 =
    28 
    29 AM_V_GOC = $(am__v_GOC_@AM_V@)
    30 am__v_GOC_ = $(am__v_GOC_@AM_DEFAULT_V@)
    31 am__v_GOC_0 = @echo "  GOC     " $@;
    32 am__v_GOC_1 =
    33 
    3421UPPCC = u++
    3522UPPCOMPILE = $(UPPCC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_UPPFLAGS) $(UPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_CFLAGS) $(CFLAGS)
     
    3926am__v_UPP_0 = @echo "  UPP     " $@;
    4027am__v_UPP_1 =
     28
     29AM_V_GOC = $(am__v_GOC_@AM_V@)
     30am__v_GOC_ = $(am__v_GOC_@AM_DEFAULT_V@)
     31am__v_GOC_0 = @echo "  GOC     " $@;
     32am__v_GOC_1 =
     33
     34AM_V_PY = $(am__v_PY_@AM_V@)
     35am__v_PY_ = $(am__v_PY_@AM_DEFAULT_V@)
     36am__v_PY_0 = @echo "  PYTHON  " $@;
     37am__v_PY_1 =
     38
     39AM_V_RUST = $(am__v_RUST_@AM_V@)
     40am__v_RUST_ = $(am__v_RUST_@AM_DEFAULT_V@)
     41am__v_RUST_0 = @echo "  RUST    " $@;
     42am__v_RUST_1 =
     43
     44AM_V_NODEJS = $(am__v_NODEJS_@AM_V@)
     45am__v_NODEJS_ = $(am__v_NODEJS_@AM_DEFAULT_V@)
     46am__v_NODEJS_0 = @echo "  NODEJS  " $@;
     47am__v_NODEJS_1 =
     48
     49AM_V_JAVAC = $(am__v_JAVAC_@AM_V@)
     50am__v_JAVAC_ = $(am__v_JAVAC_@AM_DEFAULT_V@)
     51am__v_JAVAC_0 = @echo "  JAVAC   " $@;
     52am__v_JAVAC_1 =
  • src/main.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 23 06:50:08 2019
    13 // Update Count     : 607
     12// Last Modified On : Sat Feb  8 08:33:50 2020
     13// Update Count     : 633
    1414//
    1515
     
    2020#include <cstdio>                           // for fopen, FILE, fclose, stdin
    2121#include <cstdlib>                          // for exit, free, abort, EXIT_F...
    22 #include <csignal>                         // for signal, SIGABRT, SIGSEGV
     22#include <csignal>                          // for signal, SIGABRT, SIGSEGV
    2323#include <cstring>                          // for index
    2424#include <fstream>                          // for ofstream
     
    2828#include <list>                             // for list
    2929#include <string>                           // for char_traits, operator<<
     30
     31using namespace std;
    3032
    3133#include "AST/Convert.hpp"
     
    5456#include "InitTweak/GenInit.h"              // for genInit
    5557#include "MakeLibCfa.h"                     // for makeLibCfa
    56 #include "Parser/LinkageSpec.h"             // for Spec, Cforall, Intrinsic
    5758#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
    5859#include "Parser/TypedefTable.h"            // for TypedefTable
     
    6061#include "ResolvExpr/Resolver.h"            // for resolve
    6162#include "SymTab/Validate.h"                // for validate
     63#include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    6264#include "SynTree/Declaration.h"            // for Declaration
    6365#include "SynTree/Visitor.h"                // for acceptAll
     
    6567#include "Virtual/ExpandCasts.h"            // for expandCasts
    6668
    67 
    68 using namespace std;
    6969
    7070static void NewPass( const char * const name ) {
     
    9898static bool waiting_for_gdb = false;                                    // flag to set cfa-cpp to wait for gdb on start
    9999
    100 static std::string PreludeDirector = "";
     100static string PreludeDirector = "";
    101101
    102102static void parse_cmdline( int argc, char *argv[] );
     
    105105
    106106static void backtrace( int start ) {                                    // skip first N stack frames
    107         enum { Frames = 50 };
     107        enum { Frames = 50, };                                                          // maximum number of stack frames
    108108        void * array[Frames];
    109         int size = ::backtrace( array, Frames );
     109        size_t size = ::backtrace( array, Frames );
    110110        char ** messages = ::backtrace_symbols( array, size ); // does not demangle names
    111111
     
    114114
    115115        // skip last 2 stack frames after main
    116         for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
     116        for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
    117117                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    118                 for ( char *p = messages[i]; *p; ++p ) {        // find parantheses and +offset
     118
     119                for ( char * p = messages[i]; *p; p += 1 ) {    // find parantheses and +offset
    119120                        if ( *p == '(' ) {
    120121                                mangled_name = p;
     
    154155} // backtrace
    155156
    156 static void sigSegvBusHandler( int sig_num ) {
    157         cerr << "*CFA runtime error* program cfa-cpp terminated with "
    158                  <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
    159                  << "." << endl;
     157#define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused ))
     158
     159static void Signal( int sig, void (*handler)(SIGPARMS), int flags ) {
     160        struct sigaction act;
     161
     162        act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
     163        act.sa_flags = flags;
     164
     165        if ( sigaction( sig, &act, nullptr ) == -1 ) {
     166            cerr << "*CFA runtime error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl;
     167            _exit( EXIT_FAILURE );
     168        } // if
     169} // Signal
     170
     171static void sigSegvBusHandler( SIGPARMS ) {
     172        if ( sfp->si_addr == nullptr ) {
     173                cerr << "Null pointer (nullptr) dereference." << endl;
     174        } else {
     175                cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl
     176                         << "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript." << endl;
     177        } // if
    160178        backtrace( 2 );                                                                         // skip first 2 stack frames
    161         //_exit( EXIT_FAILURE );
    162179        abort();                                                                                        // cause core dump for debugging
    163180} // sigSegvBusHandler
    164181
    165 static void sigAbortHandler( __attribute__((unused)) int sig_num ) {
     182static void sigFpeHandler( SIGPARMS ) {
     183        const char * msg;
     184
     185        switch ( sfp->si_code ) {
     186          case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break;
     187          case FPE_FLTOVF: msg = "overflow"; break;
     188          case FPE_FLTUND: msg = "underflow"; break;
     189          case FPE_FLTRES: msg = "inexact result"; break;
     190          case FPE_FLTINV: msg = "invalid operation"; break;
     191          default: msg = "unknown";
     192        } // choose
     193        cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl
     194                 << "Possible cause is constant-expression evaluation invalid." << endl;
     195        backtrace( 2 );                                                                         // skip first 2 stack frames
     196        abort();                                                                                        // cause core dump for debugging
     197} // sigFpeHandler
     198
     199static void sigAbortHandler( SIGPARMS ) {
    166200        backtrace( 6 );                                                                         // skip first 6 stack frames
    167         signal( SIGABRT, SIG_DFL);                                                      // reset default signal handler
     201        Signal( SIGABRT, (void (*)(SIGPARMS))SIG_DFL, SA_SIGINFO );     // reset default signal handler
    168202        raise( SIGABRT );                                                                       // reraise SIGABRT
    169203} // sigAbortHandler
     
    174208        list< Declaration * > translationUnit;
    175209
    176         signal( SIGSEGV, sigSegvBusHandler );
    177         signal( SIGBUS, sigSegvBusHandler );
    178         signal( SIGABRT, sigAbortHandler );
    179 
    180         // std::cout << "main" << std::endl;
     210        Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO );
     211        Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO );
     212        Signal( SIGFPE, sigFpeHandler, SA_SIGINFO );
     213        Signal( SIGABRT, sigAbortHandler, SA_SIGINFO );
     214
     215        // cout << "main" << endl;
    181216        // for ( int i = 0; i < argc; i += 1 ) {
    182         //      std::cout << '\t' << argv[i] << std::endl;
     217        //      cout << '\t' << argv[i] << endl;
    183218        // } // for
    184219
     
    187222
    188223        if ( waiting_for_gdb ) {
    189                 std::cerr << "Waiting for gdb" << std::endl;
    190                 std::cerr << "run :" << std::endl;
    191                 std::cerr << "  gdb attach " << getpid() << std::endl;
     224                cerr << "Waiting for gdb" << endl;
     225                cerr << "run :" << endl;
     226                cerr << "  gdb attach " << getpid() << endl;
    192227                raise(SIGSTOP);
    193228        } // if
     
    395430                return EXIT_FAILURE;
    396431        } catch ( ... ) {
    397                 std::exception_ptr eptr = std::current_exception();
     432                exception_ptr eptr = current_exception();
    398433                try {
    399434                        if (eptr) {
    400                                 std::rethrow_exception(eptr);
     435                                rethrow_exception(eptr);
    401436                        } else {
    402                                 std::cerr << "Exception Uncaught and Unknown" << std::endl;
    403                         } // if
    404                 } catch(const std::exception& e) {
    405                         std::cerr << "Uncaught Exception \"" << e.what() << "\"\n";
     437                                cerr << "Exception Uncaught and Unknown" << endl;
     438                        } // if
     439                } catch(const exception& e) {
     440                        cerr << "Uncaught Exception \"" << e.what() << "\"\n";
    406441                } // try
    407442                return EXIT_FAILURE;
     
    414449
    415450
    416 static const char optstring[] = ":hlLmNnpP:S:tgwW:D:";
     451static const char optstring[] = ":c:ghlLmNnpP:S:twW:D:";
    417452
    418453enum { PreludeDir = 128 };
    419454static struct option long_opts[] = {
     455        { "colors", required_argument, nullptr, 'c' },
     456        { "gdb", no_argument, nullptr, 'g' },
    420457        { "help", no_argument, nullptr, 'h' },
    421458        { "libcfa", no_argument, nullptr, 'l' },
     
    429466        { "statistics", required_argument, nullptr, 'S' },
    430467        { "tree", no_argument, nullptr, 't' },
    431         { "gdb", no_argument, nullptr, 'g' },
    432468        { "", no_argument, nullptr, 0 },                                        // -w
    433469        { "", no_argument, nullptr, 0 },                                        // -W
     
    437473
    438474static const char * description[] = {
    439         "print help message",                                                           // -h
    440         "generate libcfa.c",                                                            // -l
    441         "generate line marks",                                                          // -L
    442         "do not replace main",                                                          // -m
    443         "do not generate line marks",                                           // -N
    444         "do not read prelude",                                                          // -n
     475        "diagnostic color: never, always, or auto.",          // -c
     476        "wait for gdb to attach",                             // -g
     477        "print help message",                                 // -h
     478        "generate libcfa.c",                                  // -l
     479        "generate line marks",                                // -L
     480        "do not replace main",                                // -m
     481        "do not generate line marks",                         // -N
     482        "do not read prelude",                                // -n
    445483        "generate prototypes for prelude functions",            // -p
    446         "print",                                                                                        // -P
     484        "print",                                              // -P
    447485        "<directory> prelude directory for debug/nodebug",      // no flag
    448486        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    449         "building cfa standard lib",                                                                    // -t
    450         "wait for gdb to attach",                                                                       // -g
    451         "",                                                                                                     // -w
    452         "",                                                                                                     // -W
    453         "",                                                                                                     // -D
     487        "building cfa standard lib",                          // -t
     488        "",                                                   // -w
     489        "",                                                   // -W
     490        "",                                                   // -D
    454491}; // description
    455492
     
    519556        while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) {
    520557                switch ( c ) {
     558                  case 'c':                                                                             // diagnostic colors
     559                        if ( strcmp( optarg, "always" ) == 0 ) {
     560                                ErrorHelpers::colors = ErrorHelpers::Colors::Always;
     561                        } else if ( strcmp( optarg, "never" ) == 0 ) {
     562                                ErrorHelpers::colors = ErrorHelpers::Colors::Never;
     563                        } else if ( strcmp( optarg, "auto" ) == 0 ) {
     564                                ErrorHelpers::colors = ErrorHelpers::Colors::Auto;
     565                        } // if
     566                        break;
    521567                  case 'h':                                                                             // help message
    522568                        usage( argv );                                                          // no return
Note: See TracChangeset for help on using the changeset viewer.