add SearchOpt to enum type (#15889)

This commit is contained in:
Walter Bright 2023-12-07 22:56:03 -08:00 committed by GitHub
parent 4b78331358
commit d6ec250275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 116 additions and 109 deletions

View file

@ -97,6 +97,6 @@ struct ASTCodegen
alias isExpression = dmd.dtemplate.isExpression; alias isExpression = dmd.dtemplate.isExpression;
alias isTuple = dmd.dtemplate.isTuple; alias isTuple = dmd.dtemplate.isTuple;
alias IgnoreErrors = dmd.dsymbol.IgnoreErrors; alias SearchOpt = dmd.dsymbol.SearchOpt;
alias PASS = dmd.dsymbol.PASS; alias PASS = dmd.dsymbol.PASS;
} }

View file

@ -614,7 +614,7 @@ extern (C++) class ClassDeclaration : AggregateDeclaration
final bool isFuncHidden(FuncDeclaration fd) final bool isFuncHidden(FuncDeclaration fd)
{ {
//printf("ClassDeclaration.isFuncHidden(class = %s, fd = %s)\n", toChars(), fd.toPrettyChars()); //printf("ClassDeclaration.isFuncHidden(class = %s, fd = %s)\n", toChars(), fd.toPrettyChars());
Dsymbol s = this.search(Loc.initial, fd.ident, IgnoreAmbiguous | IgnoreErrors); Dsymbol s = this.search(Loc.initial, fd.ident, SearchOpt.ignoreAmbiguous | SearchOpt.ignoreErrors);
if (!s) if (!s)
{ {
//printf("not found\n"); //printf("not found\n");

View file

@ -401,7 +401,7 @@ extern (C++) final class Module : Package
Identifier searchCacheIdent; Identifier searchCacheIdent;
Dsymbol searchCacheSymbol; // cached value of search Dsymbol searchCacheSymbol; // cached value of search
int searchCacheFlags; // cached flags SearchOptFlags searchCacheFlags; // cached flags
bool insearch; bool insearch;
/** /**
@ -1021,14 +1021,14 @@ extern (C++) final class Module : Package
} }
} }
override bool isPackageAccessible(Package p, Visibility visibility, int flags = 0) override bool isPackageAccessible(Package p, Visibility visibility, SearchOptFlags flags = SearchOpt.all)
{ {
if (insearch) // don't follow import cycles if (insearch) // don't follow import cycles
return false; return false;
insearch = true; insearch = true;
scope (exit) scope (exit)
insearch = false; insearch = false;
if (flags & IgnorePrivateImports) if (flags & SearchOpt.ignorePrivateImports)
visibility = Visibility(Visibility.Kind.public_); // only consider public imports visibility = Visibility(Visibility.Kind.public_); // only consider public imports
return super.isPackageAccessible(p, visibility); return super.isPackageAccessible(p, visibility);
} }

View file

@ -3638,11 +3638,11 @@ struct MarkdownLinkReferences
{ {
auto loc = Loc(); auto loc = Loc();
Dsymbol pscopesym; Dsymbol pscopesym;
auto symbol = _scope.search(loc, id, pscopesym, IgnoreErrors); auto symbol = _scope.search(loc, id, pscopesym, SearchOpt.ignoreErrors);
for (size_t i = 1; symbol && i < ids.length; ++i) for (size_t i = 1; symbol && i < ids.length; ++i)
{ {
id = Identifier.lookup(ids[i].ptr, ids[i].length); id = Identifier.lookup(ids[i].ptr, ids[i].length);
symbol = id !is null ? symbol.search(loc, id, IgnoreErrors) : null; symbol = id !is null ? symbol.search(loc, id, SearchOpt.ignoreErrors) : null;
} }
if (symbol) if (symbol)
link = MarkdownLink(createHref(symbol), null, name, symbol); link = MarkdownLink(createHref(symbol), null, name, symbol);

View file

@ -350,7 +350,7 @@ extern (C++) struct Scope
* Returns: * Returns:
* symbol if found, null if not * symbol if found, null if not
*/ */
extern (C++) Dsymbol search(const ref Loc loc, Identifier ident, out Dsymbol pscopesym, int flags = IgnoreNone) extern (C++) Dsymbol search(const ref Loc loc, Identifier ident, out Dsymbol pscopesym, SearchOptFlags flags = SearchOpt.all)
{ {
version (LOGSEARCH) version (LOGSEARCH)
{ {
@ -371,7 +371,7 @@ extern (C++) struct Scope
} }
// This function is called only for unqualified lookup // This function is called only for unqualified lookup
assert(!(flags & (SearchLocalsOnly | SearchImportsOnly))); assert(!(flags & (SearchOpt.localsOnly | SearchOpt.importsOnly)));
/* If ident is "start at module scope", only look at module scope /* If ident is "start at module scope", only look at module scope
*/ */
@ -393,7 +393,7 @@ extern (C++) struct Scope
return null; return null;
} }
Dsymbol checkAliasThis(AggregateDeclaration ad, Identifier ident, int flags, Expression* exp) Dsymbol checkAliasThis(AggregateDeclaration ad, Identifier ident, SearchOptFlags flags, Expression* exp)
{ {
import dmd.mtype; import dmd.mtype;
if (!ad || !ad.aliasthis) if (!ad || !ad.aliasthis)
@ -457,7 +457,7 @@ extern (C++) struct Scope
return s; return s;
} }
Dsymbol searchScopes(int flags) Dsymbol searchScopes(SearchOptFlags flags)
{ {
for (Scope* sc = &this; sc; sc = sc.enclosing) for (Scope* sc = &this; sc; sc = sc.enclosing)
{ {
@ -467,13 +467,13 @@ extern (C++) struct Scope
//printf("\tlooking in scopesym '%s', kind = '%s', flags = x%x\n", sc.scopesym.toChars(), sc.scopesym.kind(), flags); //printf("\tlooking in scopesym '%s', kind = '%s', flags = x%x\n", sc.scopesym.toChars(), sc.scopesym.kind(), flags);
if (sc.scopesym.isModule()) if (sc.scopesym.isModule())
flags |= SearchUnqualifiedModule; // tell Module.search() that SearchLocalsOnly is to be obeyed flags |= SearchOpt.unqualifiedModule; // tell Module.search() that SearchOpt.localsOnly is to be obeyed
else if (sc.flags & SCOPE.Cfile && sc.scopesym.isStructDeclaration()) else if (sc.flags & SCOPE.Cfile && sc.scopesym.isStructDeclaration())
continue; // C doesn't have struct scope continue; // C doesn't have struct scope
if (Dsymbol s = sc.scopesym.search(loc, ident, flags)) if (Dsymbol s = sc.scopesym.search(loc, ident, flags))
{ {
if (flags & TagNameSpace) if (flags & SearchOpt.tagNameSpace)
{ {
// ImportC: if symbol is not a tag, look for it in tag table // ImportC: if symbol is not a tag, look for it in tag table
if (!s.isScopeDsymbol()) if (!s.isScopeDsymbol())
@ -510,15 +510,15 @@ extern (C++) struct Scope
} }
if (this.flags & SCOPE.ignoresymbolvisibility) if (this.flags & SCOPE.ignoresymbolvisibility)
flags |= IgnoreSymbolVisibility; flags |= SearchOpt.ignoreVisibility;
// First look in local scopes // First look in local scopes
Dsymbol s = searchScopes(flags | SearchLocalsOnly); Dsymbol s = searchScopes(flags | SearchOpt.localsOnly);
version (LOGSEARCH) if (s) printMsg("-Scope.search() found local", s); version (LOGSEARCH) if (s) printMsg("-Scope.search() found local", s);
if (!s) if (!s)
{ {
// Second look in imported modules // Second look in imported modules
s = searchScopes(flags | SearchImportsOnly); s = searchScopes(flags | SearchOpt.importsOnly);
version (LOGSEARCH) if (s) printMsg("-Scope.search() found import", s); version (LOGSEARCH) if (s) printMsg("-Scope.search() found import", s);
} }
return s; return s;
@ -552,7 +552,7 @@ extern (C++) struct Scope
Scope* sc = &this; Scope* sc = &this;
Module.clearCache(); Module.clearCache();
Dsymbol scopesym; Dsymbol scopesym;
Dsymbol s = sc.search(Loc.initial, id, scopesym, IgnoreErrors); Dsymbol s = sc.search(Loc.initial, id, scopesym, SearchOpt.ignoreErrors);
if (!s) if (!s)
return null; return null;
@ -578,7 +578,7 @@ extern (C++) struct Scope
Dsymbol scopesym; Dsymbol scopesym;
// search for exact name first // search for exact name first
if (auto s = search(Loc.initial, ident, scopesym, IgnoreErrors)) if (auto s = search(Loc.initial, ident, scopesym, SearchOpt.ignoreErrors))
return s; return s;
return speller!scope_search_fp(ident.toString()); return speller!scope_search_fp(ident.toString());
} }

View file

@ -203,20 +203,21 @@ enum PASS : ubyte
} }
// Search options // Search options
enum : int alias SearchOptFlags = uint;
enum SearchOpt : SearchOptFlags
{ {
IgnoreNone = 0x00, // default all = 0x00, // search for all symbols
IgnorePrivateImports = 0x01, // don't search private imports ignorePrivateImports = 0x01, // don't search private imports
IgnoreErrors = 0x02, // don't give error messages ignoreErrors = 0x02, // don't give error messages
IgnoreAmbiguous = 0x04, // return NULL if ambiguous ignoreAmbiguous = 0x04, // return NULL if ambiguous
SearchLocalsOnly = 0x08, // only look at locals (don't search imports) localsOnly = 0x08, // only look at locals (don't search imports)
SearchImportsOnly = 0x10, // only look in imports importsOnly = 0x10, // only look in imports
SearchUnqualifiedModule = 0x20, // the module scope search is unqualified, unqualifiedModule = 0x20, // the module scope search is unqualified,
// meaning don't search imports in that scope, // meaning don't search imports in that scope,
// because qualified module searches search // because qualified module searches search
// their imports // their imports
IgnoreSymbolVisibility = 0x80, // also find private and package protected symbols tagNameSpace = 0x40, // search ImportC tag symbol table
TagNameSpace = 0x100, // search ImportC tag symbol table ignoreVisibility = 0x80, // also find private and package protected symbols
} }
/*********************************************************** /***********************************************************
@ -1263,7 +1264,7 @@ public:
(*pary)[p.tag] = true; (*pary)[p.tag] = true;
} }
bool isPackageAccessible(Package p, Visibility visibility, int flags = 0) nothrow bool isPackageAccessible(Package p, Visibility visibility, SearchOptFlags flags = SearchOpt.all) nothrow
{ {
if (p.tag < accessiblePackages.length && accessiblePackages[p.tag] || if (p.tag < accessiblePackages.length && accessiblePackages[p.tag] ||
visibility.kind == Visibility.Kind.private_ && p.tag < privateAccessiblePackages.length && privateAccessiblePackages[p.tag]) visibility.kind == Visibility.Kind.private_ && p.tag < privateAccessiblePackages.length && privateAccessiblePackages[p.tag])
@ -1272,7 +1273,7 @@ public:
{ {
// only search visible scopes && imported modules should ignore private imports // only search visible scopes && imported modules should ignore private imports
if (visibility.kind <= visibilities[i] && if (visibility.kind <= visibilities[i] &&
ss.isScopeDsymbol.isPackageAccessible(p, visibility, IgnorePrivateImports)) ss.isScopeDsymbol.isPackageAccessible(p, visibility, SearchOpt.ignorePrivateImports))
return true; return true;
} }
return false; return false;

View file

@ -147,20 +147,21 @@ enum
/* Flags for symbol search /* Flags for symbol search
*/ */
enum typedef uint SearchOptFlags;
enum class SearchOpt : SearchOptFlags
{ {
IgnoreNone = 0x00, // default all = 0x00, // default
IgnorePrivateImports = 0x01, // don't search private imports ignorePrivateImports = 0x01, // don't search private imports
IgnoreErrors = 0x02, // don't give error messages ignoreErrors = 0x02, // don't give error messages
IgnoreAmbiguous = 0x04, // return NULL if ambiguous ignoreAmbiguous = 0x04, // return NULL if ambiguous
SearchLocalsOnly = 0x08, // only look at locals (don't search imports) localsOnly = 0x08, // only look at locals (don't search imports)
SearchImportsOnly = 0x10, // only look in imports importsOnly = 0x10, // only look in imports
SearchUnqualifiedModule = 0x20, // the module scope search is unqualified, unqualifiedModule = 0x20, // the module scope search is unqualified,
// meaning don't search imports in that scope, // meaning don't search imports in that scope,
// because qualified module searches search // because qualified module searches search
// their imports // their imports
IgnoreSymbolVisibility = 0x80, // also find private and package protected symbols tagNameSpace = 0x40, // search ImportC tag symbol table
TagNameSpace = 0x100, // search ImportC tag symbol table ignoreVisibility = 0x80, // also find private and package protected symbols
}; };
struct FieldState struct FieldState
@ -336,7 +337,7 @@ private:
public: public:
ScopeDsymbol *syntaxCopy(Dsymbol *s) override; ScopeDsymbol *syntaxCopy(Dsymbol *s) override;
virtual void importScope(Dsymbol *s, Visibility visibility); virtual void importScope(Dsymbol *s, Visibility visibility);
virtual bool isPackageAccessible(Package *p, Visibility visibility, int flags = 0); virtual bool isPackageAccessible(Package *p, Visibility visibility, SearchOptFlags flags = (SearchOptFlags)SearchOpt::all);
bool isforwardRef() override final; bool isforwardRef() override final;
static void multiplyDefined(const Loc &loc, Dsymbol *s1, Dsymbol *s2); static void multiplyDefined(const Loc &loc, Dsymbol *s1, Dsymbol *s2);
const char *kind() const override; const char *kind() const override;
@ -427,6 +428,6 @@ public:
}; };
void addMember(Dsymbol *dsym, Scope *sc, ScopeDsymbol *sds); void addMember(Dsymbol *dsym, Scope *sc, ScopeDsymbol *sds);
Dsymbol *search(Dsymbol *d, const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); Dsymbol *search(Dsymbol *d, const Loc &loc, Identifier *ident, SearchOptFlags flags = (SearchOptFlags)SearchOpt::localsOnly);
bool checkDeprecated(Dsymbol *d, const Loc &loc, Scope *sc); bool checkDeprecated(Dsymbol *d, const Loc &loc, Scope *sc);
void setScope(Dsymbol *d, Scope *sc); void setScope(Dsymbol *d, Scope *sc);

View file

@ -1617,7 +1617,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
{ {
AliasDeclaration ad = imp.aliasdecls[i]; AliasDeclaration ad = imp.aliasdecls[i];
//printf("\tImport %s alias %s = %s, scope = %p\n", toPrettyChars(), aliases[i].toChars(), names[i].toChars(), ad._scope); //printf("\tImport %s alias %s = %s, scope = %p\n", toPrettyChars(), aliases[i].toChars(), names[i].toChars(), ad._scope);
Dsymbol sym = imp.mod.search(imp.loc, imp.names[i], IgnorePrivateImports); Dsymbol sym = imp.mod.search(imp.loc, imp.names[i], SearchOpt.ignorePrivateImports);
if (sym) if (sym)
{ {
import dmd.access : symbolIsVisible; import dmd.access : symbolIsVisible;
@ -7957,11 +7957,11 @@ void checkPrintfScanfSignature(FuncDeclaration funcdecl, TypeFunction f, Scope*
* d = dsymbol where ident is searched for * d = dsymbol where ident is searched for
* loc = location to print for error messages * loc = location to print for error messages
* ident = identifier to search for * ident = identifier to search for
* flags = IgnoreXXXX * flags = search options
* Returns: * Returns:
* null if not found * null if not found
*/ */
extern(C++) Dsymbol search(Dsymbol d, const ref Loc loc, Identifier ident, int flags = IgnoreNone) extern(C++) Dsymbol search(Dsymbol d, const ref Loc loc, Identifier ident, SearchOptFlags flags = SearchOpt.all)
{ {
scope v = new SearchVisitor(loc, ident, flags); scope v = new SearchVisitor(loc, ident, flags);
d.accept(v); d.accept(v);
@ -7986,13 +7986,13 @@ Dsymbol search_correct(Dsymbol d, Identifier ident)
cost = 0; // all the same cost cost = 0; // all the same cost
Dsymbol s = d; Dsymbol s = d;
Module.clearCache(); Module.clearCache();
return s.search(Loc.initial, id, IgnoreErrors); return s.search(Loc.initial, id, SearchOpt.ignoreErrors);
} }
if (global.gag) if (global.gag)
return null; // don't do it for speculative compiles; too time consuming return null; // don't do it for speculative compiles; too time consuming
// search for exact name first // search for exact name first
if (auto s = d.search(Loc.initial, ident, IgnoreErrors)) if (auto s = d.search(Loc.initial, ident, SearchOpt.ignoreErrors))
return s; return s;
import dmd.root.speller : speller; import dmd.root.speller : speller;
@ -8005,10 +8005,10 @@ private extern(C++) class SearchVisitor : Visitor
const Loc loc; const Loc loc;
Identifier ident; Identifier ident;
int flags; SearchOptFlags flags;
Dsymbol result; Dsymbol result;
this(const ref Loc loc, Identifier ident, int flags) this(const ref Loc loc, Identifier ident, SearchOptFlags flags)
{ {
this.loc = loc; this.loc = loc;
this.ident = ident; this.ident = ident;
@ -8032,7 +8032,7 @@ private extern(C++) class SearchVisitor : Visitor
//if (strcmp(ident.toChars(),"c") == 0) *(char*)0=0; //if (strcmp(ident.toChars(),"c") == 0) *(char*)0=0;
// Look in symbols declared in this module // Look in symbols declared in this module
if (sds.symtab && !(flags & SearchImportsOnly)) if (sds.symtab && !(flags & SearchOpt.importsOnly))
{ {
//printf(" look in locals\n"); //printf(" look in locals\n");
auto s1 = sds.symtab.lookup(ident); auto s1 = sds.symtab.lookup(ident);
@ -8055,30 +8055,30 @@ private extern(C++) class SearchVisitor : Visitor
for (size_t i = 0; i < sds.importedScopes.length; i++) for (size_t i = 0; i < sds.importedScopes.length; i++)
{ {
// If private import, don't search it // If private import, don't search it
if ((flags & IgnorePrivateImports) && sds.visibilities[i] == Visibility.Kind.private_) if ((flags & SearchOpt.ignorePrivateImports) && sds.visibilities[i] == Visibility.Kind.private_)
continue; continue;
int sflags = flags & (IgnoreErrors | IgnoreAmbiguous); // remember these in recursive searches SearchOptFlags sflags = flags & (SearchOpt.ignoreErrors | SearchOpt.ignoreAmbiguous); // remember these in recursive searches
Dsymbol ss = (*sds.importedScopes)[i]; Dsymbol ss = (*sds.importedScopes)[i];
//printf("\tscanning import '%s', visibilities = %d, isModule = %p, isImport = %p\n", ss.toChars(), visibilities[i], ss.isModule(), ss.isImport()); //printf("\tscanning import '%s', visibilities = %d, isModule = %p, isImport = %p\n", ss.toChars(), visibilities[i], ss.isModule(), ss.isImport());
if (ss.isModule()) if (ss.isModule())
{ {
if (flags & SearchLocalsOnly) if (flags & SearchOpt.localsOnly)
continue; continue;
} }
else // mixin template else // mixin template
{ {
if (flags & SearchImportsOnly) if (flags & SearchOpt.importsOnly)
continue; continue;
sflags |= SearchLocalsOnly; sflags |= SearchOpt.localsOnly;
} }
/* Don't find private members if ss is a module /* Don't find private members if ss is a module
*/ */
Dsymbol s2 = ss.search(loc, ident, sflags | (ss.isModule() ? IgnorePrivateImports : IgnoreNone)); Dsymbol s2 = ss.search(loc, ident, sflags | (ss.isModule() ? SearchOpt.ignorePrivateImports : SearchOpt.all));
import dmd.access : symbolIsVisible; import dmd.access : symbolIsVisible;
if (!s2 || !(flags & IgnoreSymbolVisibility) && !symbolIsVisible(sds, s2)) if (!s2 || !(flags & SearchOpt.ignoreVisibility) && !symbolIsVisible(sds, s2))
continue; continue;
if (!s) if (!s)
{ {
@ -8149,7 +8149,7 @@ private extern(C++) class SearchVisitor : Visitor
} }
} }
if (flags & IgnoreAmbiguous) // if return NULL on ambiguity if (flags & SearchOpt.ignoreAmbiguous) // if return NULL on ambiguity
return setResult(null); return setResult(null);
/* If two imports from C import files, pick first one, as C has global name space /* If two imports from C import files, pick first one, as C has global name space
@ -8157,7 +8157,7 @@ private extern(C++) class SearchVisitor : Visitor
if (s.isCsymbol() && s2.isCsymbol()) if (s.isCsymbol() && s2.isCsymbol())
continue; continue;
if (!(flags & IgnoreErrors)) if (!(flags & SearchOpt.ignoreErrors))
ScopeDsymbol.multiplyDefined(loc, s, s2); ScopeDsymbol.multiplyDefined(loc, s, s2);
break; break;
} }
@ -8184,7 +8184,7 @@ private extern(C++) class SearchVisitor : Visitor
override void visit(WithScopeSymbol ws) override void visit(WithScopeSymbol ws)
{ {
//printf("WithScopeSymbol.search(%s)\n", ident.toChars()); //printf("WithScopeSymbol.search(%s)\n", ident.toChars());
if (flags & SearchImportsOnly) if (flags & SearchOpt.importsOnly)
return setResult(null); return setResult(null);
// Acts as proxy to the with class declaration // Acts as proxy to the with class declaration
Dsymbol s = null; Dsymbol s = null;
@ -8425,7 +8425,7 @@ private extern(C++) class SearchVisitor : Visitor
if (!ns.members || !ns.symtab) // opaque or semantic() is not yet called if (!ns.members || !ns.symtab) // opaque or semantic() is not yet called
{ {
if (!(flags & IgnoreErrors)) if (!(flags & SearchOpt.ignoreErrors))
.error(loc, "%s `%s` is forward referenced when looking for `%s`", ns.kind, ns.toPrettyChars, ident.toChars()); .error(loc, "%s `%s` is forward referenced when looking for `%s`", ns.kind, ns.toPrettyChars, ident.toChars());
return setResult(null); return setResult(null);
} }
@ -8448,7 +8448,7 @@ private extern(C++) class SearchVisitor : Visitor
override void visit(Package pkg) override void visit(Package pkg)
{ {
//printf("%s Package.search('%s', flags = x%x)\n", pkg.toChars(), ident.toChars(), flags); //printf("%s Package.search('%s', flags = x%x)\n", pkg.toChars(), ident.toChars(), flags);
flags &= ~SearchLocalsOnly; // searching an import is always transitive flags &= ~cast(int)SearchOpt.localsOnly; // searching an import is always transitive
if (!pkg.isModule() && pkg.mod) if (!pkg.isModule() && pkg.mod)
{ {
// Prefer full package name. // Prefer full package name.
@ -8475,8 +8475,8 @@ private extern(C++) class SearchVisitor : Visitor
/* Qualified module searches always search their imports, /* Qualified module searches always search their imports,
* even if SearchLocalsOnly * even if SearchLocalsOnly
*/ */
if (!(flags & SearchUnqualifiedModule)) if (!(flags & SearchOpt.unqualifiedModule))
flags &= ~(SearchUnqualifiedModule | SearchLocalsOnly); flags &= ~(SearchOpt.unqualifiedModule | SearchOpt.localsOnly);
if (m.searchCacheIdent == ident && m.searchCacheFlags == flags) if (m.searchCacheIdent == ident && m.searchCacheFlags == flags)
{ {
@ -8525,7 +8525,7 @@ private extern(C++) class SearchVisitor : Visitor
if (!sd.members || !sd.symtab) // opaque or semantic() is not yet called if (!sd.members || !sd.symtab) // opaque or semantic() is not yet called
{ {
// .stringof is always defined (but may be hidden by some other symbol) // .stringof is always defined (but may be hidden by some other symbol)
if(ident != Id.stringof && !(flags & IgnoreErrors) && sd.semanticRun < PASS.semanticdone) if(ident != Id.stringof && !(flags & SearchOpt.ignoreErrors) && sd.semanticRun < PASS.semanticdone)
.error(loc, "%s `%s` is forward referenced when looking for `%s`", sd.kind, sd.toPrettyChars, ident.toChars()); .error(loc, "%s `%s` is forward referenced when looking for `%s`", sd.kind, sd.toPrettyChars, ident.toChars());
return setResult(null); return setResult(null);
} }
@ -8551,7 +8551,7 @@ private extern(C++) class SearchVisitor : Visitor
if (!cd.members || !cd.symtab) // opaque or addMember is not yet done if (!cd.members || !cd.symtab) // opaque or addMember is not yet done
{ {
// .stringof is always defined (but may be hidden by some other symbol) // .stringof is always defined (but may be hidden by some other symbol)
if (ident != Id.stringof && !(flags & IgnoreErrors) && cd.semanticRun < PASS.semanticdone) if (ident != Id.stringof && !(flags & SearchOpt.ignoreErrors) && cd.semanticRun < PASS.semanticdone)
cd.classError("%s `%s` is forward referenced when looking for `%s`", ident.toChars()); cd.classError("%s `%s` is forward referenced when looking for `%s`", ident.toChars());
//*(char*)0=0; //*(char*)0=0;
return setResult(null); return setResult(null);
@ -8561,7 +8561,7 @@ private extern(C++) class SearchVisitor : Visitor
auto s = result; auto s = result;
// don't search imports of base classes // don't search imports of base classes
if (flags & SearchImportsOnly) if (flags & SearchOpt.importsOnly)
return setResult(s); return setResult(s);
if (s) if (s)
@ -8586,7 +8586,7 @@ private extern(C++) class SearchVisitor : Visitor
continue; continue;
else if (s == cd) // happens if s is nested in this and derives from this else if (s == cd) // happens if s is nested in this and derives from this
s = null; s = null;
else if (!(flags & IgnoreSymbolVisibility) && !(s.visible().kind == Visibility.Kind.protected_) && !symbolIsVisible(cd, s)) else if (!(flags & SearchOpt.ignoreVisibility) && !(s.visible().kind == Visibility.Kind.protected_) && !symbolIsVisible(cd, s))
s = null; s = null;
else else
break; break;

View file

@ -3284,7 +3284,7 @@ ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t) @safe
*/ */
ASTCodegen.Dsymbol findMember(ASTCodegen.Dsymbol sym, Identifier name) ASTCodegen.Dsymbol findMember(ASTCodegen.Dsymbol sym, Identifier name)
{ {
if (auto mem = sym.search(Loc.initial, name, ASTCodegen.IgnoreErrors)) if (auto mem = sym.search(Loc.initial, name, ASTCodegen.SearchOpt.ignoreErrors))
return mem; return mem;
// search doesn't work for declarations inside of uninstantiated // search doesn't work for declarations inside of uninstantiated

View file

@ -875,7 +875,7 @@ private Expression searchUFCS(Scope* sc, UnaExp ue, Identifier ident)
Loc loc = ue.loc; Loc loc = ue.loc;
// TODO: merge with Scope.search.searchScopes() // TODO: merge with Scope.search.searchScopes()
Dsymbol searchScopes(int flags) Dsymbol searchScopes(SearchOptFlags flags)
{ {
Dsymbol s = null; Dsymbol s = null;
for (Scope* scx = sc; scx; scx = scx.enclosing) for (Scope* scx = sc; scx; scx = scx.enclosing)
@ -883,7 +883,7 @@ private Expression searchUFCS(Scope* sc, UnaExp ue, Identifier ident)
if (!scx.scopesym) if (!scx.scopesym)
continue; continue;
if (scx.scopesym.isModule()) if (scx.scopesym.isModule())
flags |= SearchUnqualifiedModule; // tell Module.search() that SearchLocalsOnly is to be obeyed flags |= SearchOpt.unqualifiedModule; // tell Module.search() that SearchOpt.localsOnly is to be obeyed
s = scx.scopesym.search(loc, ident, flags); s = scx.scopesym.search(loc, ident, flags);
if (s) if (s)
{ {
@ -910,18 +910,18 @@ private Expression searchUFCS(Scope* sc, UnaExp ue, Identifier ident)
return s; return s;
} }
int flags = 0; SearchOptFlags flags = SearchOpt.all;
Dsymbol s; Dsymbol s;
if (sc.flags & SCOPE.ignoresymbolvisibility) if (sc.flags & SCOPE.ignoresymbolvisibility)
flags |= IgnoreSymbolVisibility; flags |= SearchOpt.ignoreVisibility;
// First look in local scopes // First look in local scopes
s = searchScopes(flags | SearchLocalsOnly); s = searchScopes(flags | SearchOpt.localsOnly);
if (!s) if (!s)
{ {
// Second look in imported modules // Second look in imported modules
s = searchScopes(flags | SearchImportsOnly); s = searchScopes(flags | SearchOpt.importsOnly);
} }
if (!s) if (!s)
@ -14211,15 +14211,15 @@ Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag)
if (auto ie = eright.isScopeExp()) // also used for template alias's if (auto ie = eright.isScopeExp()) // also used for template alias's
{ {
auto flags = SearchLocalsOnly; SearchOptFlags flags = SearchOpt.localsOnly;
/* Disable access to another module's private imports. /* Disable access to another module's private imports.
* The check for 'is sds our current module' is because * The check for 'is sds our current module' is because
* the current module should have access to its own imports. * the current module should have access to its own imports.
*/ */
if (ie.sds.isModule() && ie.sds != sc._module) if (ie.sds.isModule() && ie.sds != sc._module)
flags |= IgnorePrivateImports; flags |= SearchOpt.ignorePrivateImports;
if (sc.flags & SCOPE.ignoresymbolvisibility) if (sc.flags & SCOPE.ignoresymbolvisibility)
flags |= IgnoreSymbolVisibility; flags |= SearchOpt.ignoreVisibility;
Dsymbol s = ie.sds.search(exp.loc, exp.ident, flags); Dsymbol s = ie.sds.search(exp.loc, exp.ident, flags);
/* Check for visibility before resolving aliases because public /* Check for visibility before resolving aliases because public
* aliases to private symbols are public. * aliases to private symbols are public.

View file

@ -624,7 +624,7 @@ private:
public: public:
ScopeDsymbol* syntaxCopy(Dsymbol* s) override; ScopeDsymbol* syntaxCopy(Dsymbol* s) override;
virtual void importScope(Dsymbol* s, Visibility visibility); virtual void importScope(Dsymbol* s, Visibility visibility);
virtual bool isPackageAccessible(Package* p, Visibility visibility, int32_t flags = 0); virtual bool isPackageAccessible(Package* p, Visibility visibility, uint32_t flags = 0u);
bool isforwardRef() final override; bool isforwardRef() final override;
static void multiplyDefined(const Loc& loc, Dsymbol* s1, Dsymbol* s2); static void multiplyDefined(const Loc& loc, Dsymbol* s1, Dsymbol* s2);
const char* kind() const override; const char* kind() const override;
@ -2064,19 +2064,21 @@ struct FieldState final
{} {}
}; };
enum enum class SearchOpt : uint32_t
{ {
IgnoreNone = 0, all = 0u,
IgnorePrivateImports = 1, ignorePrivateImports = 1u,
IgnoreErrors = 2, ignoreErrors = 2u,
IgnoreAmbiguous = 4, ignoreAmbiguous = 4u,
SearchLocalsOnly = 8, localsOnly = 8u,
SearchImportsOnly = 16, importsOnly = 16u,
SearchUnqualifiedModule = 32, unqualifiedModule = 32u,
IgnoreSymbolVisibility = 128, tagNameSpace = 64u,
TagNameSpace = 256, ignoreVisibility = 128u,
}; };
typedef uint32_t SearchOptFlags;
enum : int32_t { IDX_NOTFOUND = 305419896 }; enum : int32_t { IDX_NOTFOUND = 305419896 };
struct TemplateInstanceBox final struct TemplateInstanceBox final
@ -4784,6 +4786,8 @@ struct ASTCodegen final
using OverloadSet = ::OverloadSet; using OverloadSet = ::OverloadSet;
using PASS = ::PASS; using PASS = ::PASS;
using ScopeDsymbol = ::ScopeDsymbol; using ScopeDsymbol = ::ScopeDsymbol;
using SearchOpt = ::SearchOpt;
using SearchOptFlags = ::SearchOptFlags;
using Ungag = ::Ungag; using Ungag = ::Ungag;
using Visibility = ::Visibility; using Visibility = ::Visibility;
using WithScopeSymbol = ::WithScopeSymbol; using WithScopeSymbol = ::WithScopeSymbol;
@ -5058,6 +5062,7 @@ struct ASTCodegen final
typedef Dsymbol* Dsymbol; typedef Dsymbol* Dsymbol;
typedef Array<Dsymbol* > Dsymbols; typedef Array<Dsymbol* > Dsymbols;
typedef Visibility Visibility; typedef Visibility Visibility;
typedef SearchOpt SearchOpt;
typedef PASS PASS; typedef PASS PASS;
ASTCodegen() ASTCodegen()
{ {
@ -6229,7 +6234,7 @@ public:
bool rootImports(); bool rootImports();
Identifier* searchCacheIdent; Identifier* searchCacheIdent;
Dsymbol* searchCacheSymbol; Dsymbol* searchCacheSymbol;
int32_t searchCacheFlags; uint32_t searchCacheFlags;
bool insearch; bool insearch;
Module* importedFrom; Module* importedFrom;
Array<Dsymbol* >* decldefs; Array<Dsymbol* >* decldefs;
@ -6253,7 +6258,7 @@ public:
void importAll(Scope* prevsc) override; void importAll(Scope* prevsc) override;
int32_t needModuleInfo(); int32_t needModuleInfo();
void checkImportDeprecation(const Loc& loc, Scope* sc); void checkImportDeprecation(const Loc& loc, Scope* sc);
bool isPackageAccessible(Package* p, Visibility visibility, int32_t flags = 0) override; bool isPackageAccessible(Package* p, Visibility visibility, uint32_t flags = 0u) override;
Dsymbol* symtabInsert(Dsymbol* s) override; Dsymbol* symtabInsert(Dsymbol* s) override;
static void runDeferredSemantic(); static void runDeferredSemantic();
static void runDeferredSemantic2(); static void runDeferredSemantic2();
@ -6342,7 +6347,7 @@ struct Scope final
void* anchorCounts; void* anchorCounts;
Identifier* prevAnchor; Identifier* prevAnchor;
AliasDeclaration* aliasAsg; AliasDeclaration* aliasAsg;
Dsymbol* search(const Loc& loc, Identifier* ident, Dsymbol*& pscopesym, int32_t flags = 0); Dsymbol* search(const Loc& loc, Identifier* ident, Dsymbol*& pscopesym, uint32_t flags = 0u);
Scope() : Scope() :
enclosing(), enclosing(),
_module(), _module(),
@ -6563,7 +6568,7 @@ extern void dsymbolSemantic(Dsymbol* dsym, Scope* sc);
extern void addMember(Dsymbol* dsym, Scope* sc, ScopeDsymbol* sds); extern void addMember(Dsymbol* dsym, Scope* sc, ScopeDsymbol* sds);
extern Dsymbol* search(Dsymbol* d, const Loc& loc, Identifier* ident, int32_t flags = 0); extern Dsymbol* search(Dsymbol* d, const Loc& loc, Identifier* ident, uint32_t flags = 0u);
extern void setScope(Dsymbol* d, Scope* sc); extern void setScope(Dsymbol* d, Scope* sc);

View file

@ -88,7 +88,7 @@ public:
Identifier *searchCacheIdent; Identifier *searchCacheIdent;
Dsymbol *searchCacheSymbol; // cached value of search Dsymbol *searchCacheSymbol; // cached value of search
int searchCacheFlags; // cached flags SearchOptFlags searchCacheFlags; // cached flags
d_bool insearch; d_bool insearch;
// module from command line we're imported from, // module from command line we're imported from,
@ -123,7 +123,7 @@ public:
Module *parse(); // syntactic parse Module *parse(); // syntactic parse
void importAll(Scope *sc) override; void importAll(Scope *sc) override;
int needModuleInfo(); int needModuleInfo();
bool isPackageAccessible(Package *p, Visibility visibility, int flags = 0) override; bool isPackageAccessible(Package *p, Visibility visibility, SearchOptFlags flags = (SearchOptFlags)SearchOpt::all) override;
Dsymbol *symtabInsert(Dsymbol *s) override; Dsymbol *symtabInsert(Dsymbol *s) override;
static void runDeferredSemantic(); static void runDeferredSemantic();
static void runDeferredSemantic2(); static void runDeferredSemantic2();

View file

@ -130,5 +130,5 @@ struct Scope
AliasDeclaration *aliasAsg; // if set, then aliasAsg is being assigned a new value, AliasDeclaration *aliasAsg; // if set, then aliasAsg is being assigned a new value,
// do not set wasRead for it // do not set wasRead for it
Dsymbol *search(const Loc &loc, Identifier *ident, Dsymbol **pscopesym, int flags = IgnoreNone); Dsymbol *search(const Loc &loc, Identifier *ident, Dsymbol **pscopesym, SearchOptFlags flags = (SearchOptFlags)SearchOpt::all);
}; };

View file

@ -228,7 +228,7 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb
Type t = s.getType(); // type symbol, type alias, or type tuple? Type t = s.getType(); // type symbol, type alias, or type tuple?
uint errorsave = global.errors; uint errorsave = global.errors;
int flags = t is null ? SearchLocalsOnly : IgnorePrivateImports; SearchOptFlags flags = t is null ? SearchOpt.localsOnly : SearchOpt.ignorePrivateImports;
Dsymbol sm = s.searchX(loc, sc, id, flags); Dsymbol sm = s.searchX(loc, sc, id, flags);
if (sm) if (sm)
@ -380,12 +380,12 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb
* loc = location to print the error messages * loc = location to print the error messages
* sc = the scope where the symbol is located * sc = the scope where the symbol is located
* id = the id of the symbol * id = the id of the symbol
* flags = the search flags which can be `SearchLocalsOnly` or `IgnorePrivateImports` * flags = the search flags which can be `SearchLocalsOnly` or `SearchOpt.ignorePrivateImports`
* *
* Returns: * Returns:
* symbol found, NULL if not * symbol found, NULL if not
*/ */
private Dsymbol searchX(Dsymbol dsym, const ref Loc loc, Scope* sc, RootObject id, int flags) private Dsymbol searchX(Dsymbol dsym, const ref Loc loc, Scope* sc, RootObject id, SearchOptFlags flags)
{ {
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars()); //printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
Dsymbol s = dsym.toAlias(); Dsymbol s = dsym.toAlias();
@ -1878,7 +1878,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc)
/* look for pre-existing declaration /* look for pre-existing declaration
*/ */
Dsymbol scopesym; Dsymbol scopesym;
auto s = sc2.search(mtype.loc, mtype.id, scopesym, IgnoreErrors | TagNameSpace); auto s = sc2.search(mtype.loc, mtype.id, scopesym, SearchOpt.ignoreErrors | SearchOpt.tagNameSpace);
if (!s || s.isModule()) if (!s || s.isModule())
{ {
// no pre-existing declaration, so declare it // no pre-existing declaration, so declare it
@ -3794,8 +3794,8 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag
return e; return e;
} }
immutable flags = sc.flags & SCOPE.ignoresymbolvisibility ? IgnoreSymbolVisibility : 0; immutable flags = sc.flags & SCOPE.ignoresymbolvisibility ? SearchOpt.ignoreVisibility : 0;
s = mt.sym.search(e.loc, ident, flags | IgnorePrivateImports); s = mt.sym.search(e.loc, ident, flags | SearchOpt.ignorePrivateImports);
L1: L1:
if (!s) if (!s)
{ {
@ -4074,8 +4074,8 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag
return e; return e;
} }
int flags = sc.flags & SCOPE.ignoresymbolvisibility ? IgnoreSymbolVisibility : 0; SearchOptFlags flags = sc.flags & SCOPE.ignoresymbolvisibility ? SearchOpt.ignoreVisibility : SearchOpt.all;
s = mt.sym.search(e.loc, ident, flags | IgnorePrivateImports); s = mt.sym.search(e.loc, ident, flags | SearchOpt.ignorePrivateImports);
L1: L1:
if (!s) if (!s)
@ -4723,7 +4723,7 @@ Type getComplexLibraryType(const ref Loc loc, Scope* sc, TY ty)
return *pt; return *pt;
} }
Dsymbol s = mConfig.searchX(Loc.initial, sc, id, IgnorePrivateImports); Dsymbol s = mConfig.searchX(Loc.initial, sc, id, SearchOpt.ignorePrivateImports);
if (!s) if (!s)
{ {
error(loc, "`%s` not found in core.stdc.config", id.toChars()); error(loc, "`%s` not found in core.stdc.config", id.toChars());

View file

@ -175,7 +175,7 @@ Dsymbol findSymbol(Dsymbol sym, string name, bool allowMissing = false)
const oldErrors = global.errors; const oldErrors = global.errors;
Identifier id = Identifier.idPool(name); Identifier id = Identifier.idPool(name);
Dsymbol found = sym.search(Loc.initial, id, IgnoreErrors); Dsymbol found = sym.search(Loc.initial, id, SearchOpt.ignoreErrors);
assert(global.errors == oldErrors, "Searching " ~ name ~ " caused errors!"); assert(global.errors == oldErrors, "Searching " ~ name ~ " caused errors!");
assert(allowMissing || found, name ~ " not found!"); assert(allowMissing || found, name ~ " not found!");