project: support %cu directive and strip -M* options

This commit is contained in:
Fangrui Song 2019-06-27 19:11:38 -07:00
parent cc7e0dde33
commit 2eefca2ab8
2 changed files with 15 additions and 2 deletions

View File

@ -261,6 +261,13 @@ struct ShowMessageParam {
// Used to identify the language at a file level. The ordering is important, as // Used to identify the language at a file level. The ordering is important, as
// a file previously identified as `C`, will be changed to `Cpp` if it // a file previously identified as `C`, will be changed to `Cpp` if it
// encounters a c++ declaration. // encounters a c++ declaration.
enum class LanguageId { Unknown = -1, C = 0, Cpp = 1, ObjC = 2, ObjCpp = 3 }; enum class LanguageId {
Unknown = -1,
C = 0,
Cpp = 1,
ObjC = 2,
ObjCpp = 3,
Cuda = 4,
};
} // namespace ccls } // namespace ccls

View File

@ -60,7 +60,8 @@ std::pair<LanguageId, bool> lookupExtension(std::string_view filename) {
bool objc = types::isObjC(I); bool objc = types::isObjC(I);
LanguageId ret; LanguageId ret;
if (types::isCXX(I)) if (types::isCXX(I))
ret = objc ? LanguageId::ObjCpp : LanguageId::Cpp; ret = types::isCuda(I) ? LanguageId::Cuda
: objc ? LanguageId::ObjCpp : LanguageId::Cpp;
else if (objc) else if (objc)
ret = LanguageId::ObjC; ret = LanguageId::ObjC;
else if (I == types::TY_C || I == types::TY_CHeader) else if (I == types::TY_C || I == types::TY_CHeader)
@ -117,6 +118,8 @@ struct ProjectProcessor {
ok |= lang == LanguageId::C && header; ok |= lang == LanguageId::C && header;
else if (A.consume_front("%cpp ")) else if (A.consume_front("%cpp "))
ok |= lang == LanguageId::Cpp; ok |= lang == LanguageId::Cpp;
else if (A.consume_front("%cu "))
ok |= lang == LanguageId::Cuda;
else if (A.consume_front("%hpp ")) else if (A.consume_front("%hpp "))
ok |= lang == LanguageId::Cpp && header; ok |= lang == LanguageId::Cpp && header;
else if (A.consume_front("%objective-c ")) else if (A.consume_front("%objective-c "))
@ -128,6 +131,9 @@ struct ProjectProcessor {
} }
if (ok) if (ok)
args.push_back(A.data()); args.push_back(A.data());
} else if (A.startswith("-M")) {
if (A == "-MF" || A == "-MT" || A == "-MQ")
i++;
} else if (!ExcludesArg(A)) { } else if (!ExcludesArg(A)) {
args.push_back(arg); args.push_back(arg);
} }