Skip to content

Move the operators to ast/ and classify them by trait - #1552

Open
trueqbit wants to merge 9 commits into
devfrom
refactor/operators-under-ast
Open

trueqbit wants to merge 9 commits into
devfrom
refactor/operators-under-ast

Conversation

@trueqbit

Copy link
Copy Markdown
Collaborator

Stacked on #1551.

Summary

column_result_t pattern-matched each of the eleven operator aliases (conc_t, add_t … bitwise_or_t, unary_minus_t, bitwise_not_t), is_assign_v and is_chainable_operand_v were defined by pattern specializations on assign_t and conc_t - the style the vocabulary document rules out -, and the unary operators had no trait at all.

  • dev/operators.h moves to dev/ast/operators.h, and takes in the arithmetic and bitwise operator overloads (-x, +, -, *, /, %, ~, <<, >>, &, |) from core_functions.h, where they had no business.
  • Each operator's tag (add_string, …) declares the C++ type the operator yields as its result_type, which the operator node inherits. column_result_t reads it through result_type_t for all binary and unary operators - twelve specializations become one.
  • New grammar traits is_unary_operator and is_conc. is_assign becomes an extern declaration with one closed definition, like is_conc: a binary operator carrying the respective tag - checked on a binary operator only, since a std::tuple of tags derives from them too. is_chainable_operand_v gains a SFINAE parameter and is enabled on is_conc.
  • ast_iterator, node_tuple and statement_serializer match the unary operators by trait.
  • Fix: ast_iterator had a specialization for bitwise_not_t but none for unary_minus_t, which was thus visited as a leaf - the values bound and the table referenced below a unary minus were missed.

Test plan

  • tests/static_tests/expression_classification.cpp: new "operators" section - is_unary_operator, is_conc, is_assign positive and negative (including tuples of tags), is_chainable_operand, the result_type of concatenation, arithmetic, bitwise and unary operators, and the node tuple of a unary minus.
  • tests/ast_iterator_tests.cpp: new "unary operators" section - the operand of a unary minus and of a bitwise not is visited.
  • tests/static_tests/operators_adl.cpp and the operator serializer tests cover the moved overloads.

🤖 Generated with Claude Code

column_result_t pattern-matched each of the eleven arithmetic, bitwise and
concatenation operator aliases, `is_assign_v` and `is_chainable_operand_v`
were pattern specializations on `assign_t` and `conc_t`, and the unary
operators had no trait - so ast_iterator never descended into a unary
minus.

- operators.h moves to ast/ and takes in the arithmetic and bitwise
  operator overloads from core_functions.h.
- Each operator's tag declares the C++ type the operator yields as its
  `result_type`, which the operator node inherits; column_result_t reads
  it through the projection for all binary and unary operators alike.
- New grammar traits `is_unary_operator` and `is_conc`; `is_assign` is one
  closed definition like `is_conc`, a binary operator carrying the tag;
  `is_chainable_operand_v` gets a SFINAE parameter and is enabled on
  `is_conc`.
- ast_iterator, node_tuple and statement_serializer match the unary
  operators by trait. Fix: a unary minus is now walked into like the
  bitwise not already was, so the values bound and the tables referenced
  below it are no longer missed.

Co-Authored-By: Claude Opus 5.5
@trueqbit
trueqbit force-pushed the refactor/consolidate-joins branch from 50bd6b0 to 117f9f4 Compare September 28, 2026 17:00
@trueqbit
trueqbit force-pushed the refactor/operators-under-ast branch from 7732cd7 to 70022e6 Compare September 28, 2026 17:00
…er-ast

dev (#1558) moved the overloaded arithmetic and bitwise operators from
core.h into operators.h, as this branch did when moving operators.h to
ast/operators.h; both sides appended the same block, which is kept once.

Resolved:
- ast/operators.h keeps this branch's includes, relative to ast/.
- core_functions.h, from which this branch took the operators, is gone on
  dev, replaced by builtin/functions/.

Co-Authored-By: Claude Opus 5.5
@trueqbit
trueqbit changed the base branch from refactor/consolidate-joins to dev October 7, 2026 10:42
@trueqbit
trueqbit marked this pull request as ready for review October 7, 2026 18:57
@trueqbit
trueqbit requested a review from fnc12 October 11, 2026 12:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant