Skip to content

fix(tdl): Add source location information when serializing an AST node. - #211

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

fix(tdl): Add source location information when serializing an AST node.#211
LinZhihao-723 merged 1 commit into
y-scope:mainfrom
LinZhihao-723:serialize-source-location

Conversation

@LinZhihao-723

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

Copy link
Copy Markdown
Member

Description

Before this PR, the serialization method of an AST node would not serialize any source location info. This PR fixes this by properly serializing the source location:

  • For all types of node, the source location is serialized after the type tag, in the form of (line_num, column_num).
  • For StructSpec, Function, and Namespace, the identifier (name) was serialized directly as a string before this PR. This PR fixes it by properly serializing the name as a child identifier node, so that the source location of the ID token can be tracked properly.

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.
  • Updated all unit tests to reflect the serialization format change.
  • Manually checked that the serialized source locations are correct in the parser test case.

Summary by CodeRabbit

  • New Features

    • Serialized AST output now includes source locations in the form “(line:column)” across all nodes (Identifiers, Types, Containers, Tuples, Structs, Namespaces, Functions, TranslationUnit).
    • Improved formatting: “Name” fields are shown as nested blocks using child serialization.
    • Added a public method to convert source locations to a string.
  • Tests

    • Updated expectations to the new location-aware serialization.
    • Expanded test inputs to cover a larger TDL program and nested structures, ensuring comprehensive validation of the new output format.

@coderabbitai

coderabbitai Bot commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds SourceLocation::serialize_to_str and updates many AST/type serializer implementations to embed source-location text in their outputs. Several nodes switch name rendering from direct getters to serializing the first child node. Tests are updated to reflect the new location-aware format and expanded input coverage.

Changes

Cohort / File(s) Summary of changes
SourceLocation API
src/spider/tdl/parser/SourceLocation.hpp
New public method serialize_to_str() returning "(line:column)"; includes <string> and fmt/format.h.
AST node serialization (core)
src/spider/tdl/parser/ast/node_impl/Function.cpp, .../Identifier.cpp, .../NamedVar.cpp, .../Namespace.cpp, .../StructSpec.cpp, .../TranslationUnit.cpp
Inject source-location into header lines. Function/Namespace/StructSpec switch to serializing first child for the name under a “Name:” block with adjusted indentation; error propagation via TRYX maintained.
Type serialization (struct and containers)
.../type_impl/Struct.cpp, .../type_impl/container_impl/List.cpp, .../container_impl/Map.cpp, .../container_impl/Tuple.cpp
Add source-location segment to type headers; keep existing child serializations/indentation, with minor placeholder/indent tweaks.
Type serialization (primitives)
.../type_impl/primitive_impl/Bool.cpp, .../primitive_impl/Float.cpp, .../primitive_impl/Int.cpp
Append source-location to primitive type headers; formatting strings updated, logic unchanged.
Tests
tests/tdl/test-parser-ast.cpp, tests/tdl/test-parser.cpp
Expected strings updated to include per-node "(line:column)" after labels; expanded parser test input and synchronized expected serialized AST.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant N as AST Node (e.g., Function)
  participant SL as SourceLocation
  participant C as Child Node (Name)
  participant F as Formatter

  N->>SL: serialize_to_str()
  SL-->>N: "(line:column)"
  N->>C: serialize_to_str(indentation+2)
  C-->>N: "child-serialized"
  N->>F: fmt::format(header with location, blocks)
  F-->>N: "final-serialized"
  note over N: Output includes [Tag](line:column) and nested Name block
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.

@LinZhihao-723
LinZhihao-723 marked this pull request as ready for review August 26, 2025 02:06
@LinZhihao-723
LinZhihao-723 requested review from a team and sitaowang1998 as code owners August 26, 2025 02:06

@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: 0

🧹 Nitpick comments (6)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.cpp (1)

15-19: Reduce duplication with a tiny formatter helper

Multiple node serializers now repeat the same pattern: indentation + node tag + SourceLocation + optional colon. Consider a small helper (e.g., format_node_header(tag, indentation_level, loc)) in ast/utils to keep this consistent and make future tweaks trivial.

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

14-18: Possible formatting inconsistency: missing trailing colon vs other type serializers

Int (and several others) render “…]]](line:col):…”. Bool currently stops at the location with no colon. If downstream consumers or tests expect a colon after the type tag uniformly, this will be a surprise. If Bool truly has no spec, you can still emit a terminal “:”.

