Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 2d68ea5

Browse files
committed
split node_gen.h into thin header and fat impl
1 parent 263a239 commit 2d68ea5

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ node_modules/
33
package-lock.json
44
build-convert/target
55
build-convert/Cargo.lock
6-
convert_gen.h
6+
node.h
7+
node.cc
78

89
lib-ruby-parser.a
910
lib-ruby-parser.h

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"diagnostic.cc",
1212
"comment.cc",
1313
"magic_comment.cc",
14+
"node.cc",
1415
"parser_result.cc",
1516
],
1617
"include_dirs": [

build-convert/build.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ fn init_exports(node: &Node) -> String {
101101
}
102102

103103
fn main() {
104-
let path = relative_path("../convert_gen.h");
105104
let nodes = lib_ruby_parser_nodes::nodes();
106105

107106
let ctor_definitions: Vec<String> = nodes.iter().map(ctor_definition).collect();
@@ -111,24 +110,38 @@ fn main() {
111110
let comparisons: Vec<String> = nodes.iter().map(build_comparison).collect();
112111
let init_exports: Vec<String> = nodes.iter().map(init_exports).collect();
113112

114-
let contents = format!(
115-
"#ifndef LIB_RUBY_PARSER_CONVERT_GEN_H
116-
#define LIB_RUBY_PARSER_CONVERT_GEN_H
113+
let node_h = format!(
114+
"#ifndef LIB_RUBY_PARSER_NODE_NODE_H
115+
#define LIB_RUBY_PARSER_NODE_NODE_H
117116
118117
#include <napi.h>
119118
#include \"lib-ruby-parser.h\"
120119
121-
template<class> inline constexpr bool always_false_v = false;
120+
namespace lib_ruby_parser_node
121+
{{
122+
123+
Napi::Value convert(std::unique_ptr<lib_ruby_parser::Node> node, Napi::Env env);
124+
void InitNodeTypes(Napi::Env env, Napi::Object exports);
125+
126+
}} // namespace lib_ruby_parser_node
127+
128+
#endif // LIB_RUBY_PARSER_NODE_NODE_H
129+
"
130+
);
131+
132+
let node_cc = format!(
133+
"#include \"node.h\"
134+
#include \"loc.h\"
135+
#include \"bytes.h\"
122136
123137
namespace lib_ruby_parser_node
124138
{{
125139
{ctor_definitions}
140+
126141
{ctor_fn_definitions}
127142
128143
Napi::Value convert(std::unique_ptr<lib_ruby_parser::Node> node, Napi::Env env);
129144
Napi::Value convert(lib_ruby_parser::Node node, Napi::Env env);
130-
Napi::Value convert(std::unique_ptr<lib_ruby_parser::Loc> loc, Napi::Env env);
131-
Napi::Value convert(lib_ruby_parser::Bytes bytes, Napi::Env env);
132145
133146
Napi::Value convert(std::string s, Napi::Env env)
134147
{{
@@ -177,8 +190,6 @@ namespace lib_ruby_parser_node
177190
{init_exports}
178191
}}
179192
}} // namespace lib_ruby_parser_node
180-
181-
#endif // LIB_RUBY_PARSER_CONVERT_GEN_H
182193
",
183194
converters = converters.join("\n "),
184195
comparisons = comparisons.join("\n "),
@@ -187,5 +198,6 @@ namespace lib_ruby_parser_node
187198
init_exports = init_exports.join("\n ")
188199
);
189200

190-
std::fs::write(&path, &contents).unwrap();
201+
std::fs::write("../node.h", &node_h).unwrap();
202+
std::fs::write("../node.cc", &node_cc).unwrap();
191203
}

node_bindings.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "comment.h"
1313
#include "magic_comment.h"
1414
#include "parser_result.h"
15+
#include "node.h"
1516

1617
namespace lib_ruby_parser_node
1718
{

parser_result.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "parser_result.h"
2-
#include "convert_gen.h"
2+
#include "node.h"
33
#include "token.h"
44
#include "diagnostic.h"
55
#include "comment.h"

0 commit comments

Comments
 (0)