aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-01-03 18:04:46 +0000
committerDouglas Gregor <dgregor@apple.com>2012-01-03 18:04:46 +0000
commit5948ae1021122164b22f74353bb7fe325a64f616 (patch)
treeb10150c1440f0bd3dd2e91cb551228dd191ed587 /lib
parent674949fe3fdd796fc643f0e7660cb973da1dd383 (diff)
Introduce a non-uglified syntax for module imports in Objective-C:
@import identifier [. identifier]* ; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147452 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/Decl.cpp16
-rw-r--r--lib/AST/DeclPrinter.cpp2
-rw-r--r--lib/Lex/Preprocessor.cpp16
-rw-r--r--lib/Parse/ParseObjc.cpp2
-rw-r--r--lib/Parse/Parser.cpp9
-rw-r--r--lib/Sema/SemaDecl.cpp8
6 files changed, 32 insertions, 21 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index c1ed43709e..31a9b3b292 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -2755,10 +2755,10 @@ static unsigned getNumModuleIdentifiers(Module *Mod) {
return Result;
}
-ImportDecl::ImportDecl(DeclContext *DC, SourceLocation ImportLoc,
+ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
Module *Imported,
ArrayRef<SourceLocation> IdentifierLocs)
- : Decl(Import, DC, ImportLoc), ImportedAndComplete(Imported, true),
+ : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, true),
NextLocalImport()
{
assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size());
@@ -2767,28 +2767,28 @@ ImportDecl::ImportDecl(DeclContext *DC, SourceLocation ImportLoc,
IdentifierLocs.size() * sizeof(SourceLocation));
}
-ImportDecl::ImportDecl(DeclContext *DC, SourceLocation ImportLoc,
+ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
Module *Imported, SourceLocation EndLoc)
- : Decl(Import, DC, ImportLoc), ImportedAndComplete(Imported, false),
+ : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, false),
NextLocalImport()
{
*reinterpret_cast<SourceLocation *>(this + 1) = EndLoc;
}
ImportDecl *ImportDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation ImportLoc, Module *Imported,
+ SourceLocation StartLoc, Module *Imported,
ArrayRef<SourceLocation> IdentifierLocs) {
void *Mem = C.Allocate(sizeof(ImportDecl) +
IdentifierLocs.size() * sizeof(SourceLocation));
- return new (Mem) ImportDecl(DC, ImportLoc, Imported, IdentifierLocs);
+ return new (Mem) ImportDecl(DC, StartLoc, Imported, IdentifierLocs);
}
ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC,
- SourceLocation ImportLoc,
+ SourceLocation StartLoc,
Module *Imported,
SourceLocation EndLoc) {
void *Mem = C.Allocate(sizeof(ImportDecl) + sizeof(SourceLocation));
- ImportDecl *Import = new (Mem) ImportDecl(DC, ImportLoc, Imported, EndLoc);
+ ImportDecl *Import = new (Mem) ImportDecl(DC, StartLoc, Imported, EndLoc);
Import->setImplicit();
return Import;
}
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index 73dac3b73e..33ddd5af41 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -647,7 +647,7 @@ void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
}
void DeclPrinter::VisitImportDecl(ImportDecl *D) {
- Out << "__import_module__ " << D->getImportedModule()->getFullModuleName()
+ Out << "@import " << D->getImportedModule()->getFullModuleName()
<< ";\n";
}
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 08d8b920d1..8722be93d3 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -548,9 +548,10 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
if (II.isExtensionToken() && !DisableMacroExpansion)
Diag(Identifier, diag::ext_token_used);
- // If this is the '__import_module__' keyword, note that the next token
- // indicates a module name.
- if (II.getTokenID() == tok::kw___import_module__ &&
+ // If this is the '__import_module__' or 'import' keyword, note that the next
+ // token indicates a module name.
+ if ((II.getTokenID() == tok::kw___import_module__ ||
+ II.getObjCKeywordID() == tok::objc_import) &&
!InMacroArgs && !DisableMacroExpansion) {
ModuleImportLoc = Identifier.getLocation();
ModuleImportPath.clear();
@@ -559,7 +560,8 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
}
}
-/// \brief Lex a token following the __import_module__ keyword.
+/// \brief Lex a token following the __import_module__ or 'import' keyword.
+///
void Preprocessor::LexAfterModuleImport(Token &Result) {
// Figure out what kind of lexer we actually have.
if (CurLexer)
@@ -578,8 +580,12 @@ void Preprocessor::LexAfterModuleImport(Token &Result) {
//
// __import_module__ identifier (. identifier)*
//
+ // or
+ //
+ // import identifier (. identifier)*
+ //
// indicates a module import directive. We already saw the __import_module__
- // keyword, so now we're looking for the identifiers.
+ // or 'import' keyword, so now we're looking for the identifiers.
if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) {
// We expected to see an identifier here, and we did; continue handling
// identifiers.
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 8260d188a3..a2994a3312 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -66,6 +66,8 @@ Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() {
case tok::objc_dynamic:
SingleDecl = ParseObjCPropertyDynamic(AtLoc);
break;
+ case tok::objc_import:
+ return ParseModuleImport(AtLoc);
default:
Diag(AtLoc, diag::err_unexpected_at);
SkipUntil(tok::semi);
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 6914b8e018..b96ff388db 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -668,7 +668,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
return DeclGroupPtrTy();
case tok::kw___import_module__:
- return ParseModuleImport();
+ return ParseModuleImport(SourceLocation());
default:
dont_know:
@@ -1569,8 +1569,9 @@ void Parser::ParseMicrosoftIfExistsExternalDeclaration() {
Braces.consumeClose();
}
-Parser::DeclGroupPtrTy Parser::ParseModuleImport() {
- assert(Tok.is(tok::kw___import_module__) &&
+Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) {
+ assert((Tok.is(tok::kw___import_module__) ||
+ Tok.isObjCAtKeyword(tok::objc_import)) &&
"Improper start to module import");
SourceLocation ImportLoc = ConsumeToken();
@@ -1596,7 +1597,7 @@ Parser::DeclGroupPtrTy Parser::ParseModuleImport() {
break;
} while (true);
- DeclResult Import = Actions.ActOnModuleImport(ImportLoc, Path);
+ DeclResult Import = Actions.ActOnModuleImport(AtLoc, ImportLoc, Path);
ExpectAndConsumeSemi(diag::err_module_expected_semi);
if (Import.isInvalid())
return DeclGroupPtrTy();
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index a1ccf946d6..9583ab6327 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -9896,7 +9896,9 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr,
return New;
}
-DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) {
+DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc,
+ SourceLocation ImportLoc,
+ ModuleIdPath Path) {
Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path,
Module::AllVisible,
/*IsIncludeDirective=*/false);
@@ -9917,8 +9919,8 @@ DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
ImportDecl *Import = ImportDecl::Create(Context,
Context.getTranslationUnitDecl(),
- ImportLoc, Mod,
- IdentifierLocs);
+ AtLoc.isValid()? AtLoc : ImportLoc,
+ Mod, IdentifierLocs);
Context.getTranslationUnitDecl()->addDecl(Import);
return Import;
}