OR-1 dataflow CPU sketch
1#ifndef NODE_TREE_SITTER_TREE_H_
2#define NODE_TREE_SITTER_TREE_H_
3
4#include "./addon_data.h"
5#include "tree_sitter/api.h"
6
7#include <napi.h>
8#include <node_object_wrap.h>
9#include <unordered_map>
10
11namespace node_tree_sitter {
12
13class Tree final : public Napi::ObjectWrap<Tree> {
14 public:
15 static void Init(Napi::Env env, Napi::Object exports);
16 static Napi::Value NewInstance(Napi::Env env, TSTree *tree);
17 static const Tree *UnwrapTree(const Napi::Value &value);
18
19 explicit Tree(const Napi::CallbackInfo &);
20 ~Tree() final;
21
22 struct NodeCacheEntry {
23 Tree *tree;
24 const void *key;
25 Napi::ObjectReference node;
26 };
27
28 TSTree *tree_;
29 std::unordered_map<const void *, NodeCacheEntry *> cached_nodes_;
30
31 private:
32 Napi::Value Edit(const Napi::CallbackInfo &info);
33 Napi::Value RootNode(const Napi::CallbackInfo &info);
34 Napi::Value RootNodeWithOffset(const Napi::CallbackInfo &info);
35 Napi::Value PrintDotGraph(const Napi::CallbackInfo &info);
36 Napi::Value GetEditedRange(const Napi::CallbackInfo &info);
37 Napi::Value GetChangedRanges(const Napi::CallbackInfo &info);
38 Napi::Value GetIncludedRanges(const Napi::CallbackInfo &info);
39 Napi::Value CacheNode(const Napi::CallbackInfo &info);
40 Napi::Value CacheNodes(const Napi::CallbackInfo &info);
41};
42
43} // namespace node_tree_sitter
44
45#endif // NODE_TREE_SITTER_TREE_H_