Remove 'externGlobals' member from Module; instead find them when needed via new SymbolTable::GetMatchingVariables method.

This commit is contained in:
Matt Pharr
2011-10-04 06:36:31 -07:00
parent fa5050d5c7
commit a6fc657b40
8 changed files with 44 additions and 29 deletions

View File

@@ -505,7 +505,6 @@ Module::AddGlobal(DeclSpecs *ds, Declarator *decl) {
// make sure it's a compile-time constant!
llvm::Constant *llvmInitializer = NULL;
if (ds->storageClass == SC_EXTERN || ds->storageClass == SC_EXTERN_C) {
externGlobals.push_back(decl->sym);
if (decl->initExpr != NULL)
Error(decl->pos, "Initializer can't be provided with \"extern\" "
"global variable \"%s\".", decl->sym->name.c_str());
@@ -1268,6 +1267,12 @@ lIsExternC(const Symbol *sym) {
}
static bool
lIsExternGlobal(const Symbol *sym) {
return sym->storageClass == SC_EXTERN || sym->storageClass == SC_EXTERN_C;
}
bool
Module::writeHeader(const char *fn) {
FILE *f = fopen(fn, "w");
@@ -1336,6 +1341,8 @@ Module::writeHeader(const char *fn) {
&exportedEnumTypes, &exportedVectorTypes);
// And do the same for the 'extern' globals
std::vector<Symbol *> externGlobals;
symbolTable->GetMatchingVariables(lIsExternGlobal, &externGlobals);
for (unsigned int i = 0; i < externGlobals.size(); ++i)
lGetExportedTypes(externGlobals[i]->type, &exportedStructTypes,
&exportedEnumTypes, &exportedVectorTypes);