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