handleTagSymbols

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

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

sc Scope

context

s Dsymbol

symbol to add to symbol table

s2 Dsymbol

existing declaration

sds ScopeDsymbol

symbol table

Return Value

Type: Dsymbol

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

Meta