Changeset 312029a for src/SynTree


Ignore:
Timestamp:
Dec 11, 2019, 8:52:38 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
737c98a
Parents:
98d6965d
Message:

move enum Aggregate from DeclarationNode to AggregateDecl, add control-keyword field-dereference to replace control-keyword cast

Location:
src/SynTree
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AggregateDecl.cc

    r98d6965d r312029a  
    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 : Wed Dec 11 16:31:55 2019
     13// Update Count     : 29
    1414//
    1515
     
    2121#include "Common/utility.h"      // for printAll, cloneAll, deleteAll
    2222#include "Declaration.h"         // for AggregateDecl, TypeDecl, Declaration
     23#include "Initializer.h"
    2324#include "Parser/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 ) {
     
    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/Declaration.cc

    r98d6965d r312029a  
    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

    r98d6965d r312029a  
    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 : Wed Dec 11 16:48:20 2019
     13// Update Count     : 149
    1414//
    1515
     
    2525#include "Mutator.h"             // for Mutator
    2626#include "Parser/LinkageSpec.h"  // for Spec, Cforall
    27 #include "Parser/ParseNode.h"    // for DeclarationNode, DeclarationNode::Ag...
    2827#include "SynTree.h"             // for UniqueId
    2928#include "SynTree/Type.h"        // for Type, Type::StorageClasses, Type::Fu...
     
    194193        std::list< DeclarationWithType* >& get_assertions() { return assertions; }
    195194
    196         virtual std::string typeString() const = 0;
     195        virtual const char * typeString() const = 0;
    197196
    198197        virtual NamedTypeDecl *clone() const override = 0;
     
    237236        TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; }
    238237
    239         virtual std::string typeString() const override;
    240         virtual std::string genTypeString() const;
     238        virtual const char * typeString() const override;
     239        virtual const char * genTypeString() const;
    241240
    242241        virtual TypeDecl *clone() const override { return new TypeDecl( *this ); }
     
    257256        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    258257
    259         virtual std::string typeString() const override;
     258        virtual const char * typeString() const override;
    260259
    261260        virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); }
     
    269268        typedef Declaration Parent;
    270269  public:
     270        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     271        static const char * aggrString( Aggregate aggr );
     272
    271273        std::list<Declaration*> members;
    272274        std::list<TypeDecl*> parameters;
     
    291293        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    292294  protected:
    293         virtual std::string typeString() const = 0;
     295        virtual const char * typeString() const = 0;
    294296};
    295297
     
    297299        typedef AggregateDecl Parent;
    298300  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 ) {}
     301        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 ) {}
    300302        StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {}
    301303
    302         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    303         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    304         bool is_thread() { return kind == DeclarationNode::Thread; }
     304        bool is_coroutine() { return kind == Coroutine; }
     305        bool is_monitor() { return kind == Monitor; }
     306        bool is_thread() { return kind == Thread; }
    305307
    306308        virtual StructDecl *clone() const override { return new StructDecl( *this ); }
     
    308310        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    309311        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    310         DeclarationNode::Aggregate kind;
    311   private:
    312         virtual std::string typeString() const override;
     312        Aggregate kind;
     313  private:
     314        virtual const char * typeString() const override;
    313315};
    314316
     
    324326        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    325327  private:
    326         virtual std::string typeString() const override;
     328        virtual const char * typeString() const override;
    327329};
    328330
     
    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
     
    357359        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    358360  private:
    359         virtual std::string typeString() const override;
     361        virtual const char * typeString() const override;
    360362};
    361363
  • src/SynTree/Expression.cc

    r98d6965d r312029a  
    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

    r98d6965d r312029a  
    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         };
    234232        struct Concrete {
    235233                std::string field;
    236234                std::string getter;
    237235        };
    238         Target target;
     236        AggregateDecl::Aggregate target;
    239237        Concrete concrete_target;
    240238
    241         KeywordCastExpr( Expression * arg, Target target );
     239        KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target );
    242240        KeywordCastExpr( const KeywordCastExpr & other );
    243241        virtual ~KeywordCastExpr();
    244242
    245         const std::string & targetString() const;
     243        const char * targetString() const;
    246244
    247245        virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
  • src/SynTree/FunctionDecl.cc

    r98d6965d r312029a  
    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 : Sat Dec  7 17:40:09 2019
     13// Update Count     : 75
    1414//
    1515
     
    2323#include "Common/utility.h"      // for maybeClone, printAll
    2424#include "Declaration.h"         // for FunctionDecl, FunctionDecl::Parent
     25#include "Expression.h"
    2526#include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
    2627#include "Statement.h"           // for CompoundStmt
  • src/SynTree/NamedTypeDecl.cc

    r98d6965d r312029a  
    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 : Wed Dec 11 08:26:17 2019
     13// Update Count     : 15
    1414//
    1515
     
    7878}
    7979
    80 std::string TypedefDecl::typeString() const { return "typedef"; }
     80const char * TypedefDecl::typeString() const { return "typedef"; }
    8181
    8282// Local Variables: //
  • src/SynTree/TypeDecl.cc

    r98d6965d r312029a  
    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 : Wed Dec 11 17:56:30 2019
     13// Update Count     : 10
    1414//
    1515
     
    1818
    1919#include "Common/utility.h"  // for maybeClone
     20#include "Parser/ParseNode.h"
    2021#include "Declaration.h"     // for TypeDecl, TypeDecl::Data, TypeDecl::Kind...
    2122#include "Type.h"            // for Type, Type::StorageClasses
     
    3132}
    3233
    33 std::string TypeDecl::typeString() const {
    34         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
     34const char * TypeDecl::typeString() const {
     35        static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" };
    3536        assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "typeString: kindNames is out of sync." );
    3637        assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    37         return (isComplete() ? "sized " : "") + kindNames[ kind ];
     38        return isComplete() ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    3839}
    3940
    40 std::string TypeDecl::genTypeString() const {
    41         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
     41const char * TypeDecl::genTypeString() const {
     42        static const char * kindNames[] = { "dtype", "ftype", "ttype" };
    4243        assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    4344        assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
Note: See TracChangeset for help on using the changeset viewer.