Skip to content

Generate libSyntax API #10926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cmake/modules/SwiftHandleGybSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,20 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
"${SWIFT_SOURCE_DIR}/utils/UnicodeData/GraphemeBreakTest.txt"
"${SWIFT_SOURCE_DIR}/utils/gyb_stdlib_support.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_stdlib_unittest_support.py"
)
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/__init__.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Child.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/kinds.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Node.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/AttributeNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/CommonNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Token.py")

foreach (src ${${sources_var_name}})
string(REGEX REPLACE "[.]gyb$" "" src_sans_gyb "${src}")
if(src STREQUAL src_sans_gyb)
Expand Down Expand Up @@ -153,3 +166,16 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
set("${dependency_out_var_name}" "${dependency_targets}" PARENT_SCOPE)
set("${sources_var_name}" "${de_gybbed_sources}" PARENT_SCOPE)
endfunction()

function(add_gyb_target target sources)
set(options)
set(single_value_args ARCH)
set(multi_value_args)
cmake_parse_arguments(GYB
"${options}" "${single_value_args}" "${multi_value_args}" ${ARGN})

handle_gyb_sources(gyb_sources_depends sources "${GYB_ARCH}")

add_custom_target(${target}
DEPENDS "${gyb_sources_depends}")
endfunction()
2 changes: 1 addition & 1 deletion include/swift/AST/LegacyASTTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LegacyASTTransformer : public ASTVisitor<LegacyASTTransformer,
SourceLoc getEndLocForDecl(const Decl *D) const;
SourceLoc getEndLocForStmt(const Stmt *S) const;
SourceLoc getEndLocForExpr(const Expr *E) const;
RC<SyntaxData> getUnknownSyntax(SourceRange SR);
RC<SyntaxData> getUnknownSyntax(SourceRange SR, SyntaxKind Kind);
RC<SyntaxData> getAttributesFromDecl(Decl *D);
RC<SyntaxData> getUnknownDecl(Decl *D);
RC<SyntaxData> getUnknownStmt(Stmt *S);
Expand Down
1 change: 1 addition & 0 deletions include/swift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ configure_file(Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h

add_subdirectory(Option)
add_subdirectory(SwiftRemoteMirror)
add_subdirectory(Syntax)
10 changes: 10 additions & 0 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,16 @@ DeclName parseDeclName(ASTContext &ctx, StringRef name);
/// Whether a given token can be the start of a decl.
bool isKeywordPossibleDeclStart(const Token &Tok);

/// \brief Lex and return a vector of `TokenSyntax` tokens, which include
/// leading and trailing trivia.
std::vector<std::pair<RC<syntax::RawTokenSyntax>,
syntax::AbsolutePosition>>
tokenizeWithTrivia(const LangOptions &LangOpts,
const SourceManager &SM,
unsigned BufferID,
unsigned Offset = 0,
unsigned EndOffset = 0);

} // end namespace swift

#endif
11 changes: 0 additions & 11 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "swift/Basic/LLVM.h"
#include "swift/Basic/OptionSet.h"
#include "swift/Basic/Version.h"
#include "swift/Syntax/TokenSyntax.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
Expand Down Expand Up @@ -132,16 +131,6 @@ namespace swift {
bool TokenizeInterpolatedString = true,
ArrayRef<Token> SplitTokens = ArrayRef<Token>());

/// \brief Lex and return a vector of `TokenSyntax` tokens, which include
/// leading and trailing trivia.
std::vector<std::pair<RC<syntax::RawTokenSyntax>,
syntax::AbsolutePosition>>
tokenizeWithTrivia(const LangOptions &LangOpts,
const SourceManager &SM,
unsigned BufferID,
unsigned Offset = 0,
unsigned EndOffset = 0);

/// Once parsing is complete, this walks the AST to resolve imports, record
/// operators, and do other top-level validation.
///
Expand Down
11 changes: 11 additions & 0 deletions include/swift/Syntax/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(SWIFT_GYB_FLAGS
--line-directive "''")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't understand why you'd disable line directives like this; the result would be that any compilation errors point into the generated file instead of the original one, with the typical result that maintainers edit the wrong file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh yes sorry about that. I turned line directives off while initially writing the gyb templates because it made it harder to see what the template instantiation was doing. That said, they should have been re-enabled before merging. I’ll re-enable them in a patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm looking, these are for the C++ bindings. gyb's line directive code emits Swift-style line directives -- clang will just ignore them. The patch for this would need to teach gyb how and when to emit C-style line directives, which wouldn't be too difficult.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, those aren't swift-style line directives, which are broken for this purpose because they are only valid in certain syntactic positions. These are just comments that get post-processed by the line-directive tool. For error messages, it doesn't matter that clang would ignore them because the output of clang would get passed through the line-directive tool just like the output of Swift does. However, generating real #line directives should also allow you to debug in the .gyb source rather than in the generated .cpp


set(generated_include_sources
SyntaxKind.h.gyb
SyntaxNodes.h.gyb
SyntaxBuilders.h.gyb
SyntaxFactory.h.gyb)

add_gyb_target(swift-syntax-generated-headers
"${generated_include_sources}")
Loading