Home | History | Annotate | Line # | Download | only in dmd
      1 
      2 /* Compiler implementation of the D programming language
      3  * Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved
      4  * written by Walter Bright
      5  * https://www.digitalmars.com
      6  * Distributed under the Boost Software License, Version 1.0.
      7  * https://www.boost.org/LICENSE_1_0.txt
      8  * https://github.com/dlang/dmd/blob/master/src/dmd/attrib.h
      9  */
     10 
     11 #pragma once
     12 
     13 #include "root/port.h"
     14 #include "dsymbol.h"
     15 
     16 class Expression;
     17 class Condition;
     18 class StaticForeach;
     19 
     20 /**************************************************************/
     21 
     22 class AttribDeclaration : public Dsymbol
     23 {
     24 public:
     25     Dsymbols *decl;     // array of Dsymbol's
     26 
     27     virtual Dsymbols *include(Scope *sc);
     28     virtual Scope *newScope(Scope *sc);
     29     void addMember(Scope *sc, ScopeDsymbol *sds);
     30     void setScope(Scope *sc);
     31     void importAll(Scope *sc);
     32     void addComment(const utf8_t *comment);
     33     const char *kind() const;
     34     bool oneMember(Dsymbol **ps, Identifier *ident);
     35     void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
     36     bool hasPointers();
     37     bool hasStaticCtorOrDtor();
     38     void checkCtorConstInit();
     39     void addLocalClass(ClassDeclarations *);
     40     AttribDeclaration *isAttribDeclaration() { return this; }
     41 
     42     void accept(Visitor *v) { v->visit(this); }
     43 };
     44 
     45 class StorageClassDeclaration : public AttribDeclaration
     46 {
     47 public:
     48     StorageClass stc;
     49 
     50     StorageClassDeclaration *syntaxCopy(Dsymbol *s);
     51     Scope *newScope(Scope *sc);
     52     bool oneMember(Dsymbol **ps, Identifier *ident);
     53     void addMember(Scope *sc, ScopeDsymbol *sds);
     54     StorageClassDeclaration *isStorageClassDeclaration() { return this; }
     55 
     56     void accept(Visitor *v) { v->visit(this); }
     57 };
     58 
     59 class DeprecatedDeclaration : public StorageClassDeclaration
     60 {
     61 public:
     62     Expression *msg;
     63     const char *msgstr;
     64 
     65     DeprecatedDeclaration *syntaxCopy(Dsymbol *s);
     66     Scope *newScope(Scope *sc);
     67     void setScope(Scope *sc);
     68     void accept(Visitor *v) { v->visit(this); }
     69 };
     70 
     71 class LinkDeclaration : public AttribDeclaration
     72 {
     73 public:
     74     LINK linkage;
     75 
     76     static LinkDeclaration *create(const Loc &loc, LINK p, Dsymbols *decl);
     77     LinkDeclaration *syntaxCopy(Dsymbol *s);
     78     Scope *newScope(Scope *sc);
     79     const char *toChars() const;
     80     void accept(Visitor *v) { v->visit(this); }
     81 };
     82 
     83 class CPPMangleDeclaration : public AttribDeclaration
     84 {
     85 public:
     86     CPPMANGLE cppmangle;
     87 
     88     CPPMangleDeclaration *syntaxCopy(Dsymbol *s);
     89     Scope *newScope(Scope *sc);
     90     void setScope(Scope *sc);
     91     const char *toChars() const;
     92     void accept(Visitor *v) { v->visit(this); }
     93 };
     94 
     95 class CPPNamespaceDeclaration : public AttribDeclaration
     96 {
     97 public:
     98     Expression *exp;
     99 
    100     CPPNamespaceDeclaration *syntaxCopy(Dsymbol *s);
    101     Scope *newScope(Scope *sc);
    102     const char *toChars() const;
    103     void accept(Visitor *v) { v->visit(this); }
    104 };
    105 
    106 class VisibilityDeclaration : public AttribDeclaration
    107 {
    108 public:
    109     Visibility visibility;
    110     DArray<Identifier*> pkg_identifiers;
    111 
    112     VisibilityDeclaration *syntaxCopy(Dsymbol *s);
    113     Scope *newScope(Scope *sc);
    114     void addMember(Scope *sc, ScopeDsymbol *sds);
    115     const char *kind() const;
    116     const char *toPrettyChars(bool unused);
    117     VisibilityDeclaration *isVisibilityDeclaration() { return this; }
    118     void accept(Visitor *v) { v->visit(this); }
    119 };
    120 
    121 class AlignDeclaration : public AttribDeclaration
    122 {
    123 public:
    124     Expressions *alignExps;
    125     structalign_t salign;
    126 
    127     AlignDeclaration(const Loc &loc, Expression *ealign, Dsymbols *decl);
    128     AlignDeclaration *syntaxCopy(Dsymbol *s);
    129     Scope *newScope(Scope *sc);
    130     void accept(Visitor *v) { v->visit(this); }
    131 };
    132 
    133 class AnonDeclaration : public AttribDeclaration
    134 {
    135 public:
    136     bool isunion;
    137     int sem;                    // 1 if successful semantic()
    138     unsigned anonoffset;        // offset of anonymous struct
    139     unsigned anonstructsize;    // size of anonymous struct
    140     unsigned anonalignsize;     // size of anonymous struct for alignment purposes
    141 
    142     AnonDeclaration *syntaxCopy(Dsymbol *s);
    143     void setScope(Scope *sc);
    144     void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
    145     const char *kind() const;
    146     AnonDeclaration *isAnonDeclaration() { return this; }
    147     void accept(Visitor *v) { v->visit(this); }
    148 };
    149 
    150 class PragmaDeclaration : public AttribDeclaration
    151 {
    152 public:
    153     Expressions *args;          // array of Expression's
    154 
    155     PragmaDeclaration *syntaxCopy(Dsymbol *s);
    156     Scope *newScope(Scope *sc);
    157     PINLINE evalPragmaInline(Scope* sc);
    158     const char *kind() const;
    159     void accept(Visitor *v) { v->visit(this); }
    160 };
    161 
    162 class ConditionalDeclaration : public AttribDeclaration
    163 {
    164 public:
    165     Condition *condition;
    166     Dsymbols *elsedecl; // array of Dsymbol's for else block
    167 
    168     ConditionalDeclaration *syntaxCopy(Dsymbol *s);
    169     bool oneMember(Dsymbol **ps, Identifier *ident);
    170     Dsymbols *include(Scope *sc);
    171     void addComment(const utf8_t *comment);
    172     void setScope(Scope *sc);
    173     void accept(Visitor *v) { v->visit(this); }
    174 };
    175 
    176 class StaticIfDeclaration : public ConditionalDeclaration
    177 {
    178 public:
    179     ScopeDsymbol *scopesym;
    180     bool addisdone;
    181     bool onStack;
    182 
    183     StaticIfDeclaration *syntaxCopy(Dsymbol *s);
    184     Dsymbols *include(Scope *sc);
    185     void addMember(Scope *sc, ScopeDsymbol *sds);
    186     void setScope(Scope *sc);
    187     void importAll(Scope *sc);
    188     const char *kind() const;
    189     void accept(Visitor *v) { v->visit(this); }
    190 };
    191 
    192 class StaticForeachDeclaration : public AttribDeclaration
    193 {
    194 public:
    195     StaticForeach *sfe;
    196     ScopeDsymbol *scopesym;
    197     bool onStack;
    198     bool cached;
    199     Dsymbols *cache;
    200 
    201     StaticForeachDeclaration *syntaxCopy(Dsymbol *s);
    202     bool oneMember(Dsymbol **ps, Identifier *ident);
    203     Dsymbols *include(Scope *sc);
    204     void addMember(Scope *sc, ScopeDsymbol *sds);
    205     void addComment(const utf8_t *comment);
    206     void setScope(Scope *sc);
    207     void importAll(Scope *sc);
    208     const char *kind() const;
    209     void accept(Visitor *v) { v->visit(this); }
    210 };
    211 
    212 class ForwardingAttribDeclaration : public AttribDeclaration
    213 {
    214 public:
    215     ForwardingScopeDsymbol *sym;
    216 
    217     Scope *newScope(Scope *sc);
    218     void addMember(Scope *sc, ScopeDsymbol *sds);
    219     ForwardingAttribDeclaration *isForwardingAttribDeclaration() { return this; }
    220     void accept(Visitor *v) { v->visit(this); }
    221 };
    222 
    223 // Mixin declarations
    224 
    225 class CompileDeclaration : public AttribDeclaration
    226 {
    227 public:
    228     Expressions *exps;
    229 
    230     ScopeDsymbol *scopesym;
    231     bool compiled;
    232 
    233     CompileDeclaration *syntaxCopy(Dsymbol *s);
    234     void addMember(Scope *sc, ScopeDsymbol *sds);
    235     void setScope(Scope *sc);
    236     const char *kind() const;
    237     void accept(Visitor *v) { v->visit(this); }
    238 };
    239 
    240 /**
    241  * User defined attributes look like:
    242  *      @(args, ...)
    243  */
    244 class UserAttributeDeclaration : public AttribDeclaration
    245 {
    246 public:
    247     Expressions *atts;
    248 
    249     UserAttributeDeclaration *syntaxCopy(Dsymbol *s);
    250     Scope *newScope(Scope *sc);
    251     void setScope(Scope *sc);
    252     Expressions *getAttributes();
    253     const char *kind() const;
    254     void accept(Visitor *v) { v->visit(this); }
    255 };
    256