Feb 15th 2023 update

This commit is contained in:
Ned Wright
2023-02-15 19:09:38 +00:00
parent f7934cd09d
commit 6a9b33ff93
159 changed files with 16474 additions and 2096 deletions

3
external/graphqlparser/c/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
GraphQLAst.h
GraphQLAst.cpp
GraphQLAstForEachConcreteType.h

View File

@@ -0,0 +1,25 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "GraphQLAstNode.h"
#include "../AstNode.h"
using facebook::graphql::ast::Node;
void graphql_node_get_location(const struct GraphQLAstNode *node,
struct GraphQLAstLocation *location) {
const auto *realNode = reinterpret_cast<const Node *>(node);
const auto &loc = realNode->getLocation();
location->beginLine = loc.begin.line;
location->beginColumn = loc.begin.column;
location->endLine = loc.end.line;
location->endColumn = loc.end.column;
}
void graphql_node_free(struct GraphQLAstNode *node) {
delete reinterpret_cast<Node *>(node);
}

View File

@@ -0,0 +1,33 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Opaque type representing a generic AST node. */
struct GraphQLAstNode;
/* A location in the AST. */
struct GraphQLAstLocation {
unsigned int beginLine;
unsigned int beginColumn;
unsigned int endLine;
unsigned int endColumn;
};
/* Fills location with location information for the given node. */
void graphql_node_get_location(const struct GraphQLAstNode *node,
struct GraphQLAstLocation *location);
void graphql_node_free(struct GraphQLAstNode *node);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,21 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "GraphQLAstToJSON.h"
#include <cstring>
#include "../JsonVisitor.h"
#include "../AstNode.h"
const char *graphql_ast_to_json(const struct GraphQLAstNode *node)
{
facebook::graphql::ast::visitor::JsonVisitor visitor;
reinterpret_cast<const facebook::graphql::ast::Node *>(node)->accept(&visitor);
return strdup(visitor.getResult().c_str());
}

View File

@@ -0,0 +1,24 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
struct GraphQLAstNode;
/**
* Serialize the given AST to JSON. The returned C string must be
* freed with free().
*/
const char *graphql_ast_to_json(const struct GraphQLAstNode *node);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,55 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "c/GraphQLAstVisitor.h"
#include "AstVisitor.h"
using namespace facebook::graphql::ast; // NOLINT
#include "c/GraphQLAstForEachConcreteType.h"
#define DECLARE_VISIT(type, snake_type) \
bool visit##type(const type &node) override; \
void endVisit##type(const type &node) override;
class CVisitorBridge : public visitor::AstVisitor {
const struct GraphQLAstVisitorCallbacks *callbacks_;
void *userData_;
public:
explicit CVisitorBridge(const struct GraphQLAstVisitorCallbacks *callbacks,
void *userData)
: callbacks_(callbacks), userData_(userData) {}
FOR_EACH_CONCRETE_TYPE(DECLARE_VISIT)
};
#define IMPLEMENT_VISIT(type, snake_type) \
bool CVisitorBridge::visit##type(const type &node) { \
if (callbacks_->visit_##snake_type) { \
return callbacks_->visit_##snake_type( \
(const struct GraphQLAst##type *)&node, userData_); \
} \
return true; \
} \
void CVisitorBridge::endVisit##type(const type &node) { \
if (callbacks_->end_visit_##snake_type) { \
callbacks_->end_visit_##snake_type( \
(const struct GraphQLAst##type *)&node, userData_); \
} \
}
FOR_EACH_CONCRETE_TYPE(IMPLEMENT_VISIT)
void graphql_node_visit(const struct GraphQLAstNode *node,
const struct GraphQLAstVisitorCallbacks *callbacks,
void *userData)
{
CVisitorBridge visitor(callbacks, userData);
if (node) {
reinterpret_cast<const facebook::graphql::ast::Node *>(node)->accept(&visitor);
}
}

View File

@@ -0,0 +1,53 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include "c/GraphQLAst.h"
#include "c/GraphQLAstForEachConcreteType.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TYPEDEFS(type, snake_type) \
typedef int (*visit_##snake_type##_func)(const struct GraphQLAst##type *snake_type, void *user_data); \
typedef void (*end_visit_##snake_type##_func)(const struct GraphQLAst##type *snake_type, void *user_data);
FOR_EACH_CONCRETE_TYPE(TYPEDEFS)
#define FUNC_MEMBER(type, snake_type) \
visit_##snake_type##_func visit_##snake_type; \
end_visit_##snake_type##_func end_visit_##snake_type;
/**
* Functions to be called when particular AST nodes are encountered.
* visit_* functions are called in pre-order, and may return non-zero to
* continue recursing into children (if any), or zero to skip them. end_visit_*
* functions are called in post-order. Any particular function may be set to
* NULL to indicate that the caller is not interested in the corresponding type
* of AST node. (NULL visit_* functions act as though they simply returned
* non-zero.)
*/
struct GraphQLAstVisitorCallbacks {
FOR_EACH_CONCRETE_TYPE(FUNC_MEMBER)
};
struct GraphQLAstNode;
/**
* Walk the AST rooted at the given node, issuing callbacks from the given
* callbacks struct as appropriate. userData will be passed as the userData
* argument to each callback.
*/
void graphql_node_visit(const struct GraphQLAstNode *node,
const struct GraphQLAstVisitorCallbacks *callbacks,
void *userData);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,35 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "GraphQLParser.h"
#include "../GraphQLParser.h"
#include "../AstNode.h"
#include <cstdlib>
struct GraphQLAstNode *graphql_parse_string(const char *text, const char **error) {
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseString(text, error).release());
}
struct GraphQLAstNode *graphql_parse_string_with_experimental_schema_support(
const char *text, const char **error) {
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseStringWithExperimentalSchemaSupport(
text, error).release());
}
struct GraphQLAstNode *graphql_parse_file(FILE *file, const char **error) {
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseFile(file, error).release());
}
struct GraphQLAstNode *graphql_parse_file_with_experimental_schema_support(
FILE *file, const char **error) {
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseFileWithExperimentalSchemaSupport(file, error).release());
}
void graphql_error_free(const char *error) {
std::free((void *)(error)); // NOLINT
}

View File

@@ -0,0 +1,54 @@
/**
* Copyright 2019-present, GraphQL Foundation
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* This file provides C wrappers for ../GraphQLParser.h.
*/
struct GraphQLAstNode;
/**
* Parse the given GraphQL source string, returning an AST. Returns
* NULL on error. Return value must be freed with
* graphql_node_free(). If NULL is returned and error is not NULL, an
* error message is placed in error and must be freed with
* graphql_error_free().
*/
struct GraphQLAstNode *graphql_parse_string(
const char *text, const char **error);
struct GraphQLAstNode *graphql_parse_string_with_experimental_schema_support(
const char *text, const char **error);
/**
* Read and parse GraphQL source from the given file, returning an
* AST. Returns nullptr on error. Return value must be freed with
* graphql_node_free(). If NULL is returned and error is not NULL, an
* error message is placed in error and must be freed with
* graphql_error_free().
*/
struct GraphQLAstNode *graphql_parse_file(FILE *file, const char **error);
struct GraphQLAstNode *graphql_parse_file_with_experimental_schema_support(
FILE *file, const char **error);
/**
* Frees an error.
*/
void graphql_error_free(const char *error);
#ifdef __cplusplus
}
#endif