|
| 1 | +//===------------------ SwiftSyntaxCDataTypes.h -------------------*- C -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// There are two copies of this file in the Swift compiler repository and in // |
| 13 | +// the SwiftSyntax repository. They need to always share the same contents. // |
| 14 | +// // |
| 15 | +// The reason behind this is that the SwiftSyntax module should be able to // |
| 16 | +// build with no dependencies to the compiler repo (in particular not // |
| 17 | +// _InternalSwiftSyntaxParser) so that it can be used for code generation // |
| 18 | +// without a matching toolchain. But to make SwiftSyntax parsing efficient, // |
| 19 | +// we need to create RawSyntax nodes from the C nodes without any conversion // |
| 20 | +// and thus SwiftSyntax needs to have knowledge about the layout of these C // |
| 21 | +// types. Thus the two copies of the file. The equality of these files is // |
| 22 | +// checked in CI (verify the source matches) and at runtime by // |
| 23 | +// SwiftSyntaxParser (verify that a hash generated from the layouts matches) // |
| 24 | +//===----------------------------------------------------------------------===// |
| 25 | + |
| 26 | +#ifndef SWIFT_C_SYNTAX_C_DATA_TYPES_H |
| 27 | +#define SWIFT_C_SYNTAX_C_DATA_TYPES_H |
| 28 | + |
| 29 | +#include <stdbool.h> |
| 30 | + |
| 31 | +/// Offset+length in UTF8 bytes. |
| 32 | +typedef struct { |
| 33 | + uint32_t offset; |
| 34 | + uint32_t length; |
| 35 | +} swiftparse_range_t; |
| 36 | + |
| 37 | +typedef uint8_t swiftparse_trivia_kind_t; |
| 38 | +typedef uint8_t swiftparse_token_kind_t; |
| 39 | +typedef uint16_t swiftparse_syntax_kind_t; |
| 40 | + |
| 41 | +/// This is for the client to provide an opaque pointer that the parser will |
| 42 | +/// associate with a syntax node. |
| 43 | +typedef void *swiftparse_client_node_t; |
| 44 | + |
| 45 | +typedef struct { |
| 46 | + /// The length in source this trivia piece occupies, in UTF8 bytes. |
| 47 | + uint32_t length; |
| 48 | + swiftparse_trivia_kind_t kind; |
| 49 | +} swiftparse_trivia_piece_t; |
| 50 | + |
| 51 | +typedef struct { |
| 52 | + const swiftparse_trivia_piece_t *leading_trivia; |
| 53 | + const swiftparse_trivia_piece_t *trailing_trivia; |
| 54 | + uint16_t leading_trivia_count; |
| 55 | + uint16_t trailing_trivia_count; |
| 56 | + swiftparse_token_kind_t kind; |
| 57 | + /// Represents the range for the node, including trivia. |
| 58 | + swiftparse_range_t range; |
| 59 | +} swiftparse_token_data_t; |
| 60 | + |
| 61 | +typedef struct { |
| 62 | + const swiftparse_client_node_t *nodes; |
| 63 | + uint32_t nodes_count; |
| 64 | +} swiftparse_layout_data_t; |
| 65 | + |
| 66 | +typedef struct { |
| 67 | + union { |
| 68 | + swiftparse_token_data_t token_data; |
| 69 | + swiftparse_layout_data_t layout_data; |
| 70 | + }; |
| 71 | + /// The syntax kind. A value of '0' means this is a token node. |
| 72 | + swiftparse_syntax_kind_t kind; |
| 73 | + bool present; |
| 74 | +} swiftparse_syntax_node_t; |
| 75 | + |
| 76 | +#endif |
0 commit comments