Proposed tweak:

-    return fmt::format(
-            "{}[Type[Primitive[Bool]]]{})",
-            create_indentation(indentation_level),
-            get_source_location().serialize_to_str()
-    );
+    return fmt::format(
+            "{}[Type[Primitive[Bool]]]{}:",
+            create_indentation(indentation_level),
+            get_source_location().serialize_to_str()
+    );

If tests intentionally assert no colon for Bool, keep as-is and consider documenting the exception.

src/spider/tdl/parser/SourceLocation.hpp (1)

5-8: Move formatting out of the header to cut compile-time and coupling

Having fmt/format.h in a widely included header increases rebuild cost and couples all TUs to fmt. Make serialize_to_str out-of-line and drop the fmt include from the header.

Header changes:

@@
-#include <string>
-
-#include <fmt/format.h>
+#include <string>
@@
-    [[nodiscard]] auto serialize_to_str() const -> std::string {
-        return fmt::format("({}:{})", m_line, m_column);
-    }
+    [[nodiscard]] auto serialize_to_str() const -> std::string;

Add a new implementation file:

// src/spider/tdl/parser/SourceLocation.cpp
#include "SourceLocation.hpp"

#include <fmt/format.h>

namespace spider::tdl::parser {
auto SourceLocation::serialize_to_str() const -> std::string {
    return fmt::format("({}:{})", m_line, m_column);
}
}  // namespace spider::tdl::parser

Optional nit: get_line()/get_column() can be constexpr without behaviour change.

Also applies to: 20-23

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

14-19: Guard against ambiguous names in pretty-printing

If identifiers can contain ':' or newline, consider quoting or escaping to keep the output trivially machine-parsable (e.g., wrap m_name in quotes and escape embedded quotes/newlines).

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

93-99: Consider centralizing node header formatting

Multiple serializers now repeat the pattern "{}{Tag}{}:". A tiny helper (e.g., format_node_header(indent, tag, loc)) would remove duplication and keep future tweaks to one place.

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

74-81: Add explicit include for SourceLocation to avoid transitive dependency

This file uses get_source_location().serialize_to_str() but doesn’t include SourceLocation.hpp, unlike the other updated serializers. Add the include for consistency and build hygiene.

Apply this diff near the other includes:

 #include <spider/tdl/parser/ast/node_impl/StructSpec.hpp>
 #include <spider/tdl/parser/ast/utils.hpp>
+#include <spider/tdl/parser/SourceLocation.hpp>
📜 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 d9db9f1 and 6027bfa.

