2020-05-29 22:47:23 +08:00
|
|
|
//===--- CommandLineArgs.cpp ----------------------------------------------===//
|
2018-05-24 16:41:07 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-05-24 16:41:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-05-29 22:47:23 +08:00
|
|
|
#include "clang/Testing/CommandLineArgs.h"
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2018-05-24 16:41:07 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
|
|
|
|
std::vector<std::string> Args;
|
2018-05-24 16:41:07 +08:00
|
|
|
// Test with basic arguments.
|
|
|
|
switch (Lang) {
|
|
|
|
case Lang_C89:
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
Args = {"-x", "c", "-std=c89"};
|
2018-05-24 16:41:07 +08:00
|
|
|
break;
|
Renamed Lang_C to Lang_C99, Lang_CXX to Lang_CXX03, and 2a to 20
Summary:
I think we would be better off with tests explicitly specifying the
language mode. Right now Lang_C means C99, but reads as "any C version",
or as "unspecified C version".
I also changed '-std=c++98' to '-std=c++03' because they are aliases (so
there is no difference in practice), because Clang implements C++03
rules in practice, and because 03 makes a nice sortable progression
between 03, 11, 14, 17, 20.
Reviewers: shafik, hlopko
Reviewed By: hlopko
Subscribers: jfb, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D81000
2020-06-02 22:10:39 +08:00
|
|
|
case Lang_C99:
|
|
|
|
Args = {"-x", "c", "-std=c99"};
|
|
|
|
break;
|
|
|
|
case Lang_CXX03:
|
|
|
|
Args = {"-std=c++03", "-frtti"};
|
2018-05-24 16:41:07 +08:00
|
|
|
break;
|
|
|
|
case Lang_CXX11:
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
Args = {"-std=c++11", "-frtti"};
|
2018-05-24 16:41:07 +08:00
|
|
|
break;
|
|
|
|
case Lang_CXX14:
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
Args = {"-std=c++14", "-frtti"};
|
2018-05-24 16:41:07 +08:00
|
|
|
break;
|
2019-12-13 00:13:35 +08:00
|
|
|
case Lang_CXX17:
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
Args = {"-std=c++17", "-frtti"};
|
2019-12-13 00:13:35 +08:00
|
|
|
break;
|
Renamed Lang_C to Lang_C99, Lang_CXX to Lang_CXX03, and 2a to 20
Summary:
I think we would be better off with tests explicitly specifying the
language mode. Right now Lang_C means C99, but reads as "any C version",
or as "unspecified C version".
I also changed '-std=c++98' to '-std=c++03' because they are aliases (so
there is no difference in practice), because Clang implements C++03
rules in practice, and because 03 makes a nice sortable progression
between 03, 11, 14, 17, 20.
Reviewers: shafik, hlopko
Reviewed By: hlopko
Subscribers: jfb, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D81000
2020-06-02 22:10:39 +08:00
|
|
|
case Lang_CXX20:
|
|
|
|
Args = {"-std=c++20", "-frtti"};
|
2019-05-09 11:59:21 +08:00
|
|
|
break;
|
2018-05-24 16:41:07 +08:00
|
|
|
case Lang_OBJCXX:
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
Args = {"-x", "objective-c++", "-frtti"};
|
2019-12-07 01:10:23 +08:00
|
|
|
break;
|
|
|
|
case Lang_OpenCL:
|
2018-05-24 16:41:07 +08:00
|
|
|
llvm_unreachable("Not implemented yet!");
|
|
|
|
}
|
Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 20:12:51 +08:00
|
|
|
return Args;
|
2018-05-24 16:41:07 +08:00
|
|
|
}
|
|
|
|
|
2020-06-04 23:40:38 +08:00
|
|
|
StringRef getFilenameForTesting(TestLanguage Lang) {
|
|
|
|
switch (Lang) {
|
|
|
|
case Lang_C89:
|
|
|
|
case Lang_C99:
|
|
|
|
return "input.c";
|
|
|
|
|
|
|
|
case Lang_CXX03:
|
|
|
|
case Lang_CXX11:
|
|
|
|
case Lang_CXX14:
|
|
|
|
case Lang_CXX17:
|
|
|
|
case Lang_CXX20:
|
|
|
|
return "input.cc";
|
|
|
|
|
|
|
|
case Lang_OpenCL:
|
|
|
|
return "input.cl";
|
|
|
|
|
|
|
|
case Lang_OBJCXX:
|
|
|
|
return "input.mm";
|
|
|
|
}
|
2020-06-05 17:41:31 +08:00
|
|
|
llvm_unreachable("Unhandled TestLanguage enum");
|
2020-06-04 23:40:38 +08:00
|
|
|
}
|
|
|
|
|
2018-05-24 16:41:07 +08:00
|
|
|
} // end namespace clang
|