Changes in / [24afc53:aa00626]


Ignore:
Location:
src
Files:
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/CVQualifiers.hpp

    r24afc53 raa00626  
    5959        // ordering is a subtype relationship over qualifiers, e.g. `int` => `const int` is free
    6060
    61         inline bool operator== ( Qualifiers a, Qualifiers b ) {
     61        bool operator== ( Qualifiers a, Qualifiers b ) {
    6262                return (a.val & EquivQualifiers) == (b.val & EquivQualifiers);
    6363        }
    64         inline bool operator!= ( Qualifiers a, Qualifiers b ) {
     64        bool operator!= ( Qualifiers a, Qualifiers b ) {
    6565                return !(a == b);
    6666        }
    67         inline bool operator<= ( Qualifiers a, Qualifiers b ) {
     67        bool operator<= ( Qualifiers a, Qualifiers b ) {
    6868                return a.is_const    <= b.is_const    // non-const converts to const for free
    6969                        && a.is_volatile <= b.is_volatile // non-volatile converts to volatile for free
     
    7171                        && a.is_atomic   == b.is_atomic;  // atomicity must be preserved in free conversion
    7272        }
    73         inline bool operator<  ( Qualifiers a, Qualifiers b ) { return a != b && a <= b; }
    74         inline bool operator>= ( Qualifiers a, Qualifiers b ) { return b <= a; }
    75         inline bool operator>  ( Qualifiers a, Qualifiers b ) { return b < a; }
     73        bool operator<  ( Qualifiers a, Qualifiers b ) { return a != b && a <= b; }
     74        bool operator>= ( Qualifiers a, Qualifiers b ) { return b <= a; }
     75        bool operator>  ( Qualifiers a, Qualifiers b ) { return b < a; }
    7676
    7777}
  • src/AST/Convert.cpp

    r24afc53 raa00626  
    413413        }
    414414
     415        virtual void visit( AttrExpr * ) override final {
     416
     417        }
     418
    415419        virtual void visit( LogicalExpr * ) override final {
    416420
  • src/AST/Decl.hpp

    r24afc53 raa00626  
    3232namespace ast {
    3333
     34class Attribute;
     35class Expr;
     36class Init;
     37class TypeDecl;
     38
    3439/// Base declaration class
    3540class Decl : public ParseNode {
     
    145150public:
    146151        ptr<Type> base;
    147         std::vector<ptr<TypeDecl>> params;
     152        std::vector<ptr<TypeDecl>> parameters;
    148153        std::vector<ptr<DeclWithType>> assertions;
    149154
    150155        NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
    151156                Type* b, Linkage::Spec spec = Linkage::Cforall )
    152         : Decl( loc, name, storage, spec ), base( b ), params(), assertions() {}
     157        : Decl( loc, name, storage, spec ), base( b ), parameters(), assertions() {}
    153158
    154159        /// Produces a name for the kind of alias
     
    226231public:
    227232        std::vector<ptr<Decl>> members;
    228         std::vector<ptr<TypeDecl>> params;
     233        std::vector<ptr<TypeDecl>> parameters;
    229234        std::vector<ptr<Attribute>> attributes;
    230235        bool body = false;
     
    233238        AggregateDecl( const CodeLocation& loc, const std::string& name,
    234239                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    235         : Decl( loc, name, Storage::Classes{}, linkage ), members(), params(),
     240        : Decl( loc, name, Storage::Classes{}, linkage ), members(), parameters(),
    236241          attributes( std::move(attrs) ) {}
    237242
  • src/AST/Expr.hpp

    r24afc53 raa00626  
    1818#include <cassert>
    1919#include <map>
    20 #include <string>
    2120#include <utility>        // for move
    2221#include <vector>
    2322
    2423#include "Fwd.hpp"        // for UniqueId
    25 #include "Label.hpp"
    2624#include "ParseNode.hpp"
    2725#include "Visitor.hpp"
     
    119117        bool extension = false;
    120118
    121         Expr( const CodeLocation & loc, const Type * res = nullptr )
    122         : ParseNode( loc ), result( res ), env(), inferred() {}
     119        Expr(const CodeLocation & loc ) : ParseNode( loc ), result(), env(), inferred() {}
    123120
    124121        Expr * set_extension( bool ex ) { extension = ex; return this; }
     
    129126};
    130127
    131 /// The application of a function to a set of parameters.
    132 /// Post-resolver form of `UntypedExpr`
    133 class ApplicationExpr final : public Expr {
    134 public:
    135         ptr<Expr> func;
    136         std::vector<ptr<Expr>> args;
    137 
    138         ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} );
    139 
    140         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    141 private:
    142         ApplicationExpr * clone() const override { return new ApplicationExpr{ *this }; }
    143 };
    144 
    145 /// The application of a function to a set of parameters, pre-overload resolution.
    146 class UntypedExpr final : public Expr {
    147 public:
    148         ptr<Expr> func;
    149         std::vector<ptr<Expr>> args;
    150 
    151         UntypedExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} )
    152         : Expr( loc ), func( f ), args( std::move(as) ) {}
    153 
    154         /// Creates a new dereference expression
    155         static UntypedExpr * createDeref( const CodeLocation & loc, Expr * arg );
    156         /// Creates a new assignment expression
    157         static UntypedExpr * createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs );
    158 
    159         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    160 private:
    161         UntypedExpr * clone() const override { return new UntypedExpr{ *this }; }
    162 };
    163 
    164 /// A name whose name is as-yet undetermined.
    165 /// May also be used to avoid name mangling in codegen phase.
    166 class NameExpr final : public Expr {
    167 public:
    168         std::string name;
    169 
    170         NameExpr( const CodeLocation & loc, const std::string & n ) : Expr( loc ), name( n ) {}
    171 
    172         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    173 private:
    174         NameExpr * clone() const override { return new NameExpr{ *this }; }
    175 };
    176 
    177 /// Address-of expression `&e`
    178 class AddressExpr final : public Expr {
    179 public:
    180         ptr<Expr> arg;
    181 
    182         AddressExpr( const CodeLocation & loc, const Expr * a );
    183 
    184         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    185 private:
    186         AddressExpr * clone() const override { return new AddressExpr{ *this }; }
    187 };
    188 
    189 /// GCC &&label
    190 /// https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html
    191 class LabelAddressExpr final : public Expr {
    192 public:
    193         Label arg;
    194 
    195         LabelAddressExpr( const CodeLocation & loc, Label && a );
    196 
    197         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    198 private:
    199         LabelAddressExpr * clone() const override { return new LabelAddressExpr{ *this }; }
    200 };
    201 
    202 /// Whether a cast existed in the program source or not
    203 enum GeneratedFlag { ExplicitCast, GeneratedCast };
    204 
    205 /// A type cast, e.g. `(int)e`
    206 class CastExpr final : public Expr {
    207 public:
    208         ptr<Expr> arg;
    209         GeneratedFlag isGenerated;
    210 
    211         CastExpr( const CodeLocation & loc, const Expr * a, const Type * to,
    212                 GeneratedFlag g = GeneratedCast ) : Expr( loc, to ), arg( a ), isGenerated( g ) {}
    213         /// Cast-to-void
    214         CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g = GeneratedCast );
    215 
    216         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    217 private:
    218         CastExpr * clone() const override { return new CastExpr{ *this }; }
    219 };
    220 
    221 /// A cast to "keyword types", e.g. `(thread &)t`
    222 class KeywordCastExpr final : public Expr {
    223 public:
    224         ptr<Expr> arg;
    225         enum Target { Coroutine, Thread, Monitor, NUMBER_OF_TARGETS } target;
    226 
    227         KeywordCastExpr( const CodeLocation & loc, const Expr * a, Target t )
    228         : Expr( loc ), arg( a ), target( t ) {}
    229 
    230         /// Get a name for the target type
    231         const std::string& targetString() const;
    232 
    233         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    234 private:
    235         KeywordCastExpr * clone() const override { return new KeywordCastExpr{ *this }; }
    236 };
    237 
    238 /// A virtual dynamic cast, e.g. `(virtual exception)e`
    239 class VirtualCastExpr final : public Expr {
    240 public:
    241         ptr<Expr> arg;
    242 
    243         VirtualCastExpr( const CodeLocation & loc, const Expr * a, const Type * to )
    244         : Expr( loc, to ), arg( a ) {}
    245 
    246         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    247 private:
    248         VirtualCastExpr * clone() const override { return new VirtualCastExpr{ *this }; }
    249 };
    250 
    251 /// A member selection operation before expression resolution, e.g. `q.p`
    252 class UntypedMemberExpr final : public Expr {
    253 public:
    254         ptr<Expr> member;
    255         ptr<Expr> aggregate;
    256 
    257         UntypedMemberExpr( const CodeLocation & loc, const Expr * mem, const Expr * agg )
    258         : Expr( loc ), member( mem ), aggregate( agg ) { assert( aggregate ); }
    259 
    260         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    261 private:
    262         UntypedMemberExpr * clone() const override { return new UntypedMemberExpr{ *this }; }
    263 };
    264 
    265 /// A member selection operation after expression resolution, e.g. `q.p`
    266 class MemberExpr final : public Expr {
    267 public:
    268         readonly<DeclWithType> member;
    269         ptr<Expr> aggregate;
    270 
    271         MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg );
    272 
    273         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    274 private:
    275         MemberExpr * clone() const override { return new MemberExpr{ *this }; }
    276 };
    277 
    278 /// A reference to a named variable.
    279 class VariableExpr final : public Expr {
    280 public:
    281         readonly<DeclWithType> var;
    282 
    283         VariableExpr( const CodeLocation & loc, const DeclWithType * v );
    284 
    285         /// generates a function pointer for a given function
    286         static VariableExpr * functionPointer( const CodeLocation & loc, const FunctionDecl * decl );
    287 
    288         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    289 private:
    290         VariableExpr * clone() const override { return new VariableExpr{ *this }; }
    291 };
    292 
    293 /// A compile-time constant
    294 class ConstantExpr final : public Expr {
    295         union Val {
    296                 unsigned long long ival;
    297                 double dval;
    298                
    299                 Val( unsigned long long i ) : ival( i ) {}
    300                 Val( double d ) : dval( d ) {}
    301         } val;
    302 public:
    303         std::string rep;
    304 
    305         ConstantExpr(
    306                 const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v )
    307         : Expr( loc, ty ), val( v ), rep( r ) {}
    308         ConstantExpr( const CodeLocation & loc, const Type * ty, const std::string & r, double v )
    309         : Expr( loc, ty ), val( v ), rep( r ) {}
    310        
    311         /// Gets the value of this constant as an integer
    312         long long int intValue() const;
    313         /// Gets the value of this constant as floating point
    314         double floatValue() const;
    315 
    316         /// generates a boolean constant of the given bool
    317         static ConstantExpr * from_bool( const CodeLocation & loc, bool b );
    318         /// generates a char constant of the given char
    319         static ConstantExpr * from_char( const CodeLocation & loc, char c );
    320         /// generates an integer constant of the given int
    321         static ConstantExpr * from_int( const CodeLocation & loc, int i );
    322         /// generates an integer constant of the given unsigned long int
    323         static ConstantExpr * from_ulong( const CodeLocation & loc, unsigned long i );
    324         /// generates a floating point constant of the given double
    325         static ConstantExpr * from_double( const CodeLocation & loc, double d );
    326         /// generates an array of chars constant of the given string
    327         static ConstantExpr * from_string( const CodeLocation & loc, const std::string & s );
    328         /// generates a null pointer value for the given type. void * if omitted.
    329         static ConstantExpr * null( const CodeLocation & loc, const Type * ptrType = nullptr );
    330 
    331         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    332 private:
    333         ConstantExpr * clone() const override { return new ConstantExpr{ *this }; }
    334 };
    335 
    336 /// sizeof expression, e.g. `sizeof(int)`, `sizeof 3+4`
    337 class SizeofExpr final : public Expr {
    338 public:
    339         ptr<Expr> expr;
    340         ptr<Type> type;
    341 
    342         SizeofExpr( const CodeLocation & loc, const Expr * e );
    343         SizeofExpr( const CodeLocation & loc, const Type * t );
    344         // deliberately no disambiguating overload for nullptr_t
    345 
    346         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    347 private:
    348         SizeofExpr * clone() const override { return new SizeofExpr{ *this }; }
    349 };
    350 
    351 /// alignof expression, e.g. `alignof(int)`, `alignof 3+4`
    352 class AlignofExpr final : public Expr {
    353 public:
    354         ptr<Expr> expr;
    355         ptr<Type> type;
    356 
    357         AlignofExpr( const CodeLocation & loc, const Expr * e );
    358         AlignofExpr( const CodeLocation & loc, const Type * t );
    359         // deliberately no disambiguating overload for nullptr_t
    360 
    361         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    362 private:
    363         AlignofExpr * clone() const override { return new AlignofExpr{ *this }; }
    364 };
    365 
    366 /// offsetof expression before resolver determines field, e.g. `offsetof(MyStruct, myfield)`
    367 class UntypedOffsetofExpr final : public Expr {
    368 public:
    369         ptr<Type> type;
    370         std::string member;
    371 
    372         UntypedOffsetofExpr( const CodeLocation & loc, const Type * ty, const std::string & mem )
    373         : Expr( loc ), type( ty ), member( mem ) {}
    374 
    375         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    376 private:
    377         UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr{ *this }; }
    378 };
    379 
    380 /// offsetof expression after resolver determines field, e.g. `offsetof(MyStruct, myfield)`
    381 class OffsetofExpr final : public Expr {
    382 public:
    383         ptr<Type> type;
    384         readonly<DeclWithType> member;
    385 
    386         OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem );
    387 
    388         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    389 private:
    390         OffsetofExpr * clone() const override { return new OffsetofExpr{ *this }; }
    391 };
    392 
    393 /// a pack of field-offsets for a generic type
    394 class OffsetPackExpr final : public Expr {
    395 public:
    396         ptr<StructInstType> type;
    397 
    398         OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty );
    399 
    400         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    401 private:
    402         OffsetPackExpr * clone() const override { return new OffsetPackExpr{ *this }; }
    403 };
    404 
    405 /// Variants of short-circuiting logical expression
    406 enum LogicalFlag { OrExpr, AndExpr };
    407 
    408 /// Short-circuiting boolean expression (`&&` or `||`)
    409 class LogicalExpr final : public Expr {
    410 public:
    411         ptr<Expr> arg1;
    412         ptr<Expr> arg2;
    413         LogicalFlag isAnd;
    414 
    415         LogicalExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia );
    416 
    417         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    418 private:
    419         LogicalExpr * clone() const override { return new LogicalExpr{ *this }; }
    420 };
    421 
    422 /// Three-argument conditional e.g. `p ? a : b`
    423 class ConditionalExpr final : public Expr {
    424 public:
    425         ptr<Expr> arg1;
    426         ptr<Expr> arg2;
    427         ptr<Expr> arg3;
    428 
    429         ConditionalExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2, const Expr * a3 )
    430         : Expr( loc ), arg1( a1 ), arg2( a2 ), arg3( a3 ) {}
    431 
    432         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    433 private:
    434         ConditionalExpr * clone() const override { return new ConditionalExpr{ *this }; }
    435 };
    436 
    437 /// Comma expression e.g. `( a , b )`
    438 class CommaExpr final : public Expr {
    439 public:
    440         ptr<Expr> arg1;
    441         ptr<Expr> arg2;
    442 
    443         CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 )
    444         : Expr( loc ), arg1( a1 ), arg2( a2 ) {}
    445 
    446         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    447 private:
    448         CommaExpr * clone() const override { return new CommaExpr{ *this }; }
    449 };
    450 
    451128/// A type used as an expression (e.g. a type generator parameter)
    452129class TypeExpr final : public Expr {
     
    461138};
    462139
    463 /// A GCC "asm constraint operand" used in an asm statement, e.g. `[output] "=f" (result)`.
    464 /// https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
    465 class AsmExpr final : public Expr {
    466 public:
    467         ptr<Expr> inout;
    468         ptr<Expr> constraint;
    469 };
    470140
    471141//=================================================================================================
     
    476146inline void increment( const class Expr * node, Node::ref_type ref ) { node->increment(ref); }
    477147inline void decrement( const class Expr * node, Node::ref_type ref ) { node->decrement(ref); }
    478 inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); }
    479 inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    480 inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    481 inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    482 inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); }
    483 inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    484 inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    485 inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    486 inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    487 inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    488 inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    489 inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    490 inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    491 inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    492 inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    493 inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    494 inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    495 inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    496 inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    497 inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    498 inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); }
    499 inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    500 inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); }
    501 inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    502 inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    503 inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    504 inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    505 inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    506 inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    507 inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    508 inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    509 inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    510 inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); }
    511 inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    512 inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    513 inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    514 inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    515 inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    516 inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); }
    517 inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    518 inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    519 inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    520 inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
    521 inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     148// inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); }
     149// inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     150// inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); }
     151// inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     152// inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); }
     153// inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     154// inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
     155// inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     156// inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
     157// inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     158// inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); }
     159// inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     160// inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
     161// inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     162// inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
     163// inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     164// inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
     165// inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     166// inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
     167// inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     168// inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); }
     169// inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     170// inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); }
     171// inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     172// inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); }
     173// inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     174// inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); }
     175// inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     176// inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
     177// inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     178// inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
     179// inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     180// inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); }
     181// inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     182// inline void increment( const class AttrExpr * node, Node::ref_type ref ) { node->increment(ref); }
     183// inline void decrement( const class AttrExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     184// inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); }
     185// inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     186// inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); }
     187// inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     188// inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); }
     189// inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     190// inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); }
     191// inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     192// inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
     193// inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    522194// inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    523195// inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
  • src/AST/Fwd.hpp

    r24afc53 raa00626  
    7777class OffsetofExpr;
    7878class OffsetPackExpr;
     79class AttrExpr;
    7980class LogicalExpr;
    8081class ConditionalExpr;
     
    251252inline void increment( const class OffsetPackExpr *, Node::ref_type );
    252253inline void decrement( const class OffsetPackExpr *, Node::ref_type );
     254inline void increment( const class AttrExpr *, Node::ref_type );
     255inline void decrement( const class AttrExpr *, Node::ref_type );
    253256inline void increment( const class LogicalExpr *, Node::ref_type );
    254257inline void decrement( const class LogicalExpr *, Node::ref_type );
  • src/AST/Node.hpp

    r24afc53 raa00626  
    7676// problems and be able to use auto return
    7777template<typename node_t>
    78 auto mutate( const node_t * node ) {
     78auto mutate(const node_t * node) {
    7979        assertf(
    8080                node->strong_count >= 1,
     
    9292}
    9393
    94 std::ostream& operator<< ( std::ostream& out, const Node * node );
     94std::ostream& operator<< ( std::ostream& out, const Node* node );
    9595
    9696/// Base class for the smart pointer types
     
    137137        operator const node_t * () const { return node; }
    138138
    139         /// wrapper for convenient access to dynamic_cast
    140139        template<typename o_node_t>
    141140        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
    142 
    143         /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
    144         /// Returns a mutable version of the pointer in this node.
    145         node_t * set_and_mutate( const node_t * n ) {
    146                 // ensure ownership of `n` by this node to avoid spurious single-owner mutates
    147                 assign( n );
    148                 // get mutable version of `n`
    149                 auto r = mutate( node );
    150                 // re-assign mutable version in case `mutate()` produced a new pointer
    151                 assign( r );
    152                 return r;
    153         }
    154141
    155142        using ptr = const node_t *;
  • src/AST/Type.hpp

    r24afc53 raa00626  
    3232
    3333class Type : public Node {
    34 public:
    35         CV::Qualifiers qualifiers;
    36        
    37         Type( CV::Qualifiers q = {} ) : qualifiers(q) {}
    38 
    39         bool is_const() const { return qualifiers.is_const; }
    40         bool is_volatile() const { return qualifiers.is_volatile; }
    41         bool is_restrict() const { return qualifiers.is_restrict; }
    42         bool is_lvalue() const { return qualifiers.is_lvalue; }
    43         bool is_mutex() const { return qualifiers.is_mutex; }
    44         bool is_atomic() const { return qualifiers.is_atomic; }
    45 
    46         void set_const( bool v ) { qualifiers.is_const = v; }
    47         void set_restrict( bool v ) { qualifiers.is_restrict = v; }
    48         void set_lvalue( bool v ) { qualifiers.is_lvalue = v; }
    49         void set_mutex( bool v ) { qualifiers.is_mutex = v; }
    50         void set_atomic( bool v ) { qualifiers.is_atomic = v; }
     34        CV::Qualifiers tq;
     35public:
     36        Type( CV::Qualifiers q = {} ) : tq(q) {}
     37
     38        CV::Qualifiers qualifiers() const { return tq; }
     39        bool is_const() const { return tq.is_const; }
     40        bool is_volatile() const { return tq.is_volatile; }
     41        bool is_restrict() const { return tq.is_restrict; }
     42        bool is_lvalue() const { return tq.is_lvalue; }
     43        bool is_mutex() const { return tq.is_mutex; }
     44        bool is_atomic() const { return tq.is_atomic; }
     45
     46        void set_qualifiers( CV::Qualifiers q ) { tq = q; }
     47        void set_const( bool v ) { tq.is_const = v; }
     48        void set_restrict( bool v ) { tq.is_restrict = v; }
     49        void set_lvalue( bool v ) { tq.is_lvalue = v; }
     50        void set_mutex( bool v ) { tq.is_mutex = v; }
     51        void set_atomic( bool v ) { tq.is_atomic = v; }
    5152
    5253        /// How many elemental types are represented by this type
     
    253254class FunctionType final : public ParameterizedType {
    254255public:
    255         std::vector<ptr<DeclWithType>> returns;
    256         std::vector<ptr<DeclWithType>> params;
     256        std::vector<ptr<DeclWithType>> returnVals;
     257        std::vector<ptr<DeclWithType>> parameters;
    257258
    258259        /// Does the function accept a variable number of arguments following the arguments specified
     
    264265
    265266        FunctionType( ArgumentFlag va = FixedArgs, CV::Qualifiers q = {} )
    266         : ParameterizedType(q), returns(), params(), isVarArgs(va) {}
     267        : ParameterizedType(q), returnVals(), parameters(), isVarArgs(va) {}
    267268
    268269        /// true if either the parameters or return values contain a tttype
    269270        bool isTtype() const;
    270271        /// true if function parameters are unconstrained by prototype
    271         bool isUnprototyped() const { return isVarArgs && params.size() == 0; }
     272        bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; }
    272273
    273274        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
     
    279280class ReferenceToType : public ParameterizedType {
    280281public:
    281         std::vector<ptr<Expr>> params;
     282        std::vector<ptr<Expr>> parameters;
    282283        std::vector<ptr<Attribute>> attributes;
    283284        std::string name;
     
    286287        ReferenceToType( const std::string& n, CV::Qualifiers q = {},
    287288                std::vector<ptr<Attribute>> && as = {} )
    288         : ParameterizedType(q), params(), attributes(std::move(as)), name(n) {}
     289        : ParameterizedType(q), parameters(), attributes(std::move(as)), name(n) {}
    289290
    290291        /// Gets aggregate declaration this type refers to
  • src/AST/Visitor.hpp

    r24afc53 raa00626  
    6969    virtual const ast::Expr *             visit( const ast::OffsetofExpr         * ) = 0;
    7070    virtual const ast::Expr *             visit( const ast::OffsetPackExpr       * ) = 0;
     71    virtual const ast::Expr *             visit( const ast::AttrExpr             * ) = 0;
    7172    virtual const ast::Expr *             visit( const ast::LogicalExpr          * ) = 0;
    7273    virtual const ast::Expr *             visit( const ast::ConditionalExpr      * ) = 0;
  • src/AST/porting.md

    r24afc53 raa00626  
    66  * specialization: strong pointer `ast::ptr<T>` is used for an ownership relationship
    77  * specialization: weak pointer `ast::readonly<T>` is used for an observation relationship
    8 * added `ast::ptr_base<T,R>::as<S>()` with same semantics as `dynamic_cast<S*>(p)`
    9 * added `N * ast::ptr_base<N,R>::set_and_mutate( const N * n )`
    10   * takes ownership of `n`, then returns a mutable version owned by this pointer
    11   * Some debate on whether this is a good approach:
    12     * makes an easy path to cloning, which we were trying to eliminate
    13       * counter-point: these are all mutating clones rather than lifetime-preserving clones, and thus "necessary" (for some definition)
    14     * existing uses:
    15       * `VariableExpr::VariableExpr`, `UntypedExpr::createDeref`
    16         * both involve grabbing a type from elsewhere and making an `lvalue` copy of it
    17         * could potentially be replaced by a view class something like this:
    18           ```
    19           template<unsigned Quals>
    20           class AddQualifiersType final : public Type {
    21             readonly<Type> base;
    22             // ...
    23           };
    24           ```
    25           * requires all `qualifiers` use (and related helpers) to be virtual, non-zero overhead
    26           * also subtle semantic change, where mutations to the source decl now change the viewing expression
     8  * added `ast::ptr_base<T,R>::as<S>()` with same semantics as `dynamic_cast<S*>(p)`
    279
    2810## Visitors ##
     
    124106  * allows `newObject` as just default settings
    125107
    126 `NamedTypeDecl`
    127 * `parameters` => `params`
    128 
    129108`TypeDecl`
    130109* moved `TypeDecl::Kind` to `ast::TypeVar::Kind`
    131 
    132 `AggregateDecl`
    133 * `parameters` => `params`
    134110
    135111`EnumDecl`
     
    139115* Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version
    140116  * does imply get_/set_ API, and some care about moving backward
    141 * added constructor that sets result, for benefit of types that set it directly
    142 
    143 `ApplicationExpr`
    144 * `function` => `func`
    145 
    146 `UntypedExpr`
    147 * `function` => `func`
    148 * removed `begin_args()` in favour of `args.begin()`
    149 
    150 `MemberExpr`
    151 * **TODO** port setup of `result` in constructor
    152 
    153 `ConstantExpr`
    154 * inlined features of `Constant`, never used elsewhere, so removed `Constant`
    155   * `Constant Constant::from_int(int)` etc. => `ConstantExpr * ConstantExpr::from_int(CodeLocation, int)`
    156     * allocates new `ConstantExpr`, consistent with all existing uses
    157 
    158 `SizeofExpr`, `AlignofExpr`
    159 * `isType` deprecated in favour of boolean check on `type`
    160   * all existing uses assume `type` set if true and don't use `expr`
    161 
    162 `AttrExpr`
    163 * did not port due to feature deprecation (e.g. `expr@attribute`)
    164 
    165 `LogicalExpr`
    166 * un-defaulted constructor parameter determining `&&` or `||`
    167117
    168118`Init`
     
    198148`Type`
    199149* `CV::Qualifiers` moved to end of constructor parameter list, defaulted to `{}`
    200   * removed getter, setter in favour of public `qualifiers` field
    201150  * `ReferenceToType` puts a defaulted list of attributes after qualifiers
    202151* `forall` field split off into `ParameterizedType` subclass
     
    211160  * `getAggr()` => `aggr()`
    212161    * also now returns `const AggregateDecl *`
    213 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write
     162* `genericSubstitution()` moved to own visitor **TODO** write
    214163
    215164`BasicType`
     
    218167`ReferenceToType`
    219168* deleted `get_baseParameters()` from children
    220   * replace with `aggr() ? aggr()->params : nullptr`
    221 * `parameters` => `params`
     169  * replace with `aggr() ? aggr()->parameters : nullptr`
    222170* hoisted `lookup` implementation into parent, made non-virtual
    223171  * also changed to return vector rather than filling; change back if any great win for reuse
     
    230178
    231179`FunctionType`
    232 * `returnVals` => `returns`
    233 * `parameters` => `params`
    234180* `bool isVarArgs;` => `enum ArgumentFlag { FixedArgs, VariableArgs }; ArgumentFlag isVarArgs;`
    235181
  • src/ResolvExpr/Unify.cc

    r24afc53 raa00626  
    2121#include <string>                 // for string, operator==, operator!=, bas...
    2222#include <utility>                // for pair, move
    23 #include <vector>
    24 
    25 #include "AST/Node.hpp"
    26 #include "AST/Type.hpp"
     23
    2724#include "Common/PassVisitor.h"   // for PassVisitor
    2825#include "FindOpenVars.h"         // for findOpenVars
     
    633630        }
    634631
     632        // xxx - compute once and store in the FunctionType?
    635633        Type * extractResultType( FunctionType * function ) {
    636634                if ( function->get_returnVals().size() == 0 ) {
     
    646644                }
    647645        }
    648 
    649         ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func ) {
    650                 assert(!"restore after AST added to build");
    651                 // if ( func->returns.empty() ) return new ast::VoidType{};
    652                 // if ( func->returns.size() == 1 ) return func->returns[0]->get_type();
    653 
    654                 // std::vector<ast::ptr<ast::Type>> tys;
    655                 // for ( const ast::DeclWithType * decl : func->returns ) {
    656                 //      tys.emplace_back( decl->get_type() );
    657                 // }
    658                 // return new ast::TupleType{ std::move(tys) };
    659         }
    660646} // namespace ResolvExpr
    661647
  • src/ResolvExpr/typeops.h

    r24afc53 raa00626  
    1818#include <vector>
    1919
    20 #include "AST/Node.hpp"
    21 #include "AST/Type.hpp"
    2220#include "SynTree/SynTree.h"
    2321#include "SynTree/Type.h"
     
    10199        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
    102100        Type * extractResultType( FunctionType * functionType );
    103         /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
    104         ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
    105101
    106102        // in CommonType.cc
Note: See TracChangeset for help on using the changeset viewer.