refactor: remove extern/const where possible

This commit is contained in:
ObserverOfTime 2024-02-28 00:56:22 +02:00 committed by Amaan Qureshi
parent 59838de33a
commit b4b2d9cecc
5 changed files with 26 additions and 13 deletions

View file

@ -263,7 +263,6 @@ impl Generator {
fn add_pragmas(&mut self) {
add_line!(self, "#if defined(__GNUC__) || defined(__clang__)");
add_line!(self, "#pragma GCC diagnostic push");
add_line!(
self,
"#pragma GCC diagnostic ignored \"-Wmissing-field-initializers\""
@ -1342,14 +1341,23 @@ impl Generator {
add_line!(self, "");
}
add_line!(self, "#ifdef TS_PUBLIC");
add_line!(self, "#undef TS_PUBLIC");
add_line!(self, "#endif");
add_line!(self, "");
add_line!(self, "#ifdef _WIN32");
add_line!(self, "#define extern __declspec(dllexport)");
add_line!(self, "#define TS_PUBLIC __declspec(dllexport)");
add_line!(self, "#else");
add_line!(
self,
"#define TS_PUBLIC __attribute__((visibility(\"default\")))"
);
add_line!(self, "#endif");
add_line!(self, "");
add_line!(
self,
"extern const TSLanguage *{language_function_name}(void) {{",
"TS_PUBLIC const TSLanguage *{language_function_name}() {{",
);
indent!(self);
add_line!(self, "static const TSLanguage language = {{");

View file

@ -7,7 +7,7 @@ typedef struct TSLanguage TSLanguage;
extern "C" {
#endif
extern const TSLanguage *tree_sitter_PARSER_NAME(void);
const TSLanguage *tree_sitter_PARSER_NAME(void);
#ifdef __cplusplus
}

View file

@ -2,10 +2,10 @@
typedef struct TSLanguage TSLanguage;
extern const TSLanguage *tree_sitter_LOWER_PARSER_NAME(void);
TSLanguage *tree_sitter_LOWER_PARSER_NAME(void);
static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr((void *)tree_sitter_LOWER_PARSER_NAME());
return PyLong_FromVoidPtr(tree_sitter_LOWER_PARSER_NAME());
}
static PyMethodDef methods[] = {

View file

@ -97,10 +97,15 @@ fn tree_sitter_dir(package_json: &str, name: &str) -> tempfile::TempDir {
format!(
r##"
#include "tree_sitter/parser.h"
#ifdef _WIN32
#define extern __declspec(dllexport)
#ifdef TS_PUBLIC
#undef TS_PUBLIC
#endif
extern const TSLanguage *tree_sitter_{name}(void) {{}}
#ifdef _WIN32
#define TS_PUBLIC __declspec(dllexport)
#else
#define TS_PUBLIC __attribute__((visibility("default")))
#endif
TS_PUBLIC const TSLanguage *tree_sitter_{name}() {{}}
"##
),
)

View file

@ -51,7 +51,7 @@ Here's an example of a simple C program that uses the Tree-sitter [JSON parser](
// Declare the `tree_sitter_json` function, which is
// implemented by the `tree-sitter-json` library.
extern const TSLanguage *tree_sitter_json();
const TSLanguage *tree_sitter_json(void);
int main() {
// Create a parser.
@ -326,9 +326,9 @@ Conceptually, it can be represented by three syntax trees with overlapping range
#include <tree_sitter/api.h>
// These functions are each implemented in their own repo.
extern const TSLanguage *tree_sitter_embedded_template();
extern const TSLanguage *tree_sitter_html();
extern const TSLanguage *tree_sitter_ruby();
const TSLanguage *tree_sitter_embedded_template(void);
const TSLanguage *tree_sitter_html(void);
const TSLanguage *tree_sitter_ruby(void);
int main(int argc, const char **argv) {
const char *text = argv[1];