1.1 --- a/src/compiler/NameBinding.cpp Sat Jan 12 16:13:46 2013 -0800
1.2 +++ b/src/compiler/NameBinding.cpp Sat Jan 12 16:26:09 2013 -0800
1.3 @@ -887,7 +887,18 @@
1.4 } else {
1.5 Local<Module> module(zone_, Module::cast(importable));
1.6 if (!module->globals())
1.7 - importAllFromTranslationUnit(node, module, module->translationUnit());
1.8 + importAllFromTranslationUnit(node, module->translationUnit());
1.9 + else
1.10 + assert(false);
1.11 + }
1.12 + } else {
1.13 + Local<Importable> importable(zone_, unit_->module()->getImportAt(node->importIndex()));
1.14 + if (importable->isPackage()) {
1.15 + assert(false);
1.16 + } else {
1.17 + Local<Module> module(zone_, Module::cast(importable));
1.18 + if (!module->globals())
1.19 + importFromTranslationUnit(node, module->translationUnit());
1.20 else
1.21 assert(false);
1.22 }
1.23 @@ -895,25 +906,53 @@
1.24 }
1.25
1.26 private:
1.27 - void importAllFromTranslationUnit(ImportStatement *node, Handle<Module> module, TranslationUnit *other) {
1.28 + bool importFrom(ImportStatement *node, Symbol *import) {
1.29 + assert(import->type());
1.30 +
1.31 + // Check for duplicate import names.
1.32 + if (unit_->importScope()->localLookup(import->name())) {
1.33 + cc_.reportError(node->pos(), Message_DuplicateImport, import->name()->chars());
1.34 + return false;
1.35 + }
1.36 +
1.37 + ImplicitSymbol *sym = new (pool_) ImplicitSymbol(unit_->importScope(),
1.38 + import->name(),
1.39 + node->pos(),
1.40 + import->type(),
1.41 + node->importIndex());
1.42 + if (!unit_->importScope()->addSymbol(sym))
1.43 + return false;
1.44 +
1.45 + return true;
1.46 + }
1.47 +
1.48 + void importFromTranslationUnit(ImportStatement *node, TranslationUnit *other) {
1.49 + assert(!other->failed());
1.50 +
1.51 + for (size_t i = 0; i < node->names()->length(); i++) {
1.52 + Handle<String> name = *node->names()->at(i);
1.53 +
1.54 + // See if the name exists in the other translation unit.
1.55 + Symbol *import = other->globalScope()->findExported(name);
1.56 + if (!import) {
1.57 + FixedArray *path = unit_->module()->importPathAt(node->importIndex());
1.58 + cc_.reportError(node->pos(), Message_NotFoundInImportable,
1.59 + name->chars(),
1.60 + String::cast(path->at(path->length() - 1))->chars());
1.61 + return;
1.62 + }
1.63 +
1.64 + if (!importFrom(node, import))
1.65 + return;
1.66 + }
1.67 + }
1.68 +
1.69 + void importAllFromTranslationUnit(ImportStatement *node, TranslationUnit *other) {
1.70 assert(!other->failed());
1.71
1.72 for (size_t i = 0; i < other->globalScope()->exported()->length(); i++) {
1.73 Symbol *import = other->globalScope()->exported()->at(i);
1.74 - assert(import->type());
1.75 -
1.76 - // Check for duplicate import names.
1.77 - if (unit_->importScope()->localLookup(import->name())) {
1.78 - cc_.reportError(node->pos(), Message_DuplicateImport, import->name()->chars());
1.79 - return;
1.80 - }
1.81 -
1.82 - ImplicitSymbol *sym = new (pool_) ImplicitSymbol(unit_->importScope(),
1.83 - import->name(),
1.84 - node->pos(),
1.85 - import->type(),
1.86 - node->importIndex());
1.87 - if (!unit_->importScope()->addSymbol(sym))
1.88 + if (!importFrom(node, import))
1.89 return;
1.90 }
1.91 }