Skip to content

Commit 9d56de1

Browse files
committed
[interop] NFC, create ClangSyntaxPrinter class
1 parent 5a02fde commit 9d56de1

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

lib/PrintAsClang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
add_swift_host_library(swiftPrintAsClang STATIC
3-
CxxSynthesis.cpp
3+
ClangSyntaxPrinter.cpp
44
DeclAndTypePrinter.cpp
55
ModuleContentsWriter.cpp
66
PrimitiveTypeMapping.cpp

lib/PrintAsClang/CxxSynthesis.cpp renamed to lib/PrintAsClang/ClangSyntaxPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- CxxSynthesis.cpp - Rules for synthesizing C++ code -----*- C++ -*-===//
1+
//===--- ClangSyntaxPrinter.cpp - Printer for C and C++ code ----*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,15 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "CxxSynthesis.h"
13+
#include "ClangSyntaxPrinter.h"
1414

1515
using namespace swift;
1616
using namespace cxx_synthesis;
1717

1818
StringRef cxx_synthesis::getCxxImplNamespaceName() { return "_impl"; }
1919

2020
/// Print a C++ namespace declaration with the give name and body.
21-
void CxxPrinter::printNamespace(
21+
void ClangSyntaxPrinter::printNamespace(
2222
llvm::function_ref<void(raw_ostream &OS)> namePrinter,
2323
llvm::function_ref<void(raw_ostream &OS)> bodyPrinter) const {
2424
os << "namespace ";
@@ -30,7 +30,7 @@ void CxxPrinter::printNamespace(
3030
os << "\n\n";
3131
}
3232

33-
void CxxPrinter::printNamespace(
33+
void ClangSyntaxPrinter::printNamespace(
3434
StringRef name,
3535
llvm::function_ref<void(raw_ostream &OS)> bodyPrinter) const {
3636
printNamespace([&](raw_ostream &os) { os << name; }, bodyPrinter);

lib/PrintAsClang/CxxSynthesis.h renamed to lib/PrintAsClang/ClangSyntaxPrinter.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- CxxSynthesis.h - Rules for synthesizing C++ code -------*- C++ -*-===//
1+
//===--- ClangSyntaxPrinter.h - Printer for C and C++ code ------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_PRINTASCLANG_CXXSYNTHESIS_H
14-
#define SWIFT_PRINTASCLANG_CXXSYNTHESIS_H
13+
#ifndef SWIFT_PRINTASCLANG_CLANGSYNTAXPRINTER_H
14+
#define SWIFT_PRINTASCLANG_CLANGSYNTAXPRINTER_H
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "llvm/ADT/StringRef.h"
@@ -26,9 +26,11 @@ namespace cxx_synthesis {
2626
/// module in C++.
2727
StringRef getCxxImplNamespaceName();
2828

29-
class CxxPrinter {
29+
} // end namespace cxx_synthesis
30+
31+
class ClangSyntaxPrinter {
3032
public:
31-
CxxPrinter(raw_ostream &os) : os(os) {}
33+
ClangSyntaxPrinter(raw_ostream &os) : os(os) {}
3234

3335
/// Print a C++ namespace declaration with the give name and body.
3436
void
@@ -43,7 +45,6 @@ class CxxPrinter {
4345
raw_ostream &os;
4446
};
4547

46-
} // end namespace cxx_synthesis
4748
} // end namespace swift
4849

4950
#endif

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "DeclAndTypePrinter.h"
14-
#include "CxxSynthesis.h"
14+
#include "ClangSyntaxPrinter.h"
1515
#include "PrimitiveTypeMapping.h"
1616
#include "PrintClangFunction.h"
1717

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "ModuleContentsWriter.h"
1414

15-
#include "CxxSynthesis.h"
15+
#include "ClangSyntaxPrinter.h"
1616
#include "DeclAndTypePrinter.h"
1717
#include "OutputLanguageMode.h"
1818
#include "PrimitiveTypeMapping.h"
@@ -642,8 +642,6 @@ swift::printModuleContentsAsObjC(raw_ostream &os,
642642
void swift::printModuleContentsAsCxx(
643643
raw_ostream &os, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
644644
ModuleDecl &M) {
645-
using cxx_synthesis::CxxPrinter;
646-
647645
std::string moduleContentsBuf;
648646
llvm::raw_string_ostream moduleOS{moduleContentsBuf};
649647
std::string modulePrologueBuf;
@@ -671,7 +669,7 @@ void swift::printModuleContentsAsCxx(
671669
}
672670

673671
// Construct a C++ namespace for the module.
674-
CxxPrinter(os).printNamespace(
672+
ClangSyntaxPrinter(os).printNamespace(
675673
[&](raw_ostream &os) { M.ValueDecl::getName().print(os); },
676674
[&](raw_ostream &os) { os << moduleOS.str(); });
677675
}

0 commit comments

Comments
 (0)