void C2Sema::ActOnImport(const char* moduleName_, SourceLocation loc, Token& aliasTok, bool isLocal) { #ifdef SEMA_DEBUG std::cerr << COL_SEMA"SEMA: import " << moduleName_ << " at "; loc.dump(SourceMgr); std::cerr << ANSI_NORMAL"\n"; #endif std::string moduleName = moduleName_; // check if importing own module if (ast.getModuleName() == moduleName) { Diag(loc, diag::err_import_own_module) << moduleName_; return; } // check for duplicate import of module const ImportDecl* old = findModule(moduleName); if (old) { Diag(loc, diag::err_duplicate_import) << moduleName; Diag(old->getLocation(), diag::note_previous_import); return; } std::string name = moduleName; if (aliasTok.is(tok::identifier)) { name = aliasTok.getIdentifierInfo()->getNameStart(); // check if same as normal module name if (name == moduleName) { Diag(aliasTok.getLocation(), diag::err_alias_same_as_module); return; } } ImportDecl* U = new ImportDecl(name, loc, isLocal, moduleName, aliasTok.getLocation()); U->setType(typeContext.getModuleType(U)); ast.addImport(U); addSymbol(U); }
void C2Sema::ActOnModule(const char* name, SourceLocation loc) { #ifdef SEMA_DEBUG std::cerr << COL_SEMA << "SEMA: module " << name << " at "; loc.dump(SourceMgr); std::cerr << ANSI_NORMAL"\n"; #endif if (name[0] == '_' && name[1] == '_') { Diag(loc, diag::err_invalid_symbol_name) << name; return; } if (!islower(name[0]) && !ast.isInterface()) { Diag(loc, diag::err_module_casing); return; } if (strcmp(name, "c2") == 0) { Diag(loc, diag::err_module_c2); return; } if (strcmp(name, "main") == 0) { Diag(loc, diag::err_module_invalid_name) << name; return; } ast.setName(name, loc); ImportDecl* U = new ImportDecl(name, loc, true, name, SourceLocation()); U->setType(typeContext.getModuleType(U)); U->setUsed(); ast.addImport(U); addSymbol(U); }