diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Basic/DiagnosticCommonKinds.td | 3 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticParseKinds.td | 6 | ||||
-rw-r--r-- | include/clang/Basic/IdentifierTable.h | 2 | ||||
-rw-r--r-- | include/clang/Basic/TokenKinds.def | 1 | ||||
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 10 | ||||
-rw-r--r-- | include/clang/Frontend/CompilerInstance.h | 21 | ||||
-rw-r--r-- | include/clang/Lex/ModuleLoader.h | 55 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 10 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 4 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 11 |
10 files changed, 105 insertions, 18 deletions
diff --git a/include/clang/Basic/DiagnosticCommonKinds.td b/include/clang/Basic/DiagnosticCommonKinds.td index 4b5de366cb..62d852572a 100644 --- a/include/clang/Basic/DiagnosticCommonKinds.td +++ b/include/clang/Basic/DiagnosticCommonKinds.td @@ -59,7 +59,8 @@ def err_friends_define_only_namespace_scope : Error< "cannot define a function with non-namespace scope in a friend declaration">; def err_deleted_non_function : Error< "only functions can have deleted definitions">; - +def warn_module_not_found : Warning<"module '%0' not found">, DefaultFatal; + // Sema && Lex def ext_longlong : Extension< "'long long' is an extension when C99 mode is not enabled">, diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index 27b4f850ee..9a6e7545b4 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -569,5 +569,11 @@ def err_seh___except_filter : Error< def err_seh___finally_block : Error< "%0 only allowed in __finally block">; +// Modules +def err_module_expected_ident : Error< + "expected a module name after '__import__'">; +def err_module_expected_semi : Error< + "expected a semicolon name after module name">; + } // end of Parse Issue category. } // end of Parser diagnostics diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 017af5caee..9238d3daa7 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -252,7 +252,7 @@ private: void RecomputeNeedsHandleIdentifier() { NeedsHandleIdentifier = (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() | - isExtensionToken()); + isExtensionToken() | getTokenID() == tok::kw___import__); } }; diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index e0b22b7b24..ccc2e612b2 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -397,6 +397,7 @@ KEYWORD(__array_extent , KEYCXX) // Apple Extension. KEYWORD(__private_extern__ , KEYALL) +KEYWORD(__import__ , KEYALL) // Microsoft Extension. KEYWORD(__declspec , KEYALL) diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 190ab85713..731ce383fc 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -18,6 +18,7 @@ #include "clang/Serialization/ASTBitCodes.h" #include "clang/Sema/Sema.h" #include "clang/Sema/CodeCompleteConsumer.h" +#include "clang/Lex/ModuleLoader.h" #include "clang/Lex/PreprocessingRecord.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/FileManager.h" @@ -66,7 +67,7 @@ class GlobalCodeCompletionAllocator /// \brief Utility class for loading a ASTContext from an AST file. /// -class ASTUnit { +class ASTUnit : public ModuleLoader { public: typedef std::map<FileID, std::vector<PreprocessedEntity *> > PreprocessedEntitiesByFileMap; @@ -696,6 +697,13 @@ public: /// /// \returns True if an error occurred, false otherwise. bool serialize(raw_ostream &OS); + + virtual ModuleKey loadModule(SourceLocation ImportLoc, + IdentifierInfo &ModuleName, + SourceLocation ModuleNameLoc) { + // ASTUnit doesn't know how to load modules (not that this matters). + return 0; + } }; } // namespace clang diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 3f97f1addb..88f8976b67 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ #include "clang/Frontend/CompilerInvocation.h" +#include "clang/Lex/ModuleLoader.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/OwningPtr.h" @@ -56,7 +57,7 @@ class TargetInfo; /// in to the compiler instance for everything. When possible, utility functions /// come in two forms; a short form that reuses the CompilerInstance objects, /// and a long form that takes explicit instances of any required objects. -class CompilerInstance { +class CompilerInstance : public ModuleLoader { /// The options used in this compiler instance. llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation; @@ -498,20 +499,6 @@ public: /// and replace any existing one with it. void createPreprocessor(); - /// Create a Preprocessor object. - /// - /// Note that this also creates a new HeaderSearch object which will be owned - /// by the resulting Preprocessor. - /// - /// \return The new object on success, or null on failure. - static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, - const PreprocessorOptions &, - const HeaderSearchOptions &, - const DependencyOutputOptions &, - const TargetInfo &, - const FrontendOptions &, - SourceManager &, FileManager &); - /// Create the AST context. void createASTContext(); @@ -626,6 +613,10 @@ public: const FrontendOptions &Opts); /// } + + virtual ModuleKey loadModule(SourceLocation ImportLoc, + IdentifierInfo &ModuleName, + SourceLocation ModuleNameLoc); }; } // end namespace clang diff --git a/include/clang/Lex/ModuleLoader.h b/include/clang/Lex/ModuleLoader.h index e69de29bb2..72ec0e3ebc 100644 --- a/include/clang/Lex/ModuleLoader.h +++ b/include/clang/Lex/ModuleLoader.h @@ -0,0 +1,55 @@ +//===--- ModuleLoader.h - Module Loader Interface ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ModuleLoader interface, which is responsible for +// loading named modules. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_LEX_MODULE_LOADER_H +#define LLVM_CLANG_LEX_MODULE_LOADER_H + +#include "clang/Basic/SourceLocation.h" + +namespace clang { + +class IdentifierInfo; + +/// \brief An opaque key that is used to describe the module and can be +/// interpreted by the module loader itself. +typedef void *ModuleKey; + +/// \brief Abstract interface for a module loader. +/// +/// This abstract interface describes a module loader, which is responsible +/// for resolving a module name (e.g., "std") to an actual module file, and +/// then loading that module. +class ModuleLoader { +public: + virtual ~ModuleLoader(); + + /// \brief Attempt to load the given module. + /// + /// This routine attempts to load the module described by the given + /// parameters. + /// + /// \param ImportLoc The location of the 'import' keyword. + /// \param ModuleName The name of the module to be loaded. + /// \param ModuleNameLoc The location of the module name. + /// + /// \returns If successful, a non-NULL module key describing this module. + /// Otherwise, returns NULL to indicate that the module could not be + /// loaded. + virtual ModuleKey loadModule(SourceLocation ImportLoc, + IdentifierInfo &ModuleName, + SourceLocation ModuleNameLoc) = 0; +}; + +} + +#endif diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index a95645451e..1ab6411e98 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -49,6 +49,7 @@ class PPCallbacks; class CodeCompletionHandler; class DirectoryLookup; class PreprocessingRecord; +class ModuleLoader; /// Preprocessor - This object engages in a tight little dance with the lexer to /// efficiently preprocess tokens. Lexers know only about tokens within a @@ -63,10 +64,12 @@ class Preprocessor : public llvm::RefCountedBase<Preprocessor> { SourceManager &SourceMgr; ScratchBuffer *ScratchBuf; HeaderSearch &HeaderInfo; + ModuleLoader &TheModuleLoader; /// \brief External source of macros. ExternalPreprocessorSource *ExternalSource; + /// PTH - An optional PTHManager object used for getting tokens from /// a token cache rather than lexing the original source file. llvm::OwningPtr<PTHManager> PTH; @@ -294,6 +297,7 @@ public: Preprocessor(Diagnostic &diags, const LangOptions &opts, const TargetInfo &target, SourceManager &SM, HeaderSearch &Headers, + ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup = 0, bool OwnsHeaderSearch = false); @@ -325,6 +329,9 @@ public: return ExternalSource; } + /// \brief Retrieve the module loader associated with this preprocessor. + ModuleLoader &getModuleLoader() const { return TheModuleLoader; } + /// SetCommentRetentionState - Control whether or not the preprocessor retains /// comments in output. void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments) { @@ -1008,6 +1015,9 @@ private: /// the macro should not be expanded return true, otherwise return false. bool HandleMacroExpandedIdentifier(Token &Tok, MacroInfo *MI); + /// \brief Handle a module import directive. + void HandleModuleImport(Token &Import); + /// \brief Cache macro expanded tokens for TokenLexers. // /// Works like a stack; a TokenLexer adds the macro expanded tokens that is diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 1215e2daa7..e5a129beb3 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1916,6 +1916,10 @@ bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, SourceLocation &DeclEnd); //===--------------------------------------------------------------------===// + // Modules + DeclGroupPtrTy ParseModuleImport(); + + //===--------------------------------------------------------------------===// // GNU G++: Type Traits [Type-Traits.html in the GCC manual] ExprResult ParseUnaryTypeTrait(); ExprResult ParseBinaryTypeTrait(); diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index adf2702cce..2e49840d0e 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -1073,6 +1073,17 @@ public: SourceLocation AsmLoc, SourceLocation RParenLoc); + /// \brief The parser has processed a module import declaration. + /// + /// \param ImportLoc The location of the '__import__' keyword. + /// + /// \param ModuleName The name of the module. + /// + /// \param ModuleNameLoc The location of the module name. + DeclResult ActOnModuleImport(SourceLocation ImportLoc, + IdentifierInfo &ModuleName, + SourceLocation ModuleNameLoc); + /// Scope actions. void ActOnPopScope(SourceLocation Loc, Scope *S); void ActOnTranslationUnitScope(Scope *S); |