dmd.dsymbol
The base class for a D symbol, which can be a module, variable, function, enum, etc.
License
Source: dsymbol.d
Documentation: https://dlang.org/phobos/dmd_dsymbol.html
-
Declaration
intforeachDsymbol(Dsymbols*symbols, scope int delegate(Dsymbol)dg);Calls
dg(Dsymbol *sym) for each Dsymbol. Ifdgreturns !=0, stops and returns that value else returns 0.Parameters
Dsymbols*symbolsDsymbols
int delegate(Dsymbol)dgdelegate to call for each Dsymbol
Return Value
last value returned by
dg()See Also
-
Declaration
voidforeachDsymbol(Dsymbols*symbols, scope void delegate(Dsymbol)dg);Calls
dg(Dsymbol *sym) for each Dsymbol.Parameters
Dsymbols*symbolsDsymbols
void delegate(Dsymbol)dgdelegate to call for each Dsymbol
See Also
-
Declaration
structFieldState;Struct/Class/Union field state. Used for transitory information when setting field offsets, such as bit fields.
-
Declaration
uintoffset;byte
offsetfor next field -
Declaration
uintfieldOffset;byte offset for the start of the bit field
-
Declaration
uintfieldSize;byte size of field
-
Declaration
uintfieldAlign;byte alignment of field
-
Declaration
uintbitOffset;bit offset for field
-
Declaration
boolinFlight;bit field is in flight
-
-
Declaration
classDsymbol: dmd.ast_node.ASTNode;-
Declaration
ushortlocalNum;perturb mangled name to avoid collisions with those in FuncDeclaration.localsymtab
-
Declaration
final ModulegetModule();Determine which Module a Dsymbol is in.
-
Declaration
final boolisCsymbol();Does this Dsymbol come from a C file?
Return Value
trueif it does -
Declaration
final ModulegetAccessModule();Determine which Module a Dsymbol is in, as far as access rights go.
-
Declaration
final inout inout(Dsymbol)pastMixin();returns the enclosing symbol if this is a template mixin.pastMixinDiscussion
pastMixinAndNspacedoes likewise, additionally skipping over Nspaces that are mangleOnly.
See alsoparent,toParentandtoParent2. -
Declaration
final inout inout(Dsymbol)toParent();
final inout inout(Dsymbol)toParent2();
final inout inout(Dsymbol)toParentDecl();
final inout inout(Dsymbol)toParentLocal();parentfield returns a lexically enclosing scope symbol this is a member of.Discussion
returns a logically enclosing scope symbol this is a member of. It skips over TemplateMixin's.toParent()
returns an enclosing scope symbol this is living at runtime. It skips over both TemplateInstance's and TemplateMixin's. It's used when looking for the 'this' pointer of the enclosing function/class.toParent2()
similar totoParentDecl()but always follows the template declaration scope instead of the instantiation scope.toParent2()
similar totoParentLocal()but follows the instantiation scope if a template declaration is non-local i.e. global or static.toParentDecl()Examples
module mod; template Foo(alias a) { mixin Bar!(); } mixin template Bar() { public { // VisibilityDeclaration void baz() { a = 2; } } } void test() { int v = 1; alias foo = Foo!(v); foo.baz(); assert(v == 2); } // s == FuncDeclaration('mod.test.Foo!().Bar!().baz()') // s.parent == TemplateMixin('mod.test.Foo!().Bar!()') // s.toParent() == TemplateInstance('mod.test.Foo!()') // s.toParent2() == FuncDeclaration('mod.test') // s.toParentDecl() == Module('mod') // s.toParentLocal() == FuncDeclaration('mod.test')
-
Declaration
final DsymboltoParentP(Dsymbolp1, Dsymbolp2= null);Returns the declaration scope scope of
thisunless any of the symbolsorp1resides in its enclosing instantiation scope then the latter is returned.p2 -
Declaration
final boolfollowInstantiationContext(Dsymbolp1, Dsymbolp2= null);Returns
trueif any of the symbolsorp1resides in the enclosing instantiation scope ofp2this. -
Declaration
static Dsymbols*arraySyntaxCopy(Dsymbols*a);Do syntax copy of an array of Dsymbol's.
-
Declaration
DsymboltoAlias();If this symbol is really an alias for another, return that other. If needed, semantic() is invoked due to resolve forward reference.
-
Declaration
DsymboltoAlias2();Resolve recursive tuple expansion in eponymous template.
-
Declaration
voidsetScope(Scope*sc);Set scope for future semantic analysis so we can deal better with forward references.
-
Declaration
Dsymbolsearch(const ref Locloc, Identifierident, intflags= IgnoreNone);Search for
identas member of s.Parameters
Locloclocation to print for error messages
Identifieridentidentifier to
searchforintflagsIgnoreXXXX
Return Value
nullif not found -
Declaration
final DsymbolsearchX(const ref Locloc, Scope*sc, RootObjectid, intflags);Search for identifier
idas a member ofthis.may be a template instance.idParameters
Locloclocation to print the error messages
Scope*scthe scope where the symbol is located
RootObjectidthe
idof the symbolintflagsthe search
flagswhich can beSearchLocalsOnlyorIgnorePrivateImportsReturn Value
symbol found, NULL if not
-
Declaration
uinteger_tsize(const ref Locloc);Return Value
SIZE_INVALID when the
sizecannot be determined -
Declaration
final inout inout(AggregateDeclaration)isMember();Returns an AggregateDeclaration when toParent() is that.
-
Declaration
final inout inout(AggregateDeclaration)isMember2();Returns an AggregateDeclaration when toParent2() is that.
-
Declaration
final inout inout(AggregateDeclaration)isMemberDecl();Returns an AggregateDeclaration when toParentDecl() is that.
-
Declaration
final inout inout(AggregateDeclaration)isMemberLocal();Returns an AggregateDeclaration when toParentLocal() is that.
-
Declaration
pure nothrow @nogc @safe Visibilityvisible(); -
Declaration
DsymbolsyntaxCopy(Dsymbols);Copy the syntax. Used for template instantiations. If
sis NULL, allocate the new object, otherwise fill it in. -
Declaration
booloneMember(Dsymbol*ps, Identifierident);Determine if this symbol is only one.
Return Value
false, *ps= NULL: There are 2 or more symbolstrue, *ps= NULL: There are zero symbolstrue, *ps= symbol: The one and only one symbol -
Declaration
static booloneMembers(Dsymbols*members, Dsymbol*ps, Identifierident);Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
-
Declaration
boolhasPointers();Is Dsymbol a variable that contains pointers?
-
Declaration
voidaddComment(const(char)*comment);Add documentation
commentto Dsymbol. Ignore NULL comments. -
Declaration
final const(char)*comment();get documentation
commentfor this Dsymbol -
Declaration
final UnitTestDeclarationddocUnittest();Get ddoc unittest associated with this symbol. (only use this with ddoc)
Return Value
ddoc unittest,
nullif none -
Declaration
final voidddocUnittest(UnitTestDeclarationutd);Set ddoc unittest associated with this symbol.
-
Declaration
final boolinNonRoot();Returns
trueif this symbol is defined in a non-root module without instantiation. -
Declaration
static voiddeinitialize();Deinitializes the global state of the compiler.
Discussion
This can be used to restore the state set by
_initto its original state. -
Declaration
voidaccept(Visitorv);
-
-
Declaration
classScopeDsymbol: dmd.dsymbol.Dsymbol;Dsymbol that generates a scope
-
Declaration
Dsymbolsearch(const ref Locloc, Identifierident, intflags= SearchLocalsOnly);This function is #1 on the list of functions that eat cpu time. Be very, very careful about slowing it down.
-
Declaration
final pure nothrow @nogc @safe Dsymbols*getImportedScopes();Return Value
the symbols whose members have been imported, i.e. imported modules and template mixins.
See Also
importScope
-
Declaration
final pure nothrow @nogc @safe Visibility.Kind[]getImportVisibilities();Return Value
the array of visibilities associated with each imported scope. The length of the array matches the imported scopes array.
See Also
getImportedScopes
-
Declaration
final FuncDeclarationfindGetMembers();Look for member of the form: const(MemberInfo)[] getMembers(string); Returns NULL if not found
-
Declaration
nothrow DsymbolsymtabInsert(Dsymbols);Insert Dsymbol in table.
Parameters
Dsymbolssymbol to add
Return Value
nullif already in table,if inserteds -
Declaration
nothrow DsymbolsymtabLookup(Dsymbols, Identifierid);Look up identifier in symbol table.
Parameters
Dsymbolssymbol
Identifierididentifier to look up
Return Value
Dsymbol if found,
nullif not -
Declaration
boolhasStaticCtorOrDtor();Return
trueif any of the members are static ctors or static dtors, or if any members have members that are. -
Declaration
static int_foreach(Scope*sc, Dsymbols*members, scope ForeachDgdg, size_t*pn= null);Expands attribute declarations in
membersin depth first order. Callsdg(size_t symidx, Dsymbol *sym) for each member. Ifdgreturns !=0, stops and returns that value else returns 0. Use this function to avoid the O(N + N^2/2) complexity of calculating dim and calling N times getNth.Return Value
last value returned by
dg()
-
-
Declaration
classWithScopeSymbol: dmd.dsymbol.ScopeDsymbol;With statement scope
-
Declaration
classArrayScopeSymbol: dmd.dsymbol.ScopeDsymbol;Array Index/Slice scope
-
Declaration
Dsymbolsearch(const ref Locloc, Identifierident, intflags= IgnoreNone);This override is used to solve
$
-
-
Declaration
classOverloadSet: dmd.dsymbol.Dsymbol;Overload Sets
-
Declaration
classForwardingScopeDsymbol: dmd.dsymbol.ScopeDsymbol;Forwarding ScopeDsymbol. Used by ForwardingAttribDeclaration and ForwardingScopeDeclaration to forward symbol insertions to another scope. See
dmd.attrib.ForwardingAttribDeclarationfor more details.-
Declaration
nothrow DsymbolsymtabLookup(Dsymbols, Identifierid);This override handles the following two cases: static foreach (i, i; [0]) { ... } and static foreach (i; [0]) { enum i = 2; }
-
-
Declaration
classExpressionDsymbol: dmd.dsymbol.Dsymbol;Class that holds an expression in a Dsymbol wrapper. This is not an AST node, but a class used to pass an expression as a function parameter of type Dsymbol.
-
Declaration
classAliasAssign: dmd.dsymbol.Dsymbol;Encapsulate assigning to an alias:
identifier = type;identifier = symbol;whereidentifieris an AliasDeclaration in scope.-
Declaration
Identifierident;Dsymbol's
identwill benull, as this class is anonymous -
Declaration
Typetype;replace previous RHS of AliasDeclaration with
type -
Declaration
Dsymbolaliassym;replace previous RHS of AliasDeclaration with
aliassym -
Declaration
nothrow this(const ref Locloc, Identifierident, Typetype, Dsymbolaliassym);only one of
typeandaliassymcan be !=null
-
-
Declaration
classDsymbolTable: dmd.root.rootobject.RootObject;Table of Dsymbol's
-
Declaration
nothrow Dsymbollookup(const Identifierident);Look up Identifier in symbol table
Parameters
Identifieridentidentifer to look up
Return Value
Dsymbol if found,
nullif not -
Declaration
nothrow voidupdate(Dsymbols);Replace existing symbol in symbol table with
. If it'ssnot there, add it.Parameters
Dsymbolsreplacement symbol with same identifier
-
Declaration
nothrow Dsymbolinsert(Dsymbols);Insert Dsymbol in table.
Parameters
Dsymbolssymbol to add
Return Value
nullif already in table,if inserteds -
Declaration
nothrow Dsymbolinsert(const Identifierident, Dsymbols);Insert Dsymbol in table.
Parameters
Identifieridentidentifier to serve as index
Dsymbolssymbol to add
Return Value
nullif already in table,if inserteds -
Declaration
const pure nothrow size_tlength();Return Value
number of symbols in symbol table
-
-
Declaration
DsymbolhandleTagSymbols(ref Scopesc, Dsymbols, Dsymbols2, ScopeDsymbolsds);ImportC tag symbols sit in a parallel symbol table, so that this C code works:
But there are relatively few such tag symbols, so that would be a waste of memory and complexity. An additional problem is we'd like the D side to find the tag symbols with ordinary lookup, not lookup in both tables, if the tag symbol is not conflicting with an ordinary symbol. The solution is to put the tag symbols that conflict into an associative array, indexed by the address of the ordinary symbol that conflicts with it. C has no modules, so this associative array is tagSymTab[] in ModuleDeclaration. A side effect of our approach is that D code cannot access a tag symbol that is hidden by an ordinary symbol. This is more of a theoretical problem, as nobody has mentioned it when importing C headers. If someone wants to do it, too bad so sad. Change the C code. This function fixes up the symbol table when faced with adding a new symbolstruct S { a; }; int S; struct S s;
when there is an existing symbolswith the same name. C also allows forward and prototype declarations of tag symbols, this function merges those.s2Parameters
Scopesccontext
Dsymbolssymbol to add to symbol table
Dsymbols2existing declaration
ScopeDsymbolsdssymbol table
Return Value
if
sands2are successfully put in symbol table then return the merged symbol,nullif they conflict -
Declaration
DsymbolhandleSymbolRedeclarations(ref Scopesc, Dsymbols, Dsymbols2, ScopeDsymbolsds);ImportC allows redeclarations of C variables, functions and typedefs. extern int x; int x = 3; and: extern void f(); void f() { } Attempt to merge them.
Parameters
Scopesccontext
Dsymbolssymbol to add to symbol table
Dsymbols2existing declaration
ScopeDsymbolsdssymbol table
Return Value
if
sands2are successfully put in symbol table then return the merged symbol,nullif they conflict