///
/// An import declaration imports the named module (or submodule). For example:
/// \code
-/// __import_module__ std.vector;
+/// @import std.vector;
/// \endcode
///
/// Import declarations can also be implicitly generated from #include/#import
friend class ASTDeclReader;
friend class ASTContext;
- ImportDecl(DeclContext *DC, SourceLocation ImportLoc, Module *Imported,
+ ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
ArrayRef<SourceLocation> IdentifierLocs);
- ImportDecl(DeclContext *DC, SourceLocation ImportLoc, Module *Imported,
+ ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
SourceLocation EndLoc);
ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { }
public:
/// \brief Create a new module import declaration.
static ImportDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation ImportLoc, Module *Imported,
+ SourceLocation StartLoc, Module *Imported,
ArrayRef<SourceLocation> IdentifierLocs);
/// \brief Create a new module import declaration for an implicitly-generated
/// import.
static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
- SourceLocation ImportLoc, Module *Imported,
+ SourceLocation StartLoc, Module *Imported,
SourceLocation EndLoc);
/// \brief Create a new module import declaration.
let CategoryName = "Modules Issue" in {
def err_module_expected_ident : Error<
- "expected a module name after '__import_module__'">;
+ "expected a module name after module import">;
def err_module_expected_semi : Error<
"expected a semicolon name after module name">;
}
NeedsHandleIdentifier =
(isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
isExtensionToken() | isCXX11CompatKeyword() || isOutOfDate() ||
- (getTokenID() == tok::kw___import_module__));
+ (getTokenID() == tok::kw___import_module__) ||
+ (getObjCKeywordID() == tok::objc_import));
}
};
OBJC2_AT_KEYWORD(optional)
OBJC2_AT_KEYWORD(synthesize)
OBJC2_AT_KEYWORD(dynamic)
+OBJC2_AT_KEYWORD(import)
// TODO: What to do about context-sensitive keywords like:
// bycopy/byref/in/inout/oneway/out?
/// for preprocessing.
SourceLocation CodeCompletionFileLoc;
- /// \brief The source location of the __import_module__ keyword we just
- /// lexed, if any.
+ /// \brief The source location of the __import_module__ or 'import' keyword we
+ /// just lexed, if any.
SourceLocation ModuleImportLoc;
/// \brief The module import path that we're currently processing.
//===--------------------------------------------------------------------===//
// Modules
- DeclGroupPtrTy ParseModuleImport();
+ DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc);
//===--------------------------------------------------------------------===//
// GNU G++: Type Traits [Type-Traits.html in the GCC manual]
/// \brief The parser has processed a module import declaration.
///
- /// \param ImportLoc The location of the '__import_module__' keyword.
+ /// \param AtLoc The location of the '@' symbol, if present.
+ ///
+ /// \param ImportLoc The location of the '__import_module__' or 'import'
+ /// keyword.
///
/// \param Path The module access path.
- DeclResult ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
+ DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
+ ModuleIdPath Path);
/// \brief Retrieve a suitable printing policy.
PrintingPolicy getPrintingPolicy() const;
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());
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;
}
}
void DeclPrinter::VisitImportDecl(ImportDecl *D) {
- Out << "__import_module__ " << D->getImportedModule()->getFullModuleName()
+ Out << "@import " << D->getImportedModule()->getFullModuleName()
<< ";\n";
}
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();
}
}
-/// \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)
//
// __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.
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);
return DeclGroupPtrTy();
case tok::kw___import_module__:
- return ParseModuleImport();
+ return ParseModuleImport(SourceLocation());
default:
dont_know:
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();
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();
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);
ImportDecl *Import = ImportDecl::Create(Context,
Context.getTranslationUnitDecl(),
- ImportLoc, Mod,
- IdentifierLocs);
+ AtLoc.isValid()? AtLoc : ImportLoc,
+ Mod, IdentifierLocs);
Context.getTranslationUnitDecl()->addDecl(Import);
return Import;
}
-__import_module__ category_left;
+@import category_left;
@interface Foo(Bottom)
-(void)bottom;
@end
-__import_module__ category_right;
+@import category_right;
@interface LeftFoo(Bottom)
-(void)bottom;
-__import_module__ category_top;
+@import category_top;
@interface Foo(Left)
-(void)left;
-__import_module__ category_top;
+@import category_top;
@interface Foo(Right1)
-(void)right1;
-__import_module__ redecl_merge_left;
+@import redecl_merge_left;
@class C4;
@class C4;
@protocol P4;
@protocol P4;
@protocol P4;
-__import_module__ redecl_merge_right;
+@import redecl_merge_right;
@class B;
-__import_module__ redecl_merge_left;
+@import redecl_merge_left;
@class C4;
void accept_a_C4(C4*);
-__import_module__ redecl_merge_top;
+@import redecl_merge_top;
@class A;
-__import_module__ redecl_merge_top;
+@import redecl_merge_top;
@interface Super
@end
#endif
int ONE;
-__import_module__ redecl_merge_top.Explicit;
+@import redecl_merge_top.Explicit;
const int one = ONE;
// in other file: expected-note{{previous definition is here}}
-__import_module__ decldef;
+@import decldef;
A *a1; // expected-error{{unknown type name 'A'}}
B *b1; // expected-error{{unknown type name 'B'}}
-__import_module__ decldef.Decl;
+@import decldef.Decl;
A *a2;
B *b;
// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -I %S/Inputs -verify %s
#import "point.h"
-__import_module__ Module;
+@import Module;
#import "point.h"
// RUN: rm -rf %t
// RUN: %clang_cc1 -x objective-c -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
-__import_module__ Module.Sub;
+@import Module.Sub;
void test_Module_Sub() {
int *ip = Module_Sub;
}
-__import_module__ Module.Buried.Treasure;
+@import Module.Buried.Treasure;
void dig() {
unsigned *up = Buried_Treasure;
// lookup_left.h: expected-note{{using}}
// lookup_right.h: expected-note{{also found}}
-__import_module__ lookup_left_objc;
-__import_module__ lookup_right_objc;
+@import lookup_left_objc;
+@import lookup_right_objc;
void test(id x) {
[x method]; // expected-warning{{multiple methods named 'method' found}}
// RUN: %clang_cc1 -fmodule-cache-path %t -x objective-c -fmodule-name=category_bottom -emit-module %S/Inputs/module.map
// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
-__import_module__ category_bottom;
+@import category_bottom;
// in category_left.h: expected-note {{previous definition}}
// RUN: rm -rf %t
// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Wmodule-build -fmodule-cache-path %t -F %S/Inputs -verify %s
-__import_module__ Module; // expected-warning{{building module 'Module' from source}}
+@import Module; // expected-warning{{building module 'Module' from source}}
// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -Wno-error=incomplete-umbrella -x objective-c++ -fmodule-cache-path %t -F %S/Inputs -verify %s
// RUN: %clang_cc1 -fno-objc-infer-related-result-type -Werror -Wno-error=incomplete-umbrella -fmodule-cache-path %t -F %S/Inputs -verify %s
#define FOO
-__import_module__ Module;
+@import Module;
@interface OtherClass
@end
// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -DFOO_RETURNS_INT_PTR -verify %s
// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -verify %s
-__import_module__ CmdLine;
+@import CmdLine;
void test() {
#ifdef FOO_RETURNS_INT_PTR
@class C2;
@class C3;
@class C3;
-__import_module__ redecl_merge_left;
+@import redecl_merge_left;
@protocol P4;
@class C3;
@class C3;
-__import_module__ redecl_merge_right;
+@import redecl_merge_right;
@implementation A
- (Super*)init { return self; }
}
C4 *global_C4;
-__import_module__ redecl_merge_left_left;
+@import redecl_merge_left_left;
void test_C4a(C4 *c4) {
global_C4 = c4 = get_a_C4();
accept_a_C4(c4);
}
-__import_module__ redecl_merge_bottom;
+@import redecl_merge_bottom;
void test_C4b() {
if (&refers_to_C4) {
-__import_module__ redeclarations_left;
-__import_module__ redeclarations_right;
+@import redeclarations_left;
+@import redeclarations_right;
@interface MyObject : NSObject
@end
// RUN: rm -rf %t
// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
-__import_module__ DependsOnModule.CXX; // expected-error{{module 'DependsOnModule.CXX' requires feature 'cplusplus'}}
+@import DependsOnModule.CXX; // expected-error{{module 'DependsOnModule.CXX' requires feature 'cplusplus'}}
// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
// RUN: %clang_cc1 -x objective-c++ -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
-__import_module__ DependsOnModule;
+@import DependsOnModule;
void testSubFramework() {
float *sf1 = sub_framework; // expected-error{{use of undeclared identifier 'sub_framework'}}
}
-__import_module__ DependsOnModule.SubFramework;
+@import DependsOnModule.SubFramework;
void testSubFrameworkAgain() {
float *sf2 = sub_framework;
}
#ifdef __cplusplus
-__import_module__ DependsOnModule.CXX;
+@import DependsOnModule.CXX;
CXXOnly cxxonly;
#endif
// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
// Note: transitively imports Module.Sub2.
-__import_module__ Module.Sub;
+@import Module.Sub;
int getValue() {
return *Module_Sub + *Module_Sub2;