In order to make the migration to modules easier, it seems to be helpful
to allow a 1:1 mapping between target names of a current build system
and the corresponding C++ modules. As such targets commonly contain
characters like "-". ":" and "/", allowing arbitrary quote-escaped
strings seems to be a straightforward option.
After several offline discussions, the precise mechanisms for C++
module names especially regarding submodules and import statements has
yet to be determined. Thus, this patch only enables string literals as
names inside the module map files which can be used by automatic module
import (through #include).
Also improve the error message on missing use-declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196573
91177308-0d34-0410-b5e6-
96231b3b80d8
def error_use_of_private_header_outside_module : Error<
"use of private header from outside its module: '%0'">;
def error_undeclared_use_of_module : Error<
- "use of a module not declared used: '%0'">;
+ "module %0 does not depend on a module exporting '%1'">;
def warn_header_guard : Warning<
"%0 is used as a header guard here, followed by #define of a different macro">,
bool ModuleMapParser::parseModuleId(ModuleId &Id) {
Id.clear();
do {
- if (Tok.is(MMToken::Identifier)) {
+ if (Tok.is(MMToken::Identifier) || Tok.is(MMToken::StringLiteral)) {
Id.push_back(std::make_pair(Tok.getString(), Tok.getLocation()));
consumeToken();
} else {
consumeToken();
// Parse the module-id.
ModuleId ParsedModuleId;
-
- do {
- if (Tok.is(MMToken::Identifier)) {
- ParsedModuleId.push_back(
- std::make_pair(Tok.getString(), Tok.getLocation()));
- consumeToken();
-
- if (Tok.is(MMToken::Period)) {
- consumeToken();
- continue;
- }
-
- break;
- }
-
- Diags.Report(Tok.getLocation(), diag::err_mmap_module_id);
- HadError = true;
- return;
- } while (true);
+ parseModuleId(ParsedModuleId);
ActiveModule->UnresolvedDirectUses.push_back(ParsedModuleId);
}
if (RequestingModule && getLangOpts().ModulesDeclUse &&
violatesUseDeclarations(RequestingModule, RequestedModule.getModule()))
Diag(FilenameLoc, diag::error_undeclared_use_of_module)
- << Filename;
+ << RequestingModule->getFullModuleName() << Filename;
}
const FileEntry *Preprocessor::LookupFile(
#ifndef H_H
#define H_H
#include "c.h"
-#include "d.h" // expected-error {{use of a module not declared used}}
+#include "d.h" // expected-error {{does not depend on a module exporting}}
#include "h1.h"
const int h1 = aux_h*c*7*d;
#endif
--- /dev/null
+#ifndef A_H
+#define A_H
+const int a = 2;
+#endif
--- /dev/null
+#ifndef B_H
+#define B_H
+const int b = 3;
+#endif
--- /dev/null
+#ifndef C_H
+#define C_H
+const int c = 2;
+#endif
--- /dev/null
+module "my/module-a" {
+ header "a.h"
+ use "my/module-c"
+
+ module "Sub" {
+ header "sub.h"
+ }
+}
+
+module "my/module-b" {
+ header "b.h"
+}
+
+module "my/module-c" {
+ header "c.h"
+}
--- /dev/null
+#ifndef SUB_H
+#define SUB_H
+const int sub = 2;
+#endif
#include "g.h"
#include "e.h"
-#include "f.h" // expected-error {{use of a module not declared used}}
+#include "f.h" // expected-error {{module XG does not depend on a module exporting 'f.h'}}
const int g2 = g1+e+f;
#include "h.h"
#include "e.h"
-#include "f.h" // expected-error {{use of a module not declared used}}
+#include "f.h" // expected-error {{does not depend on a module exporting}}
const int h2 = h1+e+f;
--- /dev/null
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fmodules-decluse -I %S/Inputs/string_names %s -fmodule-name="my/module-a" -verify
+
+#include "a.h"
+#include "b.h" // expected-error {{does not depend on a module exporting}}
+#include "c.h"