Skip to content

feat(tdl): Add support for tracking the source location in AST nodes. - #199

Merged
LinZhihao-723 merged 1 commit into
y-scope:mainfrom
LinZhihao-723:ast-source-location
Aug 18, 2025
Merged

feat(tdl): Add support for tracking the source location in AST nodes.#199
LinZhihao-723 merged 1 commit into
y-scope:mainfrom
LinZhihao-723:ast-source-location

Conversation

@LinZhihao-723

@LinZhihao-723 LinZhihao-723 commented Aug 18, 2025

Copy link
Copy Markdown
Member

Description

This PR adds support for tracking the source location in AST nodes by storing a SourceLocation instance in each AST node. All node implementations are updated to accept a source location through the factory function.

This PR doesn't update the serialization methods to include the source information. We will update this in a future PR to avoid making this PR too long.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Ensure all workflows pass.

Summary by CodeRabbit

  • New Features

    • AST nodes now carry source location (line/column) data, enabling more precise diagnostics and tooling feedback.
    • Creation APIs accept location details, expanding the public surface for location-aware workflows.
  • Documentation

    • Updated API references to include and describe the new location parameter.
  • Tests

    • Test suite updated to validate end-to-end propagation of source locations across nodes and containers.

@LinZhihao-723
LinZhihao-723 requested review from a team and sitaowang1998 as code owners August 18, 2025 19:31
@coderabbitai

coderabbitai Bot commented Aug 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Introduces SourceLocation across the AST: adds a new SourceLocation class, threads it into Node and all derived nodes via constructors and create() APIs, updates CMake to expose the header, adjusts base Type/Primitive/Container classes, and revises tests to use the new location-aware factories.

Changes

Cohort / File(s) Summary
Build/Public API Exposure
src/spider/CMakeLists.txt
Adds tdl/parser/ast/SourceLocation.hpp to public headers.
Core AST Base and Utilities
src/spider/tdl/parser/ast/SourceLocation.hpp, src/spider/tdl/parser/ast/Node.hpp, src/spider/tdl/parser/ast/utils.hpp
Adds SourceLocation class; Node now stores SourceLocation and requires it in constructor; adds accessor; includes string_view header in utils.
General AST Nodes
src/spider/tdl/parser/ast/node_impl/Function.*, .../Identifier.hpp, .../NamedVar.*, .../Namespace.*, .../StructSpec.*
Each node’s create() gains a SourceLocation parameter; constructors changed to forward SourceLocation to base Node; includes updated accordingly.
Type Hierarchy Bases
src/spider/tdl/parser/ast/node_impl/Type.hpp, .../type_impl/Container.hpp, .../type_impl/Primitive.hpp
Introduces protected explicit constructors taking SourceLocation; forwards to base classes (Node/Type).
Container Types
.../type_impl/container_impl/List.*, .../type_impl/container_impl/Map.*, .../type_impl/container_impl/Tuple.*
create() signatures now accept SourceLocation; private constructors require SourceLocation and forward to Container; Map adds public ErrorCode enum alias.
Primitive Types
.../type_impl/primitive_impl/Bool.hpp, .../type_impl/primitive_impl/Float.hpp, .../type_impl/primitive_impl/Int.hpp
Factories now take SourceLocation; constructors updated to forward SourceLocation to Primitive; includes added.
Tests
tests/tdl/test-parser-ast.cpp
Updates all AST node creations to pass SourceLocation; adds helper to produce a location; imports SourceLocation.

Sequence Diagram(s)

sequenceDiagram
  participant Parser
  participant Factories as Node Factories
  participant Node as AST Node
  participant Base as Base Classes (Node/Type/Primitive/Container)

  Parser->>Factories: create(..., SourceLocation)
  Factories->>Node: construct Node-derived(..., SourceLocation)
  Node->>Base: forward SourceLocation to base ctor
  Base-->>Node: store SourceLocation
  Node-->>Parser: return node with location
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • sitaowang1998

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is missing by the CI check.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like the clang-tidy check problems is much broader than just the type_traits problem. However, it provides a clue that the root cause might be if a system header is import through another system header, clang-tidy might not require the former to be included. Need more experiments to test if this is true.
@CodeRabbit, Please refactor #192 to make it broader, and add the hypothesis in the issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

I'll help you refactor issue #192 to make it broader and add the hypothesis about clang-tidy's behavior with system headers. Let me first find the current issue to understand its scope.

Now I'll update the issue to be broader and include the hypothesis:

