From 4ccdac90ebd22bfbc28a167cea7d4239821ceb1a Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Tue, 7 Aug 2018 17:55:18 +0300 Subject: [PATCH 1/3] move all the definitions to a single header file --- src/node_iface.h | 45 ------------------------------------- src/nodes.h | 18 --------------- src/uast.h | 56 ++++++++++++++++++++++++++++++++++++++++++++--- tests/mock_node.h | 2 +- 4 files changed, 54 insertions(+), 67 deletions(-) delete mode 100644 src/node_iface.h delete mode 100644 src/nodes.h diff --git a/src/node_iface.h b/src/node_iface.h deleted file mode 100644 index c800393..0000000 --- a/src/node_iface.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef LIBUAST_NODE_IFACE_H_ -#define LIBUAST_NODE_IFACE_H_ - -#include -#include -#include - -typedef uintptr_t NodeHandle; - -// This interface must be implemented to create a Uast context. -typedef struct NodeIface { - const char *(*InternalType)(NodeHandle); - const char *(*Token)(NodeHandle); - - // Children - size_t (*ChildrenSize)(NodeHandle); - NodeHandle (*ChildAt)(NodeHandle, int); - - // Roles - size_t (*RolesSize)(NodeHandle); - uint16_t (*RoleAt)(NodeHandle, int); - - // Properties - size_t (*PropertiesSize)(NodeHandle); - const char *(*PropertyKeyAt)(NodeHandle, int); - const char *(*PropertyValueAt)(NodeHandle, int); - - // Postion - bool (*HasStartOffset)(NodeHandle); - uint32_t (*StartOffset)(NodeHandle); - bool (*HasStartLine)(NodeHandle); - uint32_t (*StartLine)(NodeHandle); - bool (*HasStartCol)(NodeHandle); - uint32_t (*StartCol)(NodeHandle); - - bool (*HasEndOffset)(NodeHandle); - uint32_t (*EndOffset)(NodeHandle); - bool (*HasEndLine)(NodeHandle); - uint32_t (*EndLine)(NodeHandle); - bool (*HasEndCol)(NodeHandle); - uint32_t (*EndCol)(NodeHandle); - -} NodeIface; - -#endif // LIBUAST_NODE_IFACE_H_ diff --git a/src/nodes.h b/src/nodes.h deleted file mode 100644 index 3a0027b..0000000 --- a/src/nodes.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef LIBUAST_NODES_H_ -#define LIBUAST_NODES_H_ - -#include "export.h" -#include "node_iface.h" - -typedef struct Nodes Nodes; - -// Returns the amount of nodes -EXPORT int NodesSize(const Nodes *nodes); - -// Returns the node at the given index. -EXPORT NodeHandle NodeAt(const Nodes *nodes, int index); - -// Releases the resources associated with nodes -EXPORT void NodesFree(Nodes *nodes); - -#endif // LIBUAST_NODES_H_ diff --git a/src/uast.h b/src/uast.h index 9c048fe..bca5088 100644 --- a/src/uast.h +++ b/src/uast.h @@ -1,13 +1,63 @@ #ifndef LIBUAST_UAST_H_ #define LIBUAST_UAST_H_ +#include "export.h" + +#include +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include "export.h" -#include "node_iface.h" -#include "nodes.h" +typedef uintptr_t NodeHandle; + +// This interface must be implemented to create a Uast context. +typedef struct NodeIface { + const char *(*InternalType)(NodeHandle); + const char *(*Token)(NodeHandle); + + // Children + size_t (*ChildrenSize)(NodeHandle); + NodeHandle (*ChildAt)(NodeHandle, int); + + // Roles + size_t (*RolesSize)(NodeHandle); + uint16_t (*RoleAt)(NodeHandle, int); + + // Properties + size_t (*PropertiesSize)(NodeHandle); + const char *(*PropertyKeyAt)(NodeHandle, int); + const char *(*PropertyValueAt)(NodeHandle, int); + + // Postion + bool (*HasStartOffset)(NodeHandle); + uint32_t (*StartOffset)(NodeHandle); + bool (*HasStartLine)(NodeHandle); + uint32_t (*StartLine)(NodeHandle); + bool (*HasStartCol)(NodeHandle); + uint32_t (*StartCol)(NodeHandle); + + bool (*HasEndOffset)(NodeHandle); + uint32_t (*EndOffset)(NodeHandle); + bool (*HasEndLine)(NodeHandle); + uint32_t (*EndLine)(NodeHandle); + bool (*HasEndCol)(NodeHandle); + uint32_t (*EndCol)(NodeHandle); + +} NodeIface; + +typedef struct Nodes Nodes; + +// Returns the amount of nodes +EXPORT int NodesSize(const Nodes *nodes); + +// Returns the node at the given index. +EXPORT NodeHandle NodeAt(const Nodes *nodes, int index); + +// Releases the resources associated with nodes +EXPORT void NodesFree(Nodes *nodes); // Uast stores the general context required for library functions. // It must be initialized with `UastNew` passing a valid implementation of the diff --git a/tests/mock_node.h b/tests/mock_node.h index d49d185..b75cdb1 100644 --- a/tests/mock_node.h +++ b/tests/mock_node.h @@ -8,7 +8,7 @@ #include #include -#include "node_iface.h" +#include "uast.h" struct position { int offset; From 24af518e82ee803814defa1510eeed292e20eb38 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Tue, 7 Aug 2018 18:27:28 +0300 Subject: [PATCH 2/3] pass context pointer to node interface Signed-off-by: Denys Smirnov --- examples/example.cc | 42 +++++++++++++++--------------- src/uast.cc | 62 ++++++++++++++++++++++----------------------- src/uast.h | 56 ++++++++++++++++++++-------------------- tests/mock_node.h | 42 +++++++++++++++--------------- tests/nodes_test.h | 12 ++++----- 5 files changed, 107 insertions(+), 107 deletions(-) diff --git a/examples/example.cc b/examples/example.cc index 90c0229..6219019 100644 --- a/examples/example.cc +++ b/examples/example.cc @@ -41,87 +41,87 @@ class Node { void SetEndPosition(position p) { end_position = p; } }; -static const char *InternalType(NodeHandle node) { +static const char *InternalType(const Uast* ctx, NodeHandle node) { return ((Node *)node)->internal_type.data(); } -static const char *Token(NodeHandle node) { +static const char *Token(const Uast* ctx, NodeHandle node) { return ((Node *)node)->token.data(); } -static size_t ChildrenSize(NodeHandle node) { +static size_t ChildrenSize(const Uast* ctx, NodeHandle node) { return ((Node *)node)->children.size(); } -static NodeHandle ChildAt(NodeHandle node, int index) { +static NodeHandle ChildAt(const Uast* ctx, NodeHandle node, int index) { return (NodeHandle)(((Node *)node)->children.at(index)); } -static size_t RolesSize(NodeHandle node) { +static size_t RolesSize(const Uast* ctx, NodeHandle node) { return ((Node *)node)->roles.size(); } -static uint16_t RoleAt(NodeHandle node, int index) { +static uint16_t RoleAt(const Uast* ctx, NodeHandle node, int index) { return ((Node *)node)->roles.at(index); } -static size_t PropertiesSize(NodeHandle node) { +static size_t PropertiesSize(const Uast* ctx, NodeHandle node) { return ((Node *)node)->properties.size(); } -static const char *PropertyKeyAt(NodeHandle node, int index) { +static const char *PropertyKeyAt(const Uast* ctx, NodeHandle node, int index) { return std::get<0>(((Node *)node)->properties.at(index)).data(); } -static const char *PropertyValueAt(NodeHandle node, int index) { +static const char *PropertyValueAt(const Uast* ctx, NodeHandle node, int index) { return std::get<1>(((Node *)node)->properties.at(index)).data(); } -static bool HasStartOffset(NodeHandle node) { +static bool HasStartOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position != NO_POSITION; } -static uint32_t StartOffset(NodeHandle node) { +static uint32_t StartOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.offset; } -static bool HasStartLine(NodeHandle node) { +static bool HasStartLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position != NO_POSITION; } -static uint32_t StartLine(NodeHandle node) { +static uint32_t StartLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.line; } -static bool HasStartCol(NodeHandle node) { +static bool HasStartCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position != NO_POSITION; } -static uint32_t StartCol(NodeHandle node) { +static uint32_t StartCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.col; } -static bool HasEndOffset(NodeHandle node) { +static bool HasEndOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position != NO_POSITION; } -static uint32_t EndOffset(NodeHandle node) { +static uint32_t EndOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position.offset; } -static bool HasEndLine(NodeHandle node) { +static bool HasEndLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position != NO_POSITION; } -static uint32_t EndLine(NodeHandle node) { +static uint32_t EndLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position.line; } -static bool HasEndCol(NodeHandle node) { +static bool HasEndCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position != NO_POSITION; } -static uint32_t EndCol(NodeHandle node) { +static uint32_t EndCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position.col; } diff --git a/src/uast.cc b/src/uast.cc index 682435b..8128c8a 100644 --- a/src/uast.cc +++ b/src/uast.cc @@ -400,7 +400,7 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, char buf[BUF_SIZE]; - const char *internal_type = ctx->iface.InternalType(node); + const char *internal_type = ctx->iface.InternalType(ctx, node); xmlNodePtr xmlNode = static_cast(xmlNewNode(nullptr, BAD_CAST(internal_type))); int children_size = 0; int roles_size = 0; @@ -419,7 +419,7 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, } // Token - token = ctx->iface.Token(node); + token = ctx->iface.Token(ctx, node); if (token) { if (!xmlNewProp(xmlNode, BAD_CAST("token"), BAD_CAST(token))) { throw CreateXMLNodeException(); @@ -427,9 +427,9 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, } // Roles - roles_size = ctx->iface.RolesSize(node); + roles_size = ctx->iface.RolesSize(ctx, node); for (int i = 0; i < roles_size; i++) { - uint16_t role = ctx->iface.RoleAt(node, i); + uint16_t role = ctx->iface.RoleAt(ctx, node, i); const char *role_name = RoleNameForId(role); if (role_name != nullptr) { if (!xmlNewProp(xmlNode, BAD_CAST(role_name), nullptr)) { @@ -439,17 +439,17 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, } // Properties - for (size_t i = 0; i < ctx->iface.PropertiesSize(node); i++) { - const char *key = ctx->iface.PropertyKeyAt(node, i); - const char *value = ctx->iface.PropertyValueAt(node, i); + for (size_t i = 0; i < ctx->iface.PropertiesSize(ctx, node); i++) { + const char *key = ctx->iface.PropertyKeyAt(ctx, node, i); + const char *value = ctx->iface.PropertyValueAt(ctx, node, i); if (!xmlNewProp(xmlNode, BAD_CAST(key), BAD_CAST(value))) { throw CreateXMLNodeException(); } } // Position - if (ctx->iface.HasStartOffset(node)) { - int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.StartOffset(node)); + if (ctx->iface.HasStartOffset(ctx, node)) { + int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.StartOffset(ctx, node)); if (ret < 0 || ret >= BUF_SIZE) { throw CreateXMLNodeException("Unable to set start offset\n"); } @@ -457,8 +457,8 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, throw CreateXMLNodeException(); } } - if (ctx->iface.HasStartLine(node)) { - int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.StartLine(node)); + if (ctx->iface.HasStartLine(ctx, node)) { + int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.StartLine(ctx, node)); if (ret < 0 || ret >= BUF_SIZE) { throw CreateXMLNodeException("Unable to start line\n"); } @@ -466,8 +466,8 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, throw CreateXMLNodeException(); } } - if (ctx->iface.HasStartCol(node)) { - int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.StartCol(node)); + if (ctx->iface.HasStartCol(ctx, node)) { + int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.StartCol(ctx, node)); if (ret < 0 || ret >= BUF_SIZE) { throw CreateXMLNodeException("Unable to start column\n"); } @@ -475,8 +475,8 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, throw CreateXMLNodeException(); } } - if (ctx->iface.HasEndOffset(node)) { - int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.EndOffset(node)); + if (ctx->iface.HasEndOffset(ctx, node)) { + int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.EndOffset(ctx, node)); if (ret < 0 || ret >= BUF_SIZE) { throw CreateXMLNodeException("Unable to set end offset\n"); } @@ -484,8 +484,8 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, throw CreateXMLNodeException(); } } - if (ctx->iface.HasEndLine(node)) { - int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.EndLine(node)); + if (ctx->iface.HasEndLine(ctx, node)) { + int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.EndLine(ctx, node)); if (ret < 0 || ret >= BUF_SIZE) { Error(nullptr, "Unable to set end line\n"); throw CreateXMLNodeException(); @@ -494,8 +494,8 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, throw CreateXMLNodeException(); } } - if (ctx->iface.HasEndCol(node)) { - int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.EndCol(node)); + if (ctx->iface.HasEndCol(ctx, node)) { + int ret = snprintf(buf, BUF_SIZE, "%" PRIu32, ctx->iface.EndCol(ctx, node)); if (ret < 0 || ret >= BUF_SIZE) { throw CreateXMLNodeException("Unable to set end column\n"); } @@ -505,9 +505,9 @@ static xmlNodePtr CreateXmlNode(const Uast *ctx, NodeHandle node, } // Recursivelly visit all children - children_size = ctx->iface.ChildrenSize(node); + children_size = ctx->iface.ChildrenSize(ctx, node); for (int i = 0; i < children_size; i++) { - NodeHandle child = ctx->iface.ChildAt(node, i); + NodeHandle child = ctx->iface.ChildAt(ctx, node, i); if (!CreateXmlNode(ctx, child, xmlNode)) { throw CreateXMLNodeException(); } @@ -549,7 +549,7 @@ static NodeHandle transformChildAt(UastIterator *iter, NodeHandle parent, size_t assert(iter); assert(parent); - auto child = iter->ctx->iface.ChildAt(parent, pos); + auto child = iter->ctx->iface.ChildAt(iter->ctx, parent, pos); return iter->nodeTransform ? iter->nodeTransform(child): child; } @@ -560,7 +560,7 @@ static bool Visited(UastIterator *iter, NodeHandle node) { const bool visited = iter->visited.find(node) != iter->visited.end(); if(!visited) { - int children_size = iter->ctx->iface.ChildrenSize(node); + int children_size = iter->ctx->iface.ChildrenSize(iter->ctx, node); for (int i = children_size - 1; i >= 0; i--) { iter->pending.push_front(transformChildAt(iter, node, i)); } @@ -580,7 +580,7 @@ static NodeHandle PreOrderNext(UastIterator *iter) { return 0; } - int children_size = iter->ctx->iface.ChildrenSize(retNode); + int children_size = iter->ctx->iface.ChildrenSize(iter->ctx, retNode); for (int i = children_size - 1; i >= 0; i--) { iter->pending.push_front(transformChildAt(iter, retNode, i)); } @@ -597,7 +597,7 @@ static NodeHandle LevelOrderNext(UastIterator *iter) { return 0; } - int children_size = iter->ctx->iface.ChildrenSize(retNode); + int children_size = iter->ctx->iface.ChildrenSize(iter->ctx, retNode); for (int i = 0; i < children_size; i++) { iter->pending.push_back(transformChildAt(iter, retNode, i)); } @@ -636,15 +636,15 @@ static void sortPendingByPosition(UastIterator *iter) { std::sort(iter->pending.begin(), iter->pending.end(), [&iter](NodeHandle i, NodeHandle j) { auto ic = iter->ctx->iface; - if (ic.HasStartOffset(i) && ic.HasStartOffset(j)) { - return ic.StartOffset(i) < ic.StartOffset(j); + if (ic.HasStartOffset(iter->ctx, i) && ic.HasStartOffset(iter->ctx, j)) { + return ic.StartOffset(iter->ctx, i) < ic.StartOffset(iter->ctx, j); } // Continue: some didn't have offset, check by line/col - auto firstLine = ic.HasStartLine(i) ? ic.StartLine(i) : 0; - auto firstCol = ic.HasStartCol(i) ? ic.StartCol(i) : 0; - auto secondLine = ic.HasStartLine(j) ? ic.StartLine(j) : 0; - auto secondCol = ic.HasStartCol(j) ? ic.StartCol(j) : 0; + auto firstLine = ic.HasStartLine(iter->ctx, i) ? ic.StartLine(iter->ctx, i) : 0; + auto firstCol = ic.HasStartCol(iter->ctx, i) ? ic.StartCol(iter->ctx, i) : 0; + auto secondLine = ic.HasStartLine(iter->ctx, j) ? ic.StartLine(iter->ctx, j) : 0; + auto secondCol = ic.HasStartCol(iter->ctx, j) ? ic.StartCol(iter->ctx, j) : 0; if (firstLine == secondLine) { return firstCol < secondCol; diff --git a/src/uast.h b/src/uast.h index bca5088..976d063 100644 --- a/src/uast.h +++ b/src/uast.h @@ -11,40 +11,46 @@ extern "C" { #endif +// Uast stores the general context required for library functions. +// It must be initialized with `UastNew` passing a valid implementation of the +// `NodeIface` interface. +// Once it is not used anymore, it shall be released calling `UastFree`. +typedef struct Uast Uast; + typedef uintptr_t NodeHandle; // This interface must be implemented to create a Uast context. typedef struct NodeIface { - const char *(*InternalType)(NodeHandle); - const char *(*Token)(NodeHandle); + const char *(*InternalType)(const Uast*, NodeHandle); + const char *(*Token)(const Uast*, NodeHandle); // Children - size_t (*ChildrenSize)(NodeHandle); - NodeHandle (*ChildAt)(NodeHandle, int); + size_t (*ChildrenSize)(const Uast*, NodeHandle); + NodeHandle (*ChildAt)(const Uast*, NodeHandle, int); // Roles - size_t (*RolesSize)(NodeHandle); - uint16_t (*RoleAt)(NodeHandle, int); + size_t (*RolesSize)(const Uast*, NodeHandle); + uint16_t (*RoleAt)(const Uast*, NodeHandle, int); // Properties - size_t (*PropertiesSize)(NodeHandle); - const char *(*PropertyKeyAt)(NodeHandle, int); - const char *(*PropertyValueAt)(NodeHandle, int); + size_t (*PropertiesSize)(const Uast*, NodeHandle); + const char *(*PropertyKeyAt)(const Uast*, NodeHandle, int); + const char *(*PropertyValueAt)(const Uast*, NodeHandle, int); // Postion - bool (*HasStartOffset)(NodeHandle); - uint32_t (*StartOffset)(NodeHandle); - bool (*HasStartLine)(NodeHandle); - uint32_t (*StartLine)(NodeHandle); - bool (*HasStartCol)(NodeHandle); - uint32_t (*StartCol)(NodeHandle); - - bool (*HasEndOffset)(NodeHandle); - uint32_t (*EndOffset)(NodeHandle); - bool (*HasEndLine)(NodeHandle); - uint32_t (*EndLine)(NodeHandle); - bool (*HasEndCol)(NodeHandle); - uint32_t (*EndCol)(NodeHandle); + bool (*HasStartOffset)(const Uast*, NodeHandle); + uint32_t (*StartOffset)(const Uast*, NodeHandle); + bool (*HasStartLine)(const Uast*, NodeHandle); + uint32_t (*StartLine)(const Uast*, NodeHandle); + bool (*HasStartCol)(const Uast*, NodeHandle); + uint32_t (*StartCol)(const Uast*, NodeHandle); + + bool (*HasEndOffset)(const Uast*, NodeHandle); + uint32_t (*EndOffset)(const Uast*, NodeHandle); + bool (*HasEndLine)(const Uast*, NodeHandle); + uint32_t (*EndLine)(const Uast*, NodeHandle); + bool (*HasEndCol)(const Uast*, NodeHandle); + uint32_t (*EndCol)(const Uast*, NodeHandle); } NodeIface; @@ -59,12 +65,6 @@ EXPORT NodeHandle NodeAt(const Nodes *nodes, int index); // Releases the resources associated with nodes EXPORT void NodesFree(Nodes *nodes); -// Uast stores the general context required for library functions. -// It must be initialized with `UastNew` passing a valid implementation of the -// `NodeIface` interface. -// Once it is not used anymore, it shall be released calling `UastFree`. -typedef struct Uast Uast; - // An UastIterator is used to keep the state of the current iteration over the tree. // It's initialized with UastIteratorNew, used with UastIteratorNext and freed // with UastIteratorFree. diff --git a/tests/mock_node.h b/tests/mock_node.h index b75cdb1..9efc70f 100644 --- a/tests/mock_node.h +++ b/tests/mock_node.h @@ -48,87 +48,87 @@ class Node { void SetEndPosition(position p) { end_position = p; } }; -static const char *InternalType(NodeHandle node) { +static const char *InternalType(const Uast* ctx, NodeHandle node) { return ((Node *)node)->internal_type.data(); } -static const char *Token(NodeHandle node) { +static const char *Token(const Uast* ctx, NodeHandle node) { return ((Node *)node)->token.data(); } -static size_t ChildrenSize(NodeHandle node) { +static size_t ChildrenSize(const Uast* ctx, NodeHandle node) { return ((Node *)node)->children.size(); } -static NodeHandle ChildAt(NodeHandle node, int index) { +static NodeHandle ChildAt(const Uast* ctx, NodeHandle node, int index) { return (NodeHandle)(((Node *)node)->children.at(index)); } -static size_t RolesSize(NodeHandle node) { +static size_t RolesSize(const Uast* ctx, NodeHandle node) { return ((Node *)node)->roles.size(); } -static uint16_t RoleAt(NodeHandle node, int index) { +static uint16_t RoleAt(const Uast* ctx, NodeHandle node, int index) { return ((Node *)node)->roles.at(index); } -static size_t PropertiesSize(NodeHandle node) { +static size_t PropertiesSize(const Uast* ctx, NodeHandle node) { return ((Node *)node)->properties.size(); } -static const char *PropertyKeyAt(NodeHandle node, int index) { +static const char *PropertyKeyAt(const Uast* ctx, NodeHandle node, int index) { return std::get<0>(((Node *)node)->properties.at(index)).data(); } -static const char *PropertyValueAt(NodeHandle node, int index) { +static const char *PropertyValueAt(const Uast* ctx, NodeHandle node, int index) { return std::get<1>(((Node *)node)->properties.at(index)).data(); } -static bool HasStartOffset(NodeHandle node) { +static bool HasStartOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.offset != -1; } -static uint32_t StartOffset(NodeHandle node) { +static uint32_t StartOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.offset; } -static bool HasStartLine(NodeHandle node) { +static bool HasStartLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.line != -1; } -static uint32_t StartLine(NodeHandle node) { +static uint32_t StartLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.line; } -static bool HasStartCol(NodeHandle node) { +static bool HasStartCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.col != -1; } -static uint32_t StartCol(NodeHandle node) { +static uint32_t StartCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->start_position.col; } -static bool HasEndOffset(NodeHandle node) { +static bool HasEndOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position != NO_POSITION; } -static uint32_t EndOffset(NodeHandle node) { +static uint32_t EndOffset(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position.offset; } -static bool HasEndLine(NodeHandle node) { +static bool HasEndLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position != NO_POSITION; } -static uint32_t EndLine(NodeHandle node) { +static uint32_t EndLine(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position.line; } -static bool HasEndCol(NodeHandle node) { +static bool HasEndCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position != NO_POSITION; } -static uint32_t EndCol(NodeHandle node) { +static uint32_t EndCol(const Uast* ctx, NodeHandle node) { return ((Node *)node)->end_position.col; } diff --git a/tests/nodes_test.h b/tests/nodes_test.h index 78a3531..346b0e6 100644 --- a/tests/nodes_test.h +++ b/tests/nodes_test.h @@ -146,7 +146,7 @@ void TestUastFilterStartOffset() { Node *node = (Node *)NodeAt(nodes, 0); CU_ASSERT_FATAL(node->internal_type == "Module"); - CU_ASSERT_FATAL(HasStartOffset(NodeHandle(node))); + CU_ASSERT_FATAL(HasStartOffset(ctx, NodeHandle(node))); NodesFree(nodes); UastFree(ctx); @@ -161,7 +161,7 @@ void TestUastFilterStartLine() { Node *node = (Node *)NodeAt(nodes, 0); CU_ASSERT_FATAL(node->internal_type == "Module"); - CU_ASSERT_FATAL(HasStartLine(NodeHandle(node))); + CU_ASSERT_FATAL(HasStartLine(ctx, NodeHandle(node))); NodesFree(nodes); UastFree(ctx); @@ -176,7 +176,7 @@ void TestUastFilterStartCol() { Node *node = (Node *)NodeAt(nodes, 0); CU_ASSERT_FATAL(node->internal_type == "Module"); - CU_ASSERT_FATAL(HasStartCol(NodeHandle(node))); + CU_ASSERT_FATAL(HasStartCol(ctx, NodeHandle(node))); NodesFree(nodes); UastFree(ctx); @@ -191,7 +191,7 @@ void TestUastFilterEndOffset() { Node *node = (Node *)NodeAt(nodes, 0); CU_ASSERT_FATAL(node->internal_type == "Module"); - CU_ASSERT_FATAL(HasEndOffset(NodeHandle(node))); + CU_ASSERT_FATAL(HasEndOffset(ctx, NodeHandle(node))); NodesFree(nodes); UastFree(ctx); @@ -206,7 +206,7 @@ void TestUastFilterEndLine() { Node *node = (Node *)NodeAt(nodes, 0); CU_ASSERT_FATAL(node->internal_type == "Module"); - CU_ASSERT_FATAL(HasEndLine(NodeHandle(node))); + CU_ASSERT_FATAL(HasEndLine(ctx, NodeHandle(node))); NodesFree(nodes); UastFree(ctx); @@ -221,7 +221,7 @@ void TestUastFilterEndCol() { Node *node = (Node *)NodeAt(nodes, 0); CU_ASSERT_FATAL(node->internal_type == "Module"); - CU_ASSERT_FATAL(HasEndCol(NodeHandle(node))); + CU_ASSERT_FATAL(HasEndCol(ctx, NodeHandle(node))); NodesFree(nodes); UastFree(ctx); From 507eabf3a0ca9ff5f8b724b2f729fd86bc621fee Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Tue, 7 Aug 2018 20:14:37 +0300 Subject: [PATCH 3/3] update cmake files Signed-off-by: Denys Smirnov --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18417a0..97a7498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,9 +42,7 @@ set(libsrc set(libinclude ${CMAKE_SOURCE_DIR}/src/export.h ${CMAKE_SOURCE_DIR}/src/uast.h - ${CMAKE_SOURCE_DIR}/src/roles.h - ${CMAKE_SOURCE_DIR}/src/node_iface.h - ${CMAKE_SOURCE_DIR}/src/nodes.h) + ${CMAKE_SOURCE_DIR}/src/roles.h) # Dependencies set(libdep ${LIBXML2_LIBRARIES})