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/module.h
15 struct ModuleDeclaration
;
21 void* internal
; // PIMPL
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
31 class Package
: public ScopeDsymbol
35 unsigned tag
; // auto incremented tag, used to mask package tree in scopes
36 Module
*mod
; // != NULL if isPkgMod == PKGmodule
38 const char *kind() const override
;
40 bool equals(const RootObject
* const o
) const override
;
42 Package
*isPackage() override final
{ return this; }
44 bool isAncestorPackageOf(const Package
* const pkg
) const;
46 void accept(Visitor
*v
) override
{ v
->visit(this); }
48 Module
*isPackageMod();
51 class Module final
: public Package
54 static Module
*rootModule
;
55 static DsymbolTable
*modules
; // symbol table of all modules
56 static Modules amodules
; // array of all modules
57 static Dsymbols deferred
; // deferred Dsymbol's needing semantic() run on them
58 static Dsymbols deferred2
; // deferred Dsymbol's needing semantic2() run on them
59 static Dsymbols deferred3
; // deferred Dsymbol's needing semantic3() run on them
63 static AggregateDeclaration
*moduleinfo
;
66 DString arg
; // original argument name
67 ModuleDeclaration
*md
; // if !NULL, the contents of the ModuleDeclaration declaration
68 FileName srcfile
; // input source file
69 FileName objfile
; // output .obj file
70 FileName hdrfile
; // 'header' file
71 FileName docfile
; // output documentation file
72 DArray
<unsigned char> src
; // Raw content of the file
73 unsigned errors
; // if any errors in file
74 unsigned numlines
; // number of lines in source file
75 FileType filetype
; // source file type
76 d_bool hasAlwaysInlines
; // contains references to functions that must be inlined
77 d_bool isPackageFile
; // if it is a package.d
78 Package
*pkg
; // if isPackageFile is true, the Package that contains this package.d
79 Strings contentImportedFiles
; // array of files whose content was imported
81 ThreeState selfimports
;
82 ThreeState rootimports
;
83 void* tagSymTab
; // ImportC: tag symbols that conflict with other symbols used as the index
84 OutBuffer defines
; // collect all the #define lines here
85 bool selfImports(); // returns true if module imports itself
87 bool rootImports(); // returns true if module imports root module
89 Identifier
*searchCacheIdent
;
90 Dsymbol
*searchCacheSymbol
; // cached value of search
91 SearchOptFlags searchCacheFlags
; // cached flags
94 // module from command line we're imported from,
95 // i.e. a module that will be taken all the
96 // way to an object file
99 Dsymbols
*decldefs
; // top level declarations for this Module
101 Modules aimports
; // all imported modules
103 unsigned debuglevel
; // debug level
104 Identifiers
*debugids
; // debug identifiers
105 Identifiers
*debugidsNot
; // forward referenced debug identifiers
107 unsigned versionlevel
; // version level
108 Identifiers
*versionids
; // version identifiers
109 Identifiers
*versionidsNot
; // forward referenced version identifiers
111 MacroTable macrotable
; // document comment macros
112 Escape
*escapetable
; // document comment escapes
114 size_t nameoffset
; // offset of module name from start of ModuleInfo
115 size_t namelen
; // length of module name in characters
117 static Module
* create(const char *arg
, Identifier
*ident
, int doDocComment
, int doHdrGen
);
118 static const char *find(const char *filename
);
119 static Module
*load(const Loc
&loc
, Identifiers
*packages
, Identifier
*ident
);
121 const char *kind() const override
;
122 bool read(const Loc
&loc
); // read file, returns 'true' if succeed, 'false' otherwise.
123 Module
*parse(); // syntactic parse
124 int needModuleInfo();
125 bool isPackageAccessible(Package
*p
, Visibility visibility
, SearchOptFlags flags
= (SearchOptFlags
)SearchOpt::all
) override
;
126 Dsymbol
*symtabInsert(Dsymbol
*s
) override
;
127 static void runDeferredSemantic();
128 static void runDeferredSemantic2();
129 static void runDeferredSemantic3();
130 int imports(Module
*m
);
132 bool isRoot() { return this->importedFrom
== this; }
133 // true if the module source file is directly
134 // listed in command line.
135 bool isCoreModule(Identifier
*ident
);
139 int doppelganger
; // sub-module
140 Symbol
*cov
; // private uint[] __coverage;
141 DArray
<unsigned> covb
; // bit array of valid code line numbers
143 Symbol
*sictor
; // module order independent constructor
144 Symbol
*sctor
; // module constructor
145 Symbol
*sdtor
; // module destructor
146 Symbol
*ssharedctor
; // module shared constructor
147 Symbol
*sshareddtor
; // module shared destructor
148 Symbol
*stest
; // module unit test
150 Symbol
*sfilename
; // symbol for filename
152 void *ctfe_cov
; // stores coverage information from ctfe
154 Module
*isModule() override
{ return this; }
155 void accept(Visitor
*v
) override
{ v
->visit(this); }
159 struct ModuleDeclaration
163 DArray
<Identifier
*> packages
; // array of Identifier's representing packages
164 d_bool isdeprecated
; // if it is a deprecated module
167 const char *toChars() const;
170 extern void getLocalClasses(Module
* mod
, Array
<ClassDeclaration
* >& aclasses
);
171 FuncDeclaration
*findGetMembers(ScopeDsymbol
*dsym
);