Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r658fafe4 re869d663  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ParseNode.h --
     7// ParseNode.h -- 
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul 24 02:17:00 2016
    13 // Update Count     : 269
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 13:27:11 2015
     13// Update Count     : 172
    1414//
    1515
     
    2020#include <list>
    2121#include <iterator>
    22 #include <memory>
    23 
    24 #include "Common/utility.h"
     22
     23#include "utility.h"
    2524#include "Parser/LinkageSpec.h"
    2625#include "SynTree/Type.h"
    27 #include "SynTree/Expression.h"
    2826//#include "SynTree/Declaration.h"
    29 #include "Common/UniqueName.h"
    30 #include "SynTree/Label.h"
     27#include "UniqueName.h"
    3128
    3229class ExpressionNode;
     
    4340        ParseNode();
    4441        ParseNode( const std::string * );
    45         ParseNode( const std::string & );                                       // for copy constructing subclasses
     42        ParseNode( const std::string & );  // for copy constructing subclasses
    4643        virtual ~ParseNode();
    4744
    48         ParseNode *get_link() const { return next; }
     45        ParseNode *get_link() const;
    4946        ParseNode *get_last();
    5047        ParseNode *set_link( ParseNode * );
     
    6259  protected:
    6360        std::string name;
     61        ParseNode *next;
    6462        static int indent_by;
    65         ParseNode *next;
    6663};
    6764
     
    7774        virtual ExpressionNode *clone() const = 0;
    7875
    79         // virtual CommaExprNode *add_to_list( ExpressionNode * );
     76        virtual CommaExprNode *add_to_list( ExpressionNode * );
    8077
    8178        ExpressionNode *get_argName() const { return argName; }
    8279        ExpressionNode *set_argName( const std::string *aName );
    8380        ExpressionNode *set_argName( ExpressionNode *aDesignator );
    84         bool get_extension() const { return extension; }
    85         ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
    8681
    8782        virtual void print( std::ostream &, int indent = 0) const = 0;
     
    9287        void printDesignation ( std::ostream &, int indent = 0) const;
    9388  private:
    94         ExpressionNode *argName = 0;
    95         bool extension = false;
    96 };
    97 
    98 template< typename T >
    99 struct maybeBuild_t<Expression, T> {
    100         static inline Expression * doit( const T *orig ) {
    101                 if ( orig ) {
    102                         Expression *p = orig->build();
    103                         p->set_extension( orig->get_extension() );
    104                         return p;
    105                 } else {
    106                         return 0;
    107                 } // if
    108         }
     89        ExpressionNode *argName;
    10990};
    11091
     
    126107        enum Type { Integer, Float, Character, String };
    127108
    128         ConstantNode( ConstantExpr * );
    129         ConstantNode( const ConstantNode &other ) : expr( other.expr->clone() ) {};
    130         ~ConstantNode() { delete expr; }
     109        ConstantNode( Type, std::string * );
     110        ~ConstantNode() { delete &value; }
    131111
    132112        virtual ConstantNode *clone() const { return new ConstantNode( *this ); }
    133         virtual void print( std::ostream &, int indent = 0) const;
    134         virtual void printOneLine( std::ostream &, int indent = 0) const;
    135 
     113        Type get_type( void ) const { return type; }
     114        virtual void print( std::ostream &, int indent = 0) const;
     115        virtual void printOneLine( std::ostream &, int indent = 0) const;
     116
     117        const std::string &get_value() const { return value; }
    136118        ConstantNode *appendstr( const std::string *newValue );
    137119
    138120        Expression *build() const;
    139121  private:
    140         ConstantExpr *expr;
    141 };
    142 
    143 ConstantNode *makeConstantInteger( std::string & );
    144 ConstantNode *makeConstantFloat( std::string & );
    145 ConstantNode *makeConstantChar( std::string & );
    146 ConstantNode *makeConstantStr( std::string & );
     122        Type type;
     123        BasicType::Kind btype;
     124        std::string &value;
     125};
    147126
    148127class VarRefNode : public ExpressionNode {
     
    195174class OperatorNode : public ExpressionNode {
    196175  public:
    197         enum Type { TupleC, Comma, TupleFieldSel, // n-adic
    198                                 // triadic
    199                                 Cond, NCond,
    200                                 // diadic
    201                                 SizeOf, AlignOf, OffsetOf, Attr, Plus, Minus, Mul, Div, Mod, Or, And,
    202                                 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
    203                                 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
    204                                 Index, FieldSel, PFieldSel, Range,
    205                                 // monadic
    206                                 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,
    207                                 Ctor, Dtor,
     176        enum Type { TupleC, Comma, TupleFieldSel,
     177                                Cond, NCond,
     178                                SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And,
     179                                BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
     180                                Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn,
     181                                ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range,
     182                                UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress
    208183        };
    209184
     
    223198  private:
    224199        Type type;
     200        static const char *OpName[];
    225201};
    226202
     
    286262        virtual void printOneLine( std::ostream &, int indent = 0) const;
    287263
    288         const std::list< Label > &get_labels() const { return labels; };
     264        const std::list< std::string > &get_labels() const { return labels; };
    289265        void append_label( std::string *label ) { labels.push_back( *label ); delete label; }
    290266  private:
    291         std::list< Label > labels;
     267        std::list< std::string > labels;
     268};
     269
     270class CommaExprNode : public CompositeExprNode {
     271  public:
     272        CommaExprNode();
     273        CommaExprNode( ExpressionNode * );
     274        CommaExprNode( ExpressionNode *, ExpressionNode * );
     275        CommaExprNode( const CommaExprNode &other );
     276
     277        virtual CommaExprNode *add_to_list( ExpressionNode * );
     278        virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
    292279};
    293280
     
    319306        ValofExprNode( const ValofExprNode &other );
    320307        ~ValofExprNode();
    321 
     308 
    322309        virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
    323310
     
    339326        enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
    340327        enum Modifier  { Signed, Unsigned, Short, Long };
    341         enum Aggregate { Struct, Union, Trait };
     328        enum Aggregate { Struct, Union, Context };
    342329        enum TypeClass { Type, Dtype, Ftype };
    343         enum BuiltinType { Valist };
    344 
    345         static const char *storageName[];
     330
     331        static const char *storageName[]; 
    346332        static const char *qualifierName[];
    347333        static const char *basicTypeName[];
     
    349335        static const char *aggregateName[];
    350336        static const char *typeClassName[];
    351         static const char *builtinTypeName[];
    352337
    353338        static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false );
     
    358343        static DeclarationNode *newForall( DeclarationNode *);
    359344        static DeclarationNode *newFromTypedef( std::string *);
    360         static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body );
     345        static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields );
    361346        static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
    362347        static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
     
    364349        static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params );
    365350        static DeclarationNode *newTypeParam( TypeClass, std::string *);
    366         static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
    367         static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params );
     351        static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
     352        static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params );
    368353        static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams );
    369354        static DeclarationNode *newPointer( DeclarationNode *qualifiers );
     
    375360        static DeclarationNode *newAttr( std::string *, ExpressionNode *expr );
    376361        static DeclarationNode *newAttr( std::string *, DeclarationNode *type );
    377         static DeclarationNode *newBuiltinType( BuiltinType );
    378362
    379363        DeclarationNode *addQualifiers( DeclarationNode *);
     
    414398        LinkageSpec::Type get_linkage() const { return linkage; }
    415399        DeclarationNode *extractAggregate() const;
    416         ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }
    417 
    418         bool get_extension() const { return extension; }
    419         DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
    420400
    421401        DeclarationNode();
     
    430410        std::list< std::string > attributes;
    431411        ExpressionNode *bitfieldWidth;
    432         ExpressionNode *enumeratorValue;
    433412        InitializerNode *initializer;
    434413        bool hasEllipsis;
    435414        LinkageSpec::Type linkage;
    436         bool extension = false;
    437415
    438416        static UniqueName anonymous;
     
    441419class StatementNode : public ParseNode {
    442420  public:
    443         enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru,
     421        enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru, 
    444422                                While, Do,        For,
    445423                                Goto,  Continue,  Break,   Return,  Throw,
     
    474452        std::string get_target() const;
    475453
    476         // StatementNode *add_controlexp( ExpressionNode * );
     454        StatementNode *add_controlexp( ExpressionNode * );
    477455        StatementNode *append_block( StatementNode * );
    478456        StatementNode *append_last_case( StatementNode * );
     
    519497        ExpressionNode *output, *input;
    520498        ConstantNode *clobber;
    521         std::list< Label > gotolabels;
     499        std::list<std::string> gotolabels;
     500};
     501
     502class NullStmtNode : public CompoundStmtNode {
     503  public:
     504        Statement *build() const;
     505        void print( std::ostream &, int indent = 0 ) const;
    522506};
    523507
     
    533517        ExpressionNode *get_designators() const { return designator; }
    534518
    535         InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
    536         bool get_maybeConstructed() const { return maybeConstructed; }
    537 
    538519        InitializerNode *next_init() const { return kids; }
    539520
     
    546527        bool aggregate;
    547528        ExpressionNode *designator; // may be list
    548         InitializerNode *kids;
    549         bool maybeConstructed;
    550 };
    551 
    552 class CompoundLiteralNode : public ExpressionNode {
    553   public:
    554         CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids );
    555         CompoundLiteralNode( const CompoundLiteralNode &type );
    556         ~CompoundLiteralNode();
    557 
    558         virtual CompoundLiteralNode *clone() const;
    559 
    560         DeclarationNode *get_type() const { return type; }
    561         CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; }
    562 
    563         InitializerNode *get_initializer() const { return kids; }
    564         CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; }
    565 
    566         void print( std::ostream &, int indent = 0 ) const;
    567         void printOneLine( std::ostream &, int indent = 0 ) const;
    568 
    569         virtual Expression *build() const;
    570   private:
    571         DeclarationNode *type;
    572529        InitializerNode *kids;
    573530};
     
    581538        while ( cur ) {
    582539                try {
    583 //                      SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) );
    584                         SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) );
     540                        SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() );
    585541                        if ( result ) {
    586542                                *out++ = result;
Note: See TracChangeset for help on using the changeset viewer.