View source code
Display the source code in dmd/importc.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function dmd.importc.handleTagSymbols

ImportC tag symbols sit in a parallel symbol table, so that this C code works:

Dsymbol handleTagSymbols (
  ref dmd.dscope.Scope sc,
  Dsymbol s,
  Dsymbol s2,
  ScopeDsymbol sds
);
struct S { a; };
int S;
struct S s;

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 symbol s when there is an existing symbol s2 with the same name. C also allows forward and prototype declarations of tag symbols, this function merges those.

Parameters

NameDescription
sc context
s symbol to add to symbol table
s2 existing declaration
sds symbol table

Returns

if s and s2 are successfully put in symbol table then return the merged symbol, null if they conflict

Authors

Walter Bright

License

Boost License 1.0