@sitaowang1998 I've updated issue #192 to:

  1. Broadened the scope from just type_traits to all system headers with include-what-you-use violations
  2. Added your hypothesis about clang-tidy's behavior with transitive system header imports
  3. Included the current observations from PR feat(tdl): Add support for tracking the source location in AST nodes. #199 where <string_view> needed to be added
  4. Outlined a comprehensive investigation plan to test the hypothesis and fix violations systematically
  5. Added proper backlinks to this PR and comment for traceability

The updated issue now provides a framework for systematically investigating and resolving these clang-tidy violations across the entire codebase, rather than fixing them piecemeal as they're discovered.


🏁 Script executed:

#!/bin/bash
# Find and examine issue #192
gh issue view 192 --json title,body,state,url

Length of output: 1643


🏁 Script executed:

#!/bin/bash
# Update issue #192 with broader scope and hypothesis
gh issue edit 192 --title "Investigate and fix clang-tidy include-what-you-use violations for system headers" --body "## Problem

The CI is failing due to clang-tidy include-what-you-use violations where system headers are being used without being explicitly included. This issue has been observed with multiple system headers, not just \`<type_traits>\`.

## Current Observations

- PR #199 required adding \`#include <string_view>\` to \`src/spider/tdl/parser/ast/utils.hpp\` (Line 6)
- Previous issues have been seen with \`<type_traits>\` and other system headers

## Hypothesis

The root cause might be that when a system header is imported through another system header (transitive inclusion), clang-tidy's include-what-you-use check might not require the former to be explicitly included. However, this behavior may be inconsistent or dependent on specific configurations.

## Required Work

1. **Investigate the scope**: Conduct a comprehensive audit of all files to identify similar violations across the codebase
2. **Test the hypothesis**: Experiment with different system headers to verify if transitive inclusion affects clang-tidy's requirements
3. **Fix violations**: Add explicit includes for all system headers that are being used directly
4. **Document findings**: Update coding guidelines if patterns are discovered

## Related

- PR #199: https://github.com/y-scope/spider/pull/199
- Comment: https://github.com/y-scope/spider/pull/199#discussion_r2283266968

## Assignee

@sitaowang1998"

Length of output: 1553


@sitaowang1998 Perfect! I've successfully refactored issue #192 as requested. Here's what I've accomplished:

Issue Updated Successfully

Original scope: Narrow focus on <type_traits> and std::is_invocable_r_v
New scope: Comprehensive investigation of all clang-tidy include-what-you-use violations for system headers

🔍 Key Changes Made:

  1. Broadened the title: "Investigate and fix clang-tidy include-what-you-use violations for system headers"

  2. Added your hypothesis: The theory that transitive system header imports may cause inconsistent clang-tidy behavior

  3. Included current observations: Referenced the <string_view> fix needed in this PR (feat(tdl): Add support for tracking the source location in AST nodes. #199)

  4. Created systematic investigation plan:

    • Comprehensive codebase audit
    • Hypothesis testing with different system headers
    • Systematic violation fixes
    • Documentation updates
  5. Added proper traceability: Links back to this PR and comment for future reference

The issue is now positioned as a broader investigation that will help establish patterns and potentially prevent future occurrences of these violations across the entire codebase, rather than fixing them reactively as they're discovered.


🧬 Code Graph Analysis Results
  • File: src/spider/tdl/parser/ast/node_impl/Function.hpp
    Lines: 50-51
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/NamedVar.hpp
    Lines: 35-36
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/Namespace.hpp
    Lines: 53-54
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/StructSpec.hpp
    Lines: 53-54
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp
    Lines: 31-32
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/SourceLocation.hpp
    Lines: 13-13
    Content:

    [[nodiscard]] auto get_line() const noexcept -> size_t { return m_line; }
    
  • File: src/spider/tdl/parser/ast/SourceLocation.hpp
    Lines: 15-15
    Content:

    [[nodiscard]] auto get_column() const noexcept -> size_t { return m_column; }
    
  • File: src/spider/tdl/parser/ast/node_impl/Identifier.hpp
    Lines: 33-33
    Content:

    [[nodiscard]] auto get_name() const noexcept -> std::string_view { return m_name; }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 48-48
    Content:

    [[nodiscard]] auto get_parent() const noexcept -> Node const* { return m_parent; }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 53-53
    Content:

    [[nodiscard]] auto get_num_children() const noexcept -> size_t { return m_children.size(); }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 76-82
    Content:

    [[nodiscard]] auto visit_children(ChildVisitor visitor) const
                -> ystdlib::error_handling::Result<void> {
        for (auto const& child : m_children) {
            YSTDLIB_ERROR_HANDLING_TRYV(visitor(*child));
        }
        return ystdlib::error_handling::success();
    }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 91-92
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string>
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 95-97
    Content:

    [[nodiscard]] auto get_source_location() const noexcept -> SourceLocation {
            return m_source_location;
        }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 119-121
    Content:

    [[nodiscard]] auto get_child_unsafe(size_t child_idx) const -> Node const* {
            return m_children[child_idx].get();
        }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp
    Lines: 24-27
    Content:

    [[nodiscard]] static auto create(IntSpec spec, SourceLocation source_location)
                -> std::unique_ptr<Node> {
            return std::make_unique<Int>(Int{spec, source_location});
        }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp
    Lines: 34-34
    Content:

    [[nodiscard]] auto get_spec() const -> IntSpec { return m_spec; }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp
    Lines: 30-31
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp
    Lines: 24-25
    Content:

    create(IntSpec spec, SourceLocation source_location)
                -> std::unique_ptr<Node>
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp
    Lines: 24-27
    Content:

    [[nodiscard]] static auto create(FloatSpec spec, SourceLocation source_location)
                -> std::unique_ptr<Node> {
            return std::make_unique<Float>(Float{spec, source_location});
        }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp
    Lines: 34-34
    Content:

    [[nodiscard]] auto get_spec() const -> FloatSpec { return m_spec; }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp
    Lines: 30-31
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp
    Lines: 24-25
    Content:

    create(FloatSpec spec, SourceLocation source_location)
                -> std::unique_ptr<Node>
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp
    Lines: 35-39
    Content:

    [[nodiscard]] auto get_element_type() const noexcept -> Type const* {
            // The factory function ensures that the first child is of type `Type`.
            // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
            return static_cast<Type const*>(get_child_unsafe(0));
        }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp
    Lines: 31-32
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp
    Lines: 48-52
    Content:

    [[nodiscard]] auto get_key_type() const -> Type const* {
            // The factory function ensures that the first child is of type `Type`.
            // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
            return static_cast<Type const*>(get_child_unsafe(0));
        }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp
    Lines: 54-58
    Content:

    [[nodiscard]] auto get_value_type() const -> Type const* {
            // The factory function ensures that the second child is of type `Type`.
            // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
            return static_cast<Type const*>(get_child_unsafe(1));
        }
    
  • File: src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp
    Lines: 44-45
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string> override
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 48-48 (duplicate of get_parent)
    Content:

    [[nodiscard]] auto get_parent() const noexcept -> Node const* { return m_parent; }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 53-53 (duplicate of get_num_children)
    Content:

    [[nodiscard]] auto get_num_children() const noexcept -> size_t { return m_children.size(); }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 76-82 (duplicate of visit_children)
    Content:

    [[nodiscard]] auto visit_children(ChildVisitor visitor) const
                -> ystdlib::error_handling::Result<void> {
            for (auto const& child : m_children) {
                YSTDLIB_ERROR_HANDLING_TRYV(visitor(*child));
            }
            return ystdlib::error_handling::success();
        }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 91-92
    Content:

    serialize_to_str(size_t indentation_level) const
                -> ystdlib::error_handling::Result<std::string>
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 95-97
    Content:

    [[nodiscard]] auto get_source_location() const noexcept -> SourceLocation {
            return m_source_location;
        }
    
  • File: src/spider/tdl/parser/ast/Node.hpp
    Lines: 119-121
    Content:

    [[nodiscard]] auto get_child_unsafe(size_t child_idx) const -> Node const* {
            return m_children[child_idx].get();
        }
    

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (18)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)

10-15: Make SourceLocation trivially constexpr/noexcept-friendly

Minor polish: mark the ctor and accessors constexpr and the ctor noexcept. This enables compile-time construction and can help with constant expressions without changing runtime behaviour.

Apply:

-    SourceLocation(size_t line, size_t column) : m_line{line}, m_column{column} {}
+    constexpr SourceLocation(size_t line, size_t column) noexcept : m_line{line}, m_column{column} {}

-    [[nodiscard]] auto get_line() const noexcept -> size_t { return m_line; }
+    [[nodiscard]] constexpr auto get_line() const noexcept -> size_t { return m_line; }

-    [[nodiscard]] auto get_column() const noexcept -> size_t { return m_column; }
+    [[nodiscard]] constexpr auto get_column() const noexcept -> size_t { return m_column; }

9-15: Clarify 1-based vs 0-based semantics for line/column

A brief note on whether line/column are 1-based or 0-based will prevent subtle off-by-one inconsistencies across producers/consumers.

src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (1)

26-26: Prefer direct-initialization in make_unique to avoid an extra move

Idiomatic and marginally cleaner; constructs the object in-place.

Apply:

-    auto named_var{std::make_unique<NamedVar>(NamedVar{source_location})};
+    auto named_var{std::make_unique<NamedVar>(source_location)};
src/spider/tdl/parser/ast/node_impl/type_impl/Primitive.hpp (1)

10-13: Mark Primitive(SourceLocation) as noexcept

Construction should not throw; marking it noexcept helps optimisation and communicates intent. Derived ctors will inherit noexcept if they don’t throw.

Apply:

-    explicit Primitive(SourceLocation source_location) : Type{source_location} {}
+    explicit Primitive(SourceLocation source_location) noexcept : Type{source_location} {}
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)

32-32: Optional: consider perfect-forwarding in make_unique (consistency vs. micro-optimisation)

The pattern std::make_unique(Bool{source_location}) relies on move construction. Using direct perfect-forwarding avoids constructing a temporary:

-        return std::make_unique<Bool>(Bool{source_location});
+        return std::make_unique<Bool>(source_location);

If the codebase intentionally standardises on the current pattern (it appears consistent across nodes), feel free to keep it for uniformity.

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (1)

84-84: Nit: avoid temporary in make_unique

Minor allocation/ctor simplification; construct in-place instead of moving a temporary:

-    auto map{std::make_unique<Map>(Map{source_location})};
+    auto map{std::make_unique<Map>(source_location)};

Given other nodes follow the temporary pattern, apply only if you decide to standardise on direct construction.

src/spider/tdl/parser/ast/node_impl/Identifier.hpp (1)

24-26: Mark the factory [[nodiscard]] for consistency

Other node factories are annotated [[nodiscard]]. Do the same here to prevent accidental discard and to keep the API consistent.

Apply this diff:

-static auto create(std::string name, SourceLocation source_location) -> std::unique_ptr<Node> {
+[[nodiscard]] static auto create(std::string name, SourceLocation source_location) -> std::unique_ptr<Node> {
     return std::make_unique<Identifier>(Identifier{std::move(name), source_location});
 }
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (1)

26-28: Minor: consider noexcept on is_empty()

Since is_empty delegates to get_num_children() which is noexcept, marking it noexcept clarifies intent and enables minor optimizations.

Outside this hunk, update the method as:

[[nodiscard]] auto is_empty() const noexcept -> bool { return 0 == get_num_children(); }
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)

46-50: Fix copy-paste in comment and consider noexcept on get_num_functions()

  • The comment in visit_functions currently mentions NamedVar; it should say Function.
  • get_num_functions() can be noexcept, similar to other query methods.

Outside this hunk, adjust these spots:

// In visit_functions loop above:
// The factory function ensures that all the child nodes are `Function` except the first one.

[[nodiscard]] auto get_num_functions() const noexcept -> size_t { return get_num_children() - 1; }
src/spider/tdl/parser/ast/node_impl/Function.cpp (1)

66-66: Minor: avoid temporary object in make_unique

Constructing via std::make_unique<Function>(Function{...}) creates a temporary and relies on move/copy construction. Prefer direct forwarding of constructor args.

Apply this diff:

-    auto function{std::make_unique<Function>(Function{has_return, source_location})};
+    auto function = std::make_unique<Function>(has_return, source_location);
src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (1)

67-67: Minor: avoid temporary object in make_shared

Similar to other spots, constructing via std::make_shared<StructSpec>(StructSpec{...}) creates a temporary. Prefer direct forwarding.

Apply this diff:

-    auto struct_spec{std::make_shared<StructSpec>(StructSpec{source_location})};
+    auto struct_spec = std::make_shared<StructSpec>(source_location);

Additionally, consider reserving capacity in the set to avoid rehashes for larger structs (optional):

// Near the declaration of field_names
absl::flat_hash_set<std::string_view> field_names;
field_names.reserve(fields.size());
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (1)

66-72: Rename local variable function to avoid confusion.
The variable holds a Namespace node; naming it function is misleading next to func. Minor readability nit.

Apply:

-    auto function{std::make_unique<Namespace>(Namespace{source_location})};
-    YSTDLIB_ERROR_HANDLING_TRYV(function->add_child(std::move(name)));
+    auto ns{std::make_unique<Namespace>(Namespace{source_location})};
+    YSTDLIB_ERROR_HANDLING_TRYV(ns->add_child(std::move(name)));
@@
-        YSTDLIB_ERROR_HANDLING_TRYV(function->add_child(std::move(func)));
+        YSTDLIB_ERROR_HANDLING_TRYV(ns->add_child(std::move(func)));
     }
-    return function;
+    return ns;
src/spider/tdl/parser/ast/Node.hpp (1)

95-98: Optional: consider returning a const reference from get_source_location().
SourceLocation looks small; returning by value is fine. If it ever grows, a const ref avoids copies. Your call.

-    [[nodiscard]] auto get_source_location() const noexcept -> SourceLocation {
-        return m_source_location;
-    }
+    [[nodiscard]] auto get_source_location() const noexcept -> SourceLocation const& {
+        return m_source_location;
+    }
tests/tdl/test-parser-ast.cpp (5)

55-59: Use a single test SourceLocation and consider a non-zero value

Right now, every factory call reconstructs a zero location. Consider:

  • Using a single constexpr/static SourceLocation to reduce repetition/noise.
  • Using a non-zero location to better detect plumbing mistakes that default to zero.

Example tweak (optional):

-[[nodiscard]] auto create_source_location() -> spider::tdl::parser::ast::SourceLocation;
+[[nodiscard]] inline auto create_source_location() -> spider::tdl::parser::ast::SourceLocation;
@@
-auto create_source_location() -> spider::tdl::parser::ast::SourceLocation {
-    return spider::tdl::parser::ast::SourceLocation{0, 0};
-}
+auto create_source_location() -> spider::tdl::parser::ast::SourceLocation {
+    return spider::tdl::parser::ast::SourceLocation{42, 7};
+}

Also applies to: 104-107


130-140: Add an assertion for Identifier’s SourceLocation

Since this PR’s goal is location plumbing, add a minimal assertion to verify it for Identifier.

Apply this diff:

         REQUIRE(nullptr == identifier->get_parent());
         REQUIRE(identifier->get_name() == cTestName);
+
+        // Verify SourceLocation is threaded
+        auto const loc = identifier->get_source_location();
+        REQUIRE(loc.get_line() == 0);
+        REQUIRE(loc.get_column() == 0);

If you adopt a non-zero location in create_source_location(), adjust expected values accordingly.


174-184: Add an assertion for Float’s SourceLocation

Verify the Float node carries the provided SourceLocation.

         REQUIRE(float_node->get_spec() == float_spec);
         REQUIRE(float_node->get_num_children() == 0);
+
+        // Verify SourceLocation is threaded
+        auto const loc = float_node->get_source_location();
+        REQUIRE(loc.get_line() == 0);
+        REQUIRE(loc.get_column() == 0);

200-207: Add a location check for List (container) nodes

A quick assertion here increases confidence that containers also carry locations properly.

     auto const* list_node{dynamic_cast<List const*>(list_result.value().get())};
     REQUIRE(nullptr != list_node);
 
+    // Verify SourceLocation is threaded
+    auto const list_loc = list_node->get_source_location();
+    REQUIRE(list_loc.get_line() == 0);
+    REQUIRE(list_loc.get_column() == 0);
+
     REQUIRE(list_node->get_num_children() == 1);

Also applies to: 208-225


239-247: Add a location check for Map nodes

Similarly, assert SourceLocation on Map.

     auto const* map_node{dynamic_cast<Map const*>(map_result.value().get())};
     REQUIRE(nullptr != map_node);
 
+    // Verify SourceLocation is threaded
+    auto const map_loc = map_node->get_source_location();
+    REQUIRE(map_loc.get_line() == 0);
+    REQUIRE(map_loc.get_column() == 0);
+
     REQUIRE(map_node->get_num_children() == 2);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d5a1878 and c257cbb.

📒 Files selected for processing (28)
  • src/spider/CMakeLists.txt (1 hunks)
  • src/spider/tdl/parser/ast/Node.hpp (3 hunks)
  • src/spider/tdl/parser/ast/SourceLocation.hpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/Function.cpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/Function.hpp (4 hunks)
  • src/spider/tdl/parser/ast/node_impl/Identifier.hpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/NamedVar.hpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/Namespace.cpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/Namespace.hpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/Type.hpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/Container.hpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/Primitive.hpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp (3 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (2 hunks)
  • src/spider/tdl/parser/ast/utils.hpp (1 hunks)
  • tests/tdl/test-parser-ast.cpp (27 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-07T14:54:20.267Z
Learnt from: LinZhihao-723
PR: y-scope/spider#182
File: src/spider/tdl/parser/ast/Node.hpp:0-0
Timestamp: 2025-08-07T14:54:20.267Z
Learning: In the spider TDL AST Node class, derived classes should use the `add_child` method in their factory functions rather than passing children directly to a constructor, to ensure proper parent-child relationship management and error handling.

Applied to files:

  • src/spider/tdl/parser/ast/Node.hpp
🧬 Code Graph Analysis (24)
src/spider/tdl/parser/ast/node_impl/Type.hpp (1)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/SourceLocation.hpp (1)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (3)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (2)
  • create (17-24)
  • create (17-18)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp (1)
  • key_type (37-41)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp (10)
src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (2)
  • create (18-30)
  • create (18-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (2)
  • create (17-24)
  • create (17-18)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
  • create (20-31)
  • create (20-21)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (2)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/node_impl/Function.hpp (1)
  • name (42-47)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)
  • name (39-40)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/utils.hpp (3)
  • validate_child_node_type (53-54)
  • validate_child_node_type (58-63)
  • validate_child_node_type (58-58)
src/spider/tdl/parser/ast/node_impl/type_impl/Primitive.hpp (1)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (8)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (3)
  • nodiscard (33-33)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/NamedVar.hpp (2)
  • nodiscard (39-43)
  • nodiscard (45-49)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (2)
  • name (27-29)
  • name (27-27)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)
  • name (39-40)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (4)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (3)
  • nodiscard (33-33)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (8)
src/spider/tdl/parser/ast/node_impl/Function.hpp (1)
  • name (42-47)
src/spider/tdl/parser/ast/node_impl/Function.cpp (2)
  • name (27-29)
  • name (27-27)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (2)
  • name (27-29)
  • name (27-27)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)
  • name (39-40)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (2)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp (6)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (2)
  • nodiscard (22-24)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp (2)
  • nodiscard (48-52)
  • nodiscard (54-58)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (4)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (2)
  • nodiscard (22-24)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (3)
  • nodiscard (24-27)
  • nodiscard (34-34)
  • spec (24-25)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (7)
src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (2)
  • create (18-30)
  • create (18-22)
src/spider/tdl/parser/ast/node_impl/Function.cpp (2)
  • create (42-75)
  • create (42-47)
src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (2)
  • create (45-73)
  • create (45-49)
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (2)
  • create (44-72)
  • create (44-48)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (2)
  • create (17-24)
  • create (17-18)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (2)
  • create (70-88)
  • create (70-74)
src/spider/tdl/parser/ast/utils.hpp (3)
  • validate_child_node_type (53-54)
  • validate_child_node_type (58-63)
  • validate_child_node_type (58-58)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (4)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)
  • name (39-40)
src/spider/tdl/parser/ast/node_impl/Function.hpp (1)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/Container.hpp (1)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (4)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/Function.cpp (1)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (5)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (2)
  • create (70-88)
  • create (70-74)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
  • create (20-31)
  • create (20-21)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp (1)
  • element_type (27-28)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/utils.hpp (3)
  • validate_child_node_type (53-54)
  • validate_child_node_type (58-63)
  • validate_child_node_type (58-58)
src/spider/tdl/parser/ast/node_impl/NamedVar.hpp (5)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (1)
  • nodiscard (33-33)
src/spider/tdl/parser/ast/node_impl/Function.hpp (6)
  • nodiscard (54-54)
  • nodiscard (56-60)
  • nodiscard (65-72)
  • nodiscard (74-76)
  • nodiscard (90-103)
  • nodiscard (112-114)
src/spider/tdl/parser/ast/Node.hpp (5)
  • nodiscard (48-48)
  • nodiscard (53-53)
  • nodiscard (76-82)
  • nodiscard (95-97)
  • nodiscard (119-121)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (2)
  • nodiscard (57-61)
  • nodiscard (63-63)
src/spider/tdl/parser/ast/Node.hpp (3)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (11)
src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (2)
  • create (18-30)
  • create (18-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (2)
  • create (17-24)
  • create (17-18)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp (4)
  • create (41-48)
  • create (41-42)
  • name (22-24)
  • name (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (4)
  • create (70-88)
  • create (70-74)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
  • create (20-31)
  • create (20-21)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (2)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/node_impl/Function.hpp (1)
  • name (42-47)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • name (46-50)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)
  • name (39-40)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (3)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (2)
  • nodiscard (22-24)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (3)
  • nodiscard (24-27)
  • nodiscard (34-34)
  • spec (24-25)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp (4)
src/spider/tdl/parser/ast/SourceLocation.hpp (2)
  • nodiscard (13-13)
  • nodiscard (15-15)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (2)
  • nodiscard (22-24)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (2)
  • nodiscard (24-27)
  • nodiscard (34-34)
src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (8)
src/spider/tdl/parser/ast/node_impl/Function.cpp (2)
  • create (42-75)
  • create (42-47)
src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (2)
  • create (45-73)
  • create (45-49)
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (2)
  • create (44-72)
  • create (44-48)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (2)
  • create (17-24)
  • create (17-18)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (2)
  • create (70-88)
  • create (70-74)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
  • create (20-31)
  • create (20-21)
src/spider/tdl/parser/ast/node_impl/NamedVar.hpp (1)
  • id (31-32)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • source_location (22-22)
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (5)
src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (2)
  • create (18-30)
  • create (18-22)
src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (4)
  • create (45-73)
  • create (45-49)
  • name (27-29)
  • name (27-27)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (2)
  • name (24-26)
  • name (24-24)
src/spider/tdl/parser/ast/node_impl/Function.hpp (1)
  • name (42-47)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • name (46-50)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
🔇 Additional comments (36)
src/spider/tdl/parser/ast/utils.hpp (1)

6-6: serialize_ functions safely return string literals*
Verified that both serialize_int_spec and serialize_float_spec only return string literals (e.g., "int8", "float"), which have static storage duration. The std::string_views therefore refer to stable memory and won’t dangle. No further changes needed.

src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (1)

18-22: All NamedVar::create call sites updated with SourceLocation

Verified that every occurrence of NamedVar::create now passes a SourceLocation argument:

  • tests/tdl/test-parser-ast.cpp:78, 329, 413, 431, 489, 526

No further changes are required.

src/spider/tdl/parser/ast/node_impl/type_impl/Primitive.hpp (1)

5-5: Include addition is appropriate

Including SourceLocation.hpp here matches the new constructor signature and the Type(SourceLocation) base.

src/spider/tdl/parser/ast/node_impl/Type.hpp (1)

9-13: LGTM: Type now correctly threads SourceLocation via a protected ctor

Explicit, protected ctor forwarding SourceLocation to Node is the right shape for an abstract base. Keeps construction disciplined in derived classes.

src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp (1)

41-47: LGTM: Factory threads SourceLocation and preserves existing invariants

create now accepts SourceLocation and constructs Struct{source_location}, while retaining child-type validation and attach order. Matches the pattern used in other nodes in this PR.

src/spider/tdl/parser/ast/node_impl/type_impl/Container.hpp (1)

9-13: LGTM: Container properly forwards SourceLocation to Type

Protected explicit ctor enforces intended inheritance-only construction and cleanly propagates location metadata to the base.

src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)

22-24: LGTM: Location-aware Bool factory

Factory signature and construction align with the new SourceLocation plumbing across the AST.

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (1)

70-75: LGTM: Map::create now location-aware with consistent validation

Signature and ctor usage correctly include SourceLocation; child-type validation and key-type gate remain unchanged. Good consistency with List/Tuple.

src/spider/tdl/parser/ast/node_impl/NamedVar.hpp (1)

13-13: Location threading and constructor change look correct

Header inclusion, factory signature, and explicit constructor forwarding to Node{source_location} are consistent with the rest of the PR and the updated Node API.

Also applies to: 25-25, 30-32, 53-53

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (1)

13-13: Factory signature and constructor update align with the new location-aware Node

The added SourceLocation include, factory parameter, and explicit constructor forwarding to Container{source_location} look good and match the broader changes.

Also applies to: 21-21, 26-28, 39-39

src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)

18-18: Location support integration looks solid

Header inclusion, factory signature addition, and explicit constructor forwarding to Node{source_location} are correct and consistent with other nodes.

Also applies to: 36-39, 46-50, 92-92

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (1)

16-16: Tuple::create correctly threads SourceLocation

Validation remains unchanged, and construction now passes the SourceLocation to Tuple; consistent with List/Map/Struct. Looks good.

Also applies to: 20-21, 26-26

src/spider/tdl/parser/ast/node_impl/Function.cpp (1)

20-20: Include for SourceLocation is correct and necessary

The added include is appropriate for the new parameter and constructor usage.

src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (3)

18-18: Include for SourceLocation is correctly added

Header now declares the new dependency; good.


46-51: API change: StructSpec::create now takes SourceLocation

The new factory signature is clear and consistent with the rest of the AST APIs (location as the last parameter).


92-92: Base Node initialisation with SourceLocation is correct

The private constructor correctly forwards the SourceLocation to Node.

src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.hpp (3)

13-13: Include for SourceLocation is appropriate

Required for the new constructor/factory signatures.


24-27: Factory now threads SourceLocation (good consistency with Bool/Float)

The create() overload and return type remain consistent with other primitive nodes.


38-38: Constructor threads SourceLocation via Primitive base correctly

Initializes the base with SourceLocation and stores the spec; looks good.

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (1)

13-13: List now carries SourceLocation through factory and construction

  • Include added.
  • Factory signature updated to take SourceLocation.
  • Instance constructed with the provided location.

All changes align with the broader AST changes.

Also applies to: 17-17, 21-21

src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (2)

19-19: Include for SourceLocation is correct

Needed for the new factory parameter and constructor.


45-49: All StructSpec::create call sites now include the new SourceLocation parameter

We searched the entire codebase for StructSpec::create and found only the definition plus four test usages—all of which pass create_source_location() as the third argument:

• tests/tdl/test-parser-ast.cpp:443–446
• tests/tdl/test-parser-ast.cpp:500–503
• tests/tdl/test-parser-ast.cpp:511–514
• tests/tdl/test-parser-ast.cpp:535–538

No other call sites were found, so no further updates are needed.

src/spider/tdl/parser/ast/node_impl/Namespace.cpp (1)

20-20: Good addition: SourceLocation include aligns with new location-aware API.
This keeps this TU consistent with the rest of the AST changes.

src/spider/tdl/parser/ast/node_impl/Function.hpp (1)

19-19: Please confirm all Function::create calls include the new SourceLocation parameter
I ran a search across C++ sources and headers and found the Function::create definition in

  • src/spider/tdl/parser/ast/node_impl/Function.cpp

and multiple call sites in

  • tests/tdl/test-parser-ast.cpp (e.g. around lines 94, 621, 674, 721, 763, 793)

Some invocations already pass create_source_location() at the end, but earlier uses (around line 94) didn’t show it in the brief snippet. Please manually verify that every Function::create(…) invocation now passes a SourceLocation as its final argument.

Suggested command:

rg -n -C2 -g '*.{cpp,cc,cxx,h,hh,hpp,hxx}' '\bFunction::create\s*\('
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)

17-17: Struct becomes location-aware — consistent and idiomatic.

  • Includes SourceLocation.
  • Factory signature and docs updated.
  • Ctor forwards to Type with SourceLocation.

Also applies to: 34-35, 39-39, 68-68

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp (1)

13-13: List: SourceLocation propagation is consistent with other container nodes.

  • Header include, factory, and ctor updates all look correct.

Also applies to: 21-22, 26-28, 43-43

src/spider/tdl/parser/ast/Node.hpp (2)

14-15: Base Node now includes SourceLocation — correct placement and visibility.
This brings the type into scope for the base class API and derived classes.


101-101: Verify that all factory create() methods accept a SourceLocation

No initializer‐lists still default‐constructing Node{} and no explicit calls to Node() were found. The automated search for create…() functions proved noisy, so please manually confirm that every factory method in src/spider/tdl/parser/ast/node_impl (for example):

  • StructSpec::create (.../node_impl/StructSpec.cpp)
  • NamedVar::create (.../node_impl/NamedVar.cpp)
  • Namespace::create (.../node_impl/Namespace.cpp)
  • Function::create (.../node_impl/Function.cpp)
  • Map::create (.../node_impl/type_impl/container_impl/Map.cpp)

includes a SourceLocation parameter in its signature.

src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.hpp (3)

15-15: Include SourceLocation – LGTM

Including SourceLocation in the public header is appropriate since the type appears in the public API.


62-62: Constructor correctly forwards SourceLocation – LGTM

The explicit constructor forwarding SourceLocation into Container aligns with the new Node plumbing.


31-41: API change verified: no non-test callers of Map::create

All Map::create invocations found are in tests and have been updated to pass the new SourceLocation parameter. No call sites in production code were detected.

• tests/tdl/test-parser-ast.cpp – all Map::create(…, create_source_location()) calls updated
• src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp – factory signature includes SourceLocation

Please remember to document this public API change in the release notes.

src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (3)

13-13: Include SourceLocation – LGTM

Including SourceLocation here is necessary and consistent with the other primitive nodes.


24-27: Factory updated to accept SourceLocation – LGTM

Signature mirrors Int::create and Bool::create; construction path is correct.


38-40: Constructor wires SourceLocation into Primitive – LGTM

Base initialization order and member initialization are correct.

tests/tdl/test-parser-ast.cpp (2)

28-28: Test dependency update – LGTM

Including SourceLocation in tests is expected given the location-aware APIs.


295-305: Solid coverage of Map key-type errors – LGTM

These checks for UnsupportedKeyType vs UnexpectedChildNodeType cover the intended error propagation.

Comment thread src/spider/CMakeLists.txt
Comment thread src/spider/tdl/parser/ast/node_impl/Function.cpp
Comment thread src/spider/tdl/parser/ast/node_impl/Namespace.cpp

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like the clang-tidy check problems is much broader than just the type_traits problem. However, it provides a clue that the root cause might be if a system header is import through another system header, clang-tidy might not require the former to be included. Need more experiments to test if this is true.
@CodeRabbit, Please refactor #192 to make it broader, and add the hypothesis in the issue.

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.

2 participants