Merge dmd upstream 6243fa6d2
[official-gcc.git] / gcc / d / dmd / module.h
blobd8fb020175e9191967817ab6c5bcb781217bd037
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/dlang/dmd/blob/master/src/dmd/module.h
9 */
11 #pragma once
13 #include "root/root.h"
14 #include "dsymbol.h"
16 class ClassDeclaration;
17 struct ModuleDeclaration;
18 struct Macro;
19 struct Escape;
20 class VarDeclaration;
21 class Library;
23 enum PKG
25 PKGunknown, // not yet determined whether it's a package.d or not
26 PKGmodule, // already determined that's an actual package.d
27 PKGpackage // already determined that's an actual package
30 class Package : public ScopeDsymbol
32 public:
33 PKG isPkgMod;
34 unsigned tag; // auto incremented tag, used to mask package tree in scopes
35 Module *mod; // != NULL if isPkgMod == PKGmodule
37 Package(Identifier *ident);
38 const char *kind() const;
40 static DsymbolTable *resolve(Identifiers *packages, Dsymbol **pparent, Package **ppkg);
42 Package *isPackage() { return this; }
44 bool isAncestorPackageOf(const Package * const pkg) const;
46 void semantic(Scope *);
47 Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly);
48 void accept(Visitor *v) { v->visit(this); }
50 Module *isPackageMod();
53 class Module : public Package
55 public:
56 static Module *rootModule;
57 static DsymbolTable *modules; // symbol table of all modules
58 static Modules amodules; // array of all modules
59 static Dsymbols deferred; // deferred Dsymbol's needing semantic() run on them
60 static Dsymbols deferred2; // deferred Dsymbol's needing semantic2() run on them
61 static Dsymbols deferred3; // deferred Dsymbol's needing semantic3() run on them
62 static unsigned dprogress; // progress resolving the deferred list
63 static void _init();
65 static AggregateDeclaration *moduleinfo;
68 const char *arg; // original argument name
69 ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
70 File *srcfile; // input source file
71 const char* srcfilePath; // the path prefix to the srcfile if it applies
72 File *objfile; // output .obj file
73 File *hdrfile; // 'header' file
74 File *docfile; // output documentation file
75 unsigned errors; // if any errors in file
76 unsigned numlines; // number of lines in source file
77 int isDocFile; // if it is a documentation input file, not D source
78 bool isPackageFile; // if it is a package.d
79 int needmoduleinfo;
81 int selfimports; // 0: don't know, 1: does not, 2: does
82 bool selfImports(); // returns true if module imports itself
84 int rootimports; // 0: don't know, 1: does not, 2: does
85 bool rootImports(); // returns true if module imports root module
87 int insearch;
88 Identifier *searchCacheIdent;
89 Dsymbol *searchCacheSymbol; // cached value of search
90 int searchCacheFlags; // cached flags
92 // module from command line we're imported from,
93 // i.e. a module that will be taken all the
94 // way to an object file
95 Module *importedFrom;
97 Dsymbols *decldefs; // top level declarations for this Module
99 Modules aimports; // all imported modules
101 unsigned debuglevel; // debug level
102 Strings *debugids; // debug identifiers
103 Strings *debugidsNot; // forward referenced debug identifiers
105 unsigned versionlevel; // version level
106 Strings *versionids; // version identifiers
107 Strings *versionidsNot; // forward referenced version identifiers
109 Macro *macrotable; // document comment macros
110 Escape *escapetable; // document comment escapes
112 size_t nameoffset; // offset of module name from start of ModuleInfo
113 size_t namelen; // length of module name in characters
115 Module(const char *arg, Identifier *ident, int doDocComment, int doHdrGen);
116 static Module* create(const char *arg, Identifier *ident, int doDocComment, int doHdrGen);
118 static Module *load(Loc loc, Identifiers *packages, Identifier *ident);
120 const char *kind() const;
121 File *setOutfile(const char *name, const char *dir, const char *arg, const char *ext);
122 void setDocfile();
123 bool read(Loc loc); // read file, returns 'true' if succeed, 'false' otherwise.
124 Module *parse(); // syntactic parse
125 void importAll(Scope *sc);
126 void semantic(Scope *); // semantic analysis
127 void semantic2(Scope *); // pass 2 semantic analysis
128 void semantic3(Scope *); // pass 3 semantic analysis
129 int needModuleInfo();
130 Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly);
131 bool isPackageAccessible(Package *p, Prot protection, int flags = 0);
132 Dsymbol *symtabInsert(Dsymbol *s);
133 void deleteObjFile();
134 static void addDeferredSemantic(Dsymbol *s);
135 static void addDeferredSemantic2(Dsymbol *s);
136 static void addDeferredSemantic3(Dsymbol *s);
137 static void runDeferredSemantic();
138 static void runDeferredSemantic2();
139 static void runDeferredSemantic3();
140 static void clearCache();
141 int imports(Module *m);
143 bool isRoot() { return this->importedFrom == this; }
144 // true if the module source file is directly
145 // listed in command line.
146 bool isCoreModule(Identifier *ident);
148 // Back end
150 int doppelganger; // sub-module
151 Symbol *cov; // private uint[] __coverage;
152 unsigned *covb; // bit array of valid code line numbers
154 Symbol *sictor; // module order independent constructor
155 Symbol *sctor; // module constructor
156 Symbol *sdtor; // module destructor
157 Symbol *ssharedctor; // module shared constructor
158 Symbol *sshareddtor; // module shared destructor
159 Symbol *stest; // module unit test
161 Symbol *sfilename; // symbol for filename
163 Module *isModule() { return this; }
164 void accept(Visitor *v) { v->visit(this); }
168 struct ModuleDeclaration
170 Loc loc;
171 Identifier *id;
172 Identifiers *packages; // array of Identifier's representing packages
173 bool isdeprecated; // if it is a deprecated module
174 Expression *msg;
176 ModuleDeclaration(Loc loc, Identifiers *packages, Identifier *id);
178 const char *toChars();