Debian Codegraph @

gcc/d/dmd/module.h

raw
1
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2025 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/module.h
9 */
10
11 #pragma once
12
13 #include "dsymbol.h"
14
15 struct ModuleDeclaration;
16 struct Escape;
17 struct FileBuffer;
18
19 struct MacroTable
20 {
21 void* internal; // PIMPL
22 };
23
24 enum PKG
25 {
26 PKGunknown, // not yet determined whether it's a package.d or not
27 PKGmodule, // already determined that's an actual package.d
28 PKGpackage // already determined that's an actual package
29 };
30
31 enum class Edition : unsigned char
32 {
33 none = 0u,
34 legacy = 1u,
35 v2024 = 2u,
36 latest = 2u,
37 };
38
39 class Package : public ScopeDsymbol
40 {
41 public:
42 PKG isPkgMod;
43 unsigned tag; // auto incremented tag, used to mask package tree in scopes
44 Module *mod; // != NULL if isPkgMod == PKGmodule
45
46 const char *kind() const override;
47
48 bool equals(const RootObject * const o) const override;
49
50 bool isAncestorPackageOf(const Package * const pkg) const;
51
52 void accept(Visitor *v) override { v->visit(this); }
53
54 Module *isPackageMod();
55 };
56
57 class Module final : public Package
58 {
59 public:
60 static Module *rootModule;
61 static DsymbolTable *modules; // symbol table of all modules
62 static Modules amodules; // array of all modules
63 static Dsymbols deferred; // deferred Dsymbol's needing semantic() run on them
64 static Dsymbols deferred2; // deferred Dsymbol's needing semantic2() run on them
65 static Dsymbols deferred3; // deferred Dsymbol's needing semantic3() run on them
66
67 static void _init();
68
69 static AggregateDeclaration *moduleinfo;
70
71
72 DString arg; // original argument name
73 ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
74 FileName srcfile; // input source file
75 FileName objfile; // output .obj file
76 FileName hdrfile; // 'header' file
77 FileName docfile; // output documentation file
78 DArray<unsigned char> src; // Raw content of the file
79 unsigned errors; // if any errors in file
80 unsigned numlines; // number of lines in source file
81 FileType filetype; // source file type
82 d_bool hasAlwaysInlines; // contains references to functions that must be inlined
83 d_bool isPackageFile; // if it is a package.d
84 Edition edition; // language edition that this module is compiled with
85 Package *pkg; // if isPackageFile is true, the Package that contains this package.d
86 Strings contentImportedFiles; // array of files whose content was imported
87 int needmoduleinfo;
88 ThreeState selfimports;
89 ThreeState rootimports;
90 void* tagSymTab; // ImportC: tag symbols that conflict with other symbols used as the index
91 OutBuffer defines; // collect all the #define lines here
92 bool selfImports(); // returns true if module imports itself
93
94 bool rootImports(); // returns true if module imports root module
95
96 Identifier *searchCacheIdent;
97 Dsymbol *searchCacheSymbol; // cached value of search
98 SearchOptFlags searchCacheFlags; // cached flags
99 d_bool insearch;
100
101 // module from command line we're imported from,
102 // i.e. a module that will be taken all the
103 // way to an object file
104 Module *importedFrom;
105
106 Dsymbols *decldefs; // top level declarations for this Module
107
108 Modules aimports; // all imported modules
109
110 Identifiers *debugids; // debug identifiers
111 Identifiers *debugidsNot; // forward referenced debug identifiers
112
113 Identifiers *versionids; // version identifiers
114 Identifiers *versionidsNot; // forward referenced version identifiers
115
116 MacroTable macrotable; // document comment macros
117 Escape *escapetable; // document comment escapes
118
119 size_t nameoffset; // offset of module name from start of ModuleInfo
120 size_t namelen; // length of module name in characters
121
122 static Module* create(const char *arg, Identifier *ident, int doDocComment, int doHdrGen);
123 static const char *find(const char *filename);
124 static Module *load(Loc loc, Identifiers *packages, Identifier *ident);
125
126 const char *kind() const override;
127 bool read(Loc loc); // read file, returns 'true' if succeed, 'false' otherwise.
128 Module *parse(); // syntactic parse
129 int needModuleInfo();
130 bool isPackageAccessible(Package *p, Visibility visibility, SearchOptFlags flags = (SearchOptFlags)SearchOpt::all) override;
131 Dsymbol *symtabInsert(Dsymbol *s) override;
132 static void runDeferredSemantic();
133 static void runDeferredSemantic2();
134 static void runDeferredSemantic3();
135 int imports(Module *m);
136
137 bool isRoot() { return this->importedFrom == this; }
138 // true if the module source file is directly
139 // listed in command line.
140 bool isCoreModule(Identifier *ident);
141
142 // Back end
143
144 int doppelganger; // sub-module
145 Symbol *cov; // private uint[] __coverage;
146 DArray<unsigned> covb; // bit array of valid code line numbers
147
148 Symbol *sictor; // module order independent constructor
149 Symbol *sctor; // module constructor
150 Symbol *sdtor; // module destructor
151 Symbol *ssharedctor; // module shared constructor
152 Symbol *sshareddtor; // module shared destructor
153 Symbol *stest; // module unit test
154
155 Symbol *sfilename; // symbol for filename
156
157 void *ctfe_cov; // stores coverage information from ctfe
158
159 void accept(Visitor *v) override { v->visit(this); }
160 };
161
162
163 struct ModuleDeclaration
164 {
165 Loc loc;
166 Identifier *id;
167 DArray<Identifier*> packages; // array of Identifier's representing packages
168 d_bool isdeprecated; // if it is a deprecated module
169 Expression *msg;
170
171 const char *toChars() const;
172 };
173
174 namespace dmd
175 {
176 void getLocalClasses(Module* mod, Array<ClassDeclaration* >& aclasses);
177 FuncDeclaration *findGetMembers(ScopeDsymbol *dsym);
178 }