Skip to content

Commit 806b870

Browse files
committed
Apply skip_symbol? check to macro definitions for consistency with variables.
Macro constants and variable constants both render the same "constant" template, but macros lacked the skip check that variables have via visit_variable. cursor.spelling works correctly for macro cursors so skip_symbol? applies cleanly.
1 parent 755e17c commit 806b870

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

lib/ruby-bindgen/generators/rice/rice.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ def visit_macro_definition(cursor)
17291729
return unless tokens.size == 2
17301730
return unless tokens.tokens[0].kind == :identifier
17311731
return unless tokens.tokens[1].kind == :literal
1732+
return if skip_symbol?(cursor)
17321733

17331734
self.render_cursor(cursor, "constant",
17341735
:name => tokens.tokens[0].spelling.upcase_first,

test/bindings/cpp/version_guards-rb.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ using namespace Rice;
99

1010
void Init_VersionGuards()
1111
{
12+
Class(rb_cObject).define_constant("INCLUDED_MACRO", INCLUDED_MACRO);
13+
1214
Module rb_mGuards = define_module("Guards");
1315

1416
Rice::Data_Type<Guards::MyClass> rb_cGuardsMyClass = define_class_under<Guards::MyClass>(rb_mGuards, "MyClass")

test/headers/cpp/version_guards.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#pragma once
22

3+
// Macro constants — SKIPPED_MACRO should be filtered via symbols
4+
#define INCLUDED_MACRO 100
5+
#define SKIPPED_MACRO 999
6+
37
namespace Guards
48
{
59
// Class with methods, constructors, and anonymous enum constants

test/rice_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def test_mappings
107107
def test_version_guards
108108
run_rice_test("version_guards.hpp",
109109
version_check: "TEST_VERSION",
110-
symbols: { versions: {
110+
symbols: { skip: ["SKIPPED_MACRO"],
111+
versions: {
111112
20000 => ["Guards::MyClass::newMethod",
112113
"Guards::MyClass::NEW_CONST",
113114
"Guards::MyClass::overloaded(int, bool)",

0 commit comments

Comments
 (0)