-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[🦩] Add ASTGen. #60943
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
Closed
Closed
[🦩] Add ASTGen. #60943
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7bc67c9
Add Swift-side infrastructure for ASTGen.
zoecarver 2df25fc
Move ASTGen into Swift from swift-syntax.
zoecarver ddede20
Apply Doug's review comments
zoecarver 4e9e5fe
Make ASTGen a swift package
zoecarver 401cfc4
Add support for closures
zoecarver 1b1944e
Add support for structs/classes.
zoecarver 629fb68
[nfc] Split ASTGen into files + extensions.
zoecarver d58a01d
Add support for bool literals.
zoecarver 5935670
Support functions with statements in their body.
zoecarver 7433dc9
Link a few more targets
zoecarver 5b792b7
Fix the remaining few linker errors.
zoecarver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
//===--- ASTBridging.h - header for the swift SILBridging module ----------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_C_AST_ASTBRIDGING_H | ||
#define SWIFT_C_AST_ASTBRIDGING_H | ||
|
||
// Provide macros to temporarily suppress warning about the use of | ||
// _Nullable and _Nonnull. | ||
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \ | ||
_Pragma("clang diagnostic push") \ | ||
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \ | ||
_Pragma("clang assume_nonnull begin") | ||
|
||
#define SWIFT_END_NULLABILITY_ANNOTATIONS \ | ||
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end") | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Diagnostic Engine | ||
//===----------------------------------------------------------------------===// | ||
|
||
// TODO: Move this to somewhere common header. | ||
#if __has_attribute(enum_extensibility) | ||
#define ENUM_EXTENSIBILITY_ATTR(arg) __attribute__((enum_extensibility(arg))) | ||
#else | ||
#define ENUM_EXTENSIBILITY_ATTR(arg) | ||
#endif | ||
|
||
// NOTE: This must be the same underlying value as C++ 'swift::DiagID' defined | ||
// in 'DiagnosticList.cpp'. | ||
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : unsigned { | ||
#define DIAG(KIND, ID, Options, Text, Signature) BridgedDiagID_##ID, | ||
#include "swift/AST/DiagnosticsAll.def" | ||
} BridgedDiagID; | ||
|
||
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS | ||
|
||
typedef long SwiftInt; | ||
typedef unsigned long SwiftUInt; | ||
|
||
typedef struct { | ||
const void *_Nullable data; | ||
long numElements; | ||
} BridgedArrayRef; | ||
|
||
typedef struct { | ||
void *start; | ||
SwiftInt byteLength; | ||
} BridgedCharSourceRange; | ||
|
||
// FIXME: Can we bridge InFlightDiagnostic? | ||
void DiagnosticEngine_diagnose(void *, void *loc, BridgedDiagID diagID, | ||
BridgedArrayRef arguments, | ||
BridgedCharSourceRange highlight, | ||
BridgedArrayRef fixIts); | ||
|
||
int DiagnosticEngine_hadAnyError(void *); | ||
|
||
typedef const char *BridgedIdentifier; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
||
#define _Bool bool | ||
|
||
#endif | ||
|
||
BridgedIdentifier | ||
SwiftASTContext_getIdentifier(void *ctx, const char *_Nullable str, long len); | ||
|
||
void *SwiftImportDecl_create(void *, void *, void *, char, void *, | ||
BridgedArrayRef, BridgedArrayRef); | ||
|
||
void *SwiftTopLevelCodeDecl_createStmt(void *ctx, void *DC, void *startLoc, | ||
void *element, void *endLoc); | ||
void *SwiftTopLevelCodeDecl_createExpr(void *ctx, void *DC, void *startLoc, | ||
void *element, void *endLoc); | ||
|
||
void *SwiftSequenceExpr_create(void *ctx, BridgedArrayRef exprs); | ||
|
||
void *SwiftTupleExpr_create(void *ctx, void *lparen, BridgedArrayRef subs, | ||
void *rparen); | ||
|
||
void *SwiftFunctionCallExpr_create(void *ctx, void *fn, void *args); | ||
|
||
void *SwiftIdentifierExpr_create(void *ctx, const char *base, void *loc); | ||
|
||
void *SwiftStringLiteralExpr_create(void *ctx, const char *_Nullable string, | ||
long len, void *TokenLoc); | ||
|
||
void *SwiftIntegerLiteralExpr_create(void *ctx, const char *_Nullable string, | ||
long len, void *TokenLoc); | ||
|
||
void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc); | ||
|
||
void *SwiftVarDecl_create(void *ctx, const char *_Nullable name, | ||
void *loc, _Bool isStatic, _Bool isLet, void *dc); | ||
|
||
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then, void *_Nullable elseLoc, | ||
void *_Nullable elseStmt); | ||
|
||
void *BraceStmt_createExpr(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc); | ||
void *BraceStmt_createStmt(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc); | ||
|
||
void *BridgedSourceLoc_advanced(void *loc, long len); | ||
|
||
void *ParamDecl_create(void *ctx, void *loc, | ||
void *_Nullable argLoc, void *_Nullable argName, | ||
void *_Nullable paramLoc, void *_Nullable paramName, | ||
void *declContext); | ||
|
||
void *FuncDecl_create(void *ctx, void *staticLoc, _Bool isStatic, void *funcLoc, | ||
const char *name, void *nameLoc, | ||
_Bool isAsync, void *_Nullable asyncLoc, | ||
_Bool throws, void *_Nullable throwsLoc, | ||
void *paramLLoc, BridgedArrayRef params, void *paramRLoc, | ||
void *_Nullable body, void *_Nullable returnType, | ||
void *declContext); | ||
|
||
void *SimpleIdentTypeRepr_create(void *ctx, void *loc, const char *id); | ||
|
||
void *UnresolvedDotExpr_create(void *ctx, void *base, void *dotLoc, const char *name, void *nameLoc); | ||
|
||
void *ClosureExpr_create(void *ctx, void *body, void *dc); | ||
|
||
void NominalTypeDecl_setMembers(void *decl, BridgedArrayRef members); | ||
|
||
struct DeclContextAndDecl { | ||
void *declContext; | ||
void *nominalDecl; | ||
void *decl; | ||
}; | ||
|
||
struct DeclContextAndDecl StructDecl_create(void *ctx, void *loc, const char *name, void *nameLoc, | ||
void *dc); | ||
struct DeclContextAndDecl ClassDecl_create(void *ctx, void *loc, const char *name, void *nameLoc, | ||
void *dc); | ||
|
||
void TopLevelCodeDecl_dump(void *); | ||
void Expr_dump(void *); | ||
void Decl_dump(void *); | ||
void Stmt_dump(void *); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
SWIFT_END_NULLABILITY_ANNOTATIONS | ||
|
||
#endif // SWIFT_C_AST_ASTBRIDGING_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type really sucks :(