📒 Files selected for processing (16)
  • src/spider/tdl/parser/SourceLocation.hpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/Function.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/Identifier.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/NamedVar.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/Namespace.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/TranslationUnit.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp (1 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/Map.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.cpp (1 hunks)
  • src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.cpp (1 hunks)
  • tests/tdl/test-parser-ast.cpp (17 hunks)
  • tests/tdl/test-parser.cpp (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (12)
src/spider/tdl/parser/ast/node_impl/Identifier.cpp (4)
src/spider/tdl/parser/ast/utils.cpp (2)
  • create_indentation (14-19)
  • create_indentation (14-14)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/Identifier.hpp (1)
  • indentation_level (29-30)
src/spider/tdl/parser/ast/node_impl/NamedVar.hpp (1)
  • indentation_level (35-36)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.cpp (4)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/utils.cpp (2)
  • create_indentation (14-19)
  • create_indentation (14-14)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Bool.hpp (1)
  • indentation_level (27-28)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (1)
  • indentation_level (31-32)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.cpp (4)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/utils.cpp (2)
  • create_indentation (14-19)
  • create_indentation (14-14)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Float.hpp (1)
  • indentation_level (30-31)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp (3)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/type_impl/Struct.hpp (1)
  • indentation_level (43-44)
src/spider/tdl/parser/ast/node_impl/StructSpec.cpp (3)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/StructSpec.hpp (1)
  • indentation_level (53-54)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (2)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/utils.cpp (2)
  • create_indentation (14-19)
  • create_indentation (14-14)
src/spider/tdl/parser/ast/node_impl/TranslationUnit.cpp (1)
src/spider/tdl/parser/ast/node_impl/TranslationUnit.hpp (1)
  • indentation_level (45-46)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (3)
src/spider/tdl/parser/ast/utils.cpp (2)
  • create_indentation (14-19)
  • create_indentation (14-14)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.hpp (1)
  • indentation_level (31-32)
src/spider/tdl/parser/SourceLocation.hpp (2)
src/spider/tdl/Error.hpp (3)
  • nodiscard (27-27)
  • nodiscard (29-31)
  • nodiscard (33-35)
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.cpp (1)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/node_impl/Namespace.cpp (3)
src/spider/tdl/parser/ast/utils.hpp (1)
  • create_indentation (22-22)
src/spider/tdl/parser/ast/Node.hpp (1)
  • indentation_level (91-92)
src/spider/tdl/parser/ast/node_impl/Namespace.hpp (1)
  • indentation_level (53-54)
⏰ 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: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
🔇 Additional comments (34)
src/spider/tdl/parser/ast/node_impl/type_impl/primitive_impl/Int.cpp (1)

15-19: LGTM: location inserted in the right spot for primitives with specs

The colon-delimited placement between the type tag and the spec mirrors the project-wide convention. Error propagation via TRYX is correct.

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

14-19: LGTM: consistent header + location + colon + payload

Good alignment with the new convention and clean use of indentation. No error-unwrapping needed here.

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

52-62: LGTM: header now carries location; child-identifier serialisation preserved

Nice, the location is added after “[Type[Struct]]” and before the colon; the “Name:” block continues to render via the first child Identifier with proper error propagation.


52-62: Struct nodes are only instantiated via the factory – get_child_unsafe(0) is safe

Verified via a repo-wide search that the only occurrence of

std::make_unique<Struct>(Struct{…})

is in src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp at line 45 (inside the create() method), and there are no other direct calls to new Struct or make_unique<Struct> elsewhere. This guarantees the first child is always an Identifier, so using get_child_unsafe(0) here is justified.

• src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp:45 – lone instantiation in factory method

(Optional) If you’d like to harden against future regressions, you could add a debug_assert(children().size() > 0) before serializing, but it isn’t strictly necessary given the invariant held by the factory.

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

93-99: LGTM: Location suffix integrated correctly in Map serialization

Placeholders and indentation are consistent; the added source-location segment sits exactly before the colon as per the new convention.

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

38-43: LGTM: Empty Tuple now carries source location

Header formatting with cTypeTag and location is correct and matches the project-wide pattern.


63-67: LGTM: Non-empty Tuple header embeds location as intended

The header line is consistent with other container types; child traversal remains untouched.

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

35-41: LGTM: NamedVar serialization updated to include source location

Header placement of the location string is consistent; Id and Type sections keep existing indentation semantics.

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

74-81: LGTM: TranslationUnit header now includes source location

The insertion point and formatting align with the new standard across nodes.


74-81: Align location serialization to “(line:column)” throughout

Scanning the repository confirms that every call to serialize_to_str() (including in SourceLocation.hpp) emits coordinates in the “(line:column)” form, and all existing tests expect that colon‐separated format. No occurrences of the old “(line, col)” syntax remain in tests/ or in node implementations.

Action items:

  • Update the PR description (and any accompanying docs) to refer to the “(line:column)” format instead of “(line_num, column_num)”.
  • Confirm that any external consumers of the serialized AST (e.g., downstream tools, scripts or documentation) have been updated to parse “(line:column)” tokens and do not rely on a comma‐separated form.
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (1)

29-33: LGTM: Location added to List header cleanly

Consistent placement and indentation. No functional changes beyond serialization.

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

15-18: Consistent source location inclusion in serialization.

The implementation correctly adds the source location information to the serialization output using the new get_source_location().serialize_to_str() pattern. This aligns with the PR objective to embed source location information in all AST node serializations.

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

94-102: Proper implementation of source location and name serialization changes.

The changes correctly:

  • Add source location information via get_source_location().serialize_to_str()
  • Replace direct name access (get_name()) with child node serialization (get_child_unsafe(0)->serialize_to_str())
  • Maintain proper indentation hierarchy for the nested Name block

This follows the established pattern across other node types in the PR and preserves source location information for the identifier token.

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

94-102: Consistent source location and child serialization implementation.

The implementation properly:

  • Integrates source location using get_source_location().serialize_to_str()
  • Changes from direct name access to serializing the first child node with proper error handling via YSTDLIB_ERROR_HANDLING_TRYX
  • Maintains correct indentation levels for the nested Name structure

This aligns with the pattern established across other AST nodes in the PR.

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

184-184: Test update reflects new serialization format.

The test expectation correctly includes the (0:0) source location suffix, matching the new serialization format where all nodes include their source location information.


200-212: Comprehensive test coverage for primitive type location serialization.

All Int type variants now correctly expect the (0:0) source location suffix in their serialized output, ensuring thorough test coverage for the new location-aware serialization format.


231-236: Float type test expectations updated correctly.

The test expectations for Float types properly include the source location suffix, maintaining consistency with the updated serialization format.


258-258: Bool type serialization test updated appropriately.

The Bool type test correctly expects the location suffix in the serialized output.


278-290: Container type nested serialization tests updated comprehensively.

The test expectations for List of Map correctly include source location information at every level:

  • The outer List container: [Type[Container[List]]](0:0)
  • The inner Map container: [Type[Container[Map]]](0:0)
  • The primitive key and value types: [Type[Primitive[Int]]](0:0) and [Type[Primitive[Float]]](0:0)

This ensures complete test coverage for nested container serialization with source locations.


314-328: Complex nested container serialization correctly validated.

The Map of List test expectations properly include source location suffixes at all nesting levels, providing comprehensive validation of the new serialization format for complex nested structures.


405-419: NamedVar serialization test updated with proper location information.

The test correctly expects source location suffixes for:

  • The NamedVar node itself
  • The nested Identifier
  • The nested Map type and its key/value primitive types

This validates the complete serialization chain for named variables.


430-436: Empty Tuple serialization test updated appropriately.

The empty Tuple test correctly expects the source location suffix while maintaining the "Empty" content designation.


458-474: Complex Tuple serialization thoroughly tested.

The test expectations for Tuples with elements correctly include source location information at every level of nesting, ensuring comprehensive validation of the new format.


524-554: StructSpec serialization comprehensively validated.

The test properly validates the new StructSpec serialization format with:

  • Source location for the StructSpec itself
  • Nested Name block with Identifier serialization
  • Source locations for all field components (NamedVar nodes, Identifiers, and types)

This ensures complete test coverage for structured type definitions.


624-632: Struct type serialization test updated correctly.

The Struct type test expectations include proper source location information and the nested Name structure, maintaining consistency with the new serialization pattern.


706-738: Function serialization thoroughly tested with all components.

The comprehensive Function test correctly validates:

  • Source location for the Function node
  • Nested Name block with Identifier serialization
  • Return type with full nested structure and locations
  • Parameter serialization with complete type information and locations

This provides extensive validation of function declaration serialization.


762-786: Function without return type properly tested.

The test correctly handles functions with void return types while maintaining proper source location information throughout the serialization.


809-828: Function with empty parameters correctly validated.

The test for functions with no parameters properly includes source location information and maintains the "No Params" designation.


847-858: Minimal function case thoroughly tested.

The test for functions with no parameters and no return type correctly validates the simplest function serialization case with proper source location inclusion.


903-925: Namespace serialization comprehensively validated.

The Namespace test expectations correctly include:

  • Source location for the Namespace itself
  • Nested Name block structure
  • Complete Function serialization with all components and their source locations

This ensures thorough validation of namespace declarations.


966-1021: TranslationUnit serialization thoroughly tested.

The comprehensive TranslationUnit test validates the complete hierarchy with source locations at every level:

  • TranslationUnit root node
  • All nested StructSpecs with their components
  • All nested Namespaces with their Function contents

This provides complete end-to-end validation of the serialization system.

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

105-116: Function serialization properly updated with source location and name changes.

The implementation correctly:

  • Includes source location via get_source_location().serialize_to_str()
  • Changes from direct name access to child node serialization with proper error handling
  • Maintains consistent indentation structure for the nested Name block
  • Handles both parameter and no-parameter cases appropriately

118-130: No-parameter case properly handled.

The no-parameter branch of the function serialization maintains the same source location and name serialization changes while correctly handling the "No Params" case.

tests/tdl/test-parser.cpp (1)

271-273: No further assertions required – full-string comparison already enforces coordinate accuracy

The end-to-end equality check against cExpectedSerializedAst will fail if any location is off by even one character or line, so all source-location coordinates (including namespace, struct, functions, etc.) are already fully verified. Adding individual find-style checks would be purely redundant:

• Full literal match covers every position resolve_review_comment

@LinZhihao-723
LinZhihao-723 merged commit 017533e into y-scope:main Aug 26, 2025
8 checks passed
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