Skip to content

Commit

Permalink
[SYCL] Fix double definition of default values for template parameters.
Browse files Browse the repository at this point in the history
Added SuppressDefaultTemplateArguments flag for PrintingPolicy
class and use it at generation of the intergation header.

Example:
  ///  template<typename T = void>
  ///  class A {...};
  ///  /*Forward declaration*/
  ///  template<typename T> class kernel;
  ///  ...
  ///  cgh.parallel_for<class kernel<A>>>(
  ///      range<1>(1), [=](id<1> i){ /*do something*/ });

At the moment the forward declaration of class A will be generated as
  ///   template<typename T = void> class A
after this patch will be written as
  ///   template<typename T> class A

Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent 9be56d5 commit 5c727bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 11 additions & 1 deletion clang/include/clang/AST/PrettyPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct PrintingPolicy {
MSVCFormatting(false), ConstantsAsWritten(false),
SuppressImplicitBase(false), FullyQualifiedName(false),
RemapFilePaths(false), PrintCanonicalTypes(false),
SuppressDefinition(false) {}
SuppressDefinition(false), SuppressDefaultTemplateArguments (false) {}

/// Adjust this printing policy for cases where it's known that we're
/// printing C++ code (for instance, if AST dumping reaches a C++-only
Expand All @@ -69,6 +69,7 @@ struct PrintingPolicy {
void adjustForCPlusPlusFwdDecl() {
PolishForDeclaration = true;
SuppressDefinition = true;
SuppressDefaultTemplateArguments = true;
}

/// The number of spaces to use to indent each line.
Expand Down Expand Up @@ -252,6 +253,15 @@ struct PrintingPolicy {
/// \endcode
unsigned SuppressDefinition : 1;

/// When true, suppresses printing default template arguments of a type. E.g.
/// \code
/// template<typename T = void> class A
/// \endcode
/// will be printed as
/// \code
/// template<typename T> class A
/// \endcode
unsigned SuppressDefaultTemplateArguments : 1;
};

} // end namespace clang
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,8 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {

Out << *TTP;

if (TTP->hasDefaultArgument()) {
if (TTP->hasDefaultArgument()
&& !Policy.SuppressDefaultTemplateArguments ) {
Out << " = ";
Out << TTP->getDefaultArgument().getAsString(Policy);
};
Expand All @@ -1024,7 +1025,8 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {
Name = II->getName();
printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());

if (NTTP->hasDefaultArgument()) {
if (NTTP->hasDefaultArgument()
&& !Policy.SuppressDefaultTemplateArguments ) {
Out << " = ";
NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy,
Indentation);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/integration_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct x {};
template <typename T>
struct point {};
namespace second_namespace {
template <typename T>
template <typename T = int>
class second_kernel;
}

Expand Down

0 comments on commit 5c727bb

Please sign in to comment.