Example #1
0
void
NameResolver::registerFunction(FunctionSymbol *sym)
{
  Scope *scope = sym->scope();
  assert(scope == globals_);

  Symbol *other = scope->localLookup(sym->name());
  if (!other) {
    scope->addSymbol(sym);
    return;
  }

  // If |other| is not a function, it's an error.
  FunctionSymbol *orig = other->asFunction();
  if (!orig) {
    reportRedeclaration(sym, other);
    return;
  }

  // If both have bodies, it's an error.
  FunctionStatement *sym_node = sym->node()->toFunctionStatement();
  FunctionStatement *orig_node = orig->node()->toFunctionStatement();
  if (sym_node->body() && orig_node->body()) {
    reportRedeclaration(sym, other);
    return;
  }

  // Build a shadow list, containing all symbols with this name.
  orig->addShadow(orig_node);
  orig->addShadow(sym_node);
  sym_node->setShadowed(orig);
}
Example #2
0
bool
NameResolver::registerSymbol(Symbol *sym)
{
  Scope *scope = getOrCreateScope();

  if (Symbol *other = scope->localLookup(sym->name())) {
    // Report, but allow errors to continue.
    reportRedeclaration(sym, other);
    return true;
  }

  return scope->addSymbol(sym);
}