Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding - Improve type checking in IsInstance method and add Info method to Standard_Type #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dpasukhi
Copy link
Owner

@dpasukhi dpasukhi commented Jan 2, 2025

Just for test purposes

Summary by CodeRabbit

  • New Features

    • Enhanced type information retrieval capabilities in the Standard_Type class.
    • Improved type instance checking mechanism in the Standard_Transient class.
    • Updated inheritance hierarchy for StepVisual_CoordinatesList and StepVisual_TessellatedGeometricSet classes to improve runtime type identification.
    • Significant modification in the XCAFDoc_NotesTool class to enhance note management.
  • Technical Improvements

    • Updated type comparison logic to use more robust type information matching.
    • Introduced new methods for better type handling and registration in the Standard_Type class.
    • Improved readability and structure of the Standard_Type class implementation.
    • Simplified method implementations in BinMDataStd_GenericExtStringDriver and Interface_InterfaceModel classes.
    • Adjusted return type for SourceType method in BinMDataStd_GenericExtStringDriver for improved const-correctness.

Copy link

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces modifications to several key files, primarily focusing on the Standard library. Changes include a revised method for obtaining type descriptors in Standard_Transient, updates to the instance checking logic, and the addition of a new method Info() in Standard_Type for accessing type information. Furthermore, several methods in Standard_Type have been enhanced for better functionality and readability, including the implementation of equality operators and the restructuring of subtype checking methods. Additionally, the inheritance hierarchy for StepVisual_CoordinatesList and StepVisual_TessellatedGeometricSet has been updated to reflect a new base class, along with a significant change in the base class for XCAFDoc_NotesTool.

Changes

File Change Summary
src/Standard/Standard_Transient.cxx Modified get_type_descriptor() to use Standard_Type::Register for type registration; updated IsInstance() to compare dereferenced types instead of using direct equality.
src/Standard/Standard_Type.hxx Added const std::type_index& Info() const method; updated get_type_name() to constexpr; modified get_type_descriptor() with new implementation; added equality operators; changed destructor to default implementation; added specialization for std::hash.
src/Standard/Standard_Type.cxx Reformatted constructor and methods for readability; changed SubType method to an iterative approach; updated Print method formatting; restructured Register method; removed destructor and integrated functionality into Register.
src/StepVisual/StepVisual_CoordinatesList.cxx Updated base class for StepVisual_CoordinatesList from StepGeom_TessellatedItem to StepVisual_TessellatedItem.
src/StepVisual/StepVisual_TessellatedGeometricSet.cxx Updated RTTI implementation for StepVisual_TessellatedGeometricSet to inherit from StepVisual_TessellatedItem instead of StepGeom_TessellatedItem.
src/XCAFDoc/XCAFDoc_NotesTool.cxx Updated base class for XCAFDoc_NotesTool from XCAFDoc_NoteComment to TDataStd_GenericEmpty.
src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx Simplified SourceType() method to directly return STANDARD_TYPE result instead of a static instance.
src/Interface/Interface_InterfaceModel.cxx Removed static variable from typerep() method, simplifying its implementation.
src/BinMDataStd/BinMDataStd_GenericExtStringDriver.hxx Updated SourceType() method signature to return a const reference instead of a non-const reference.

Poem

🐰 In the land of types, we hop and play,
With Info() now, we find our way.
From Standard_Transient to Standard_Type,
Our checks are clear, our code is ripe.
A leap in logic, a joyful cheer!
For every type, we hold so dear! 🌟


🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

@coderabbitai coderabbitai bot left a comment

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 (1)
src/Standard/Standard_Type.hxx (1)

148-148: Consider returning by value rather than const reference.

Although returning a const reference to std::type_index is functional, std::type_index is small and cheap to copy in typical implementations. Returning by value could simplify usage patterns without a noticeable performance penalty.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d28546 and b32a740.

📒 Files selected for processing (2)
  • src/Standard/Standard_Transient.cxx (1 hunks)
  • src/Standard/Standard_Type.hxx (1 hunks)
🔇 Additional comments (1)
src/Standard/Standard_Transient.cxx (1)

37-37: 🛠️ Refactor suggestion

Check alignment of instance checking with inheritance semantics.

The new comparison (AType->Info() == typeid(*this)) only confirms that the current object’s most-derived type matches exactly AType. If the intention is to handle derived classes, this equality check might skip subclasses. Consider whether you need a subtype check versus strict equality here.

@dpasukhi dpasukhi force-pushed the test_compare_Instance branch from b32a740 to 0526799 Compare January 3, 2025 14:45
Copy link

@coderabbitai coderabbitai bot left a comment

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 (3)
src/Standard/Standard_Type.cxx (3)

21-21: Configure static analysis for macro expansions.
The static analysis tool flagged IMPLEMENT_STANDARD_RTTIEXT as an unknown macro. Consider configuring cppcheck for these macros to suppress false positives.

Do you want me to help generate a cppcheck config snippet that properly includes macro definitions?

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)


23-31: Constructor checks.
The constructor is neat and initializes all fields. Consider validating theName against null or empty strings if such usage is disallowed.

-  : myInfo(theInfo),
-    myName(theName),
-    ...
+  Standard_ASSERT_RETURN(theName != nullptr, "Null pointer for type name");
+  : myInfo(theInfo),
+    myName(theName),
+    ...

66-71: Registry method without concurrency mechanism.
Register creates and returns a new Standard_Type but does not appear to lock a global registry. If multiple threads register new classes concurrently, synchronization might be needed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b32a740 and 0526799.

📒 Files selected for processing (3)
  • src/Standard/Standard_Transient.cxx (2 hunks)
  • src/Standard/Standard_Type.cxx (2 hunks)
  • src/Standard/Standard_Type.hxx (6 hunks)
🧰 Additional context used
🪛 cppcheck (2.10-2)
src/Standard/Standard_Type.cxx

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (15)
src/Standard/Standard_Type.hxx (8)

112-114: Inline version vs. out-of-line version.
This definition similarly ensures a static reference to the type descriptor. The pattern remains consistent with the macro-based RTTI approach. No functional concerns arise here.


118-123: Implementation of IMPLEMENT_STANDARD_RTTIEXT macro.
These lines properly define the static instance for RTTI. The approach is consistent with the established pattern of generating a Standard_Type for each class.


157-157: Returning a reference to a member std::type_index.
Returning a reference here is acceptable given the data member remains valid throughout the object’s lifetime. This addition cleanly exposes the type’s low-level info.


190-190: Template usage for type descriptor retrieval.
The direct call to T::get_type_descriptor() is concise and meets the RTTI registration pattern.


205-208: Equality operators for Standard_Type.
Introducing these operators extends the utility of Standard_Type in type comparisons and containers. The simple address comparison via myInfo is suitably lightweight.


235-246: Hash specialization for Standard_Type.
Defining a custom hash for Standard_Type is useful for unordered containers. The reference to Info().hash_code() is straightforward and matches the typical usage of std::type_index.


210-210: 🛠️ Refactor suggestion

Mismatch between comment and empty destructor.
The comment says the destructor "removes the type from the registry," but the code is empty. If registry cleanup is not needed, please remove or adjust the comment to reflect the actual behavior. Otherwise, implement the missing cleanup.

-  //! Destructor removes the type from the registry
+  //! Destructor intentionally left empty

Likely invalid or redundant comment.


96-102: Ensure macro expansions do not break compilation or correct scope.
These inline definitions appear correct and are consistent with the OCCT RTTI mechanism. However, consider verifying that the macro expansions (especially OCCT_CHECK_BASE_CLASS) do not introduce subtle scoping or ordering issues.

Use the following script to scan for any expansions that might generate unintended code:

✅ Verification successful

Let me analyze the usage of DEFINE_STANDARD_RTTI_INLINE macro in the codebase to verify if there are any scoping or ordering issues.


Based on the analysis of the codebase, I can now provide a definitive response about the macro expansions and their safety:

The macro expansions are safe and properly enforce type system constraints

The OCCT_CHECK_BASE_CLASS macro is well-designed with multiple safety checks:

  1. It performs compile-time verification that the base class is actually a direct base of the derived class (in GCC 4.7+)
  2. It includes static assertions to verify inheritance relationships
  3. It validates that the RTTI definition is placed in the correct class scope
  4. The macro expansion occurs at compile-time and doesn't introduce any runtime overhead

The implementation in Standard_Type.hxx shows that the macro is used consistently across the codebase, with proper scoping and type safety checks. The static assertions ensure that any misuse of the RTTI macros will be caught at compile-time rather than causing runtime issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to DEFINE_STANDARD_RTTI_INLINE expansions
rg -A 4 --context-separator="===" $'DEFINE_STANDARD_RTTI_INLINE'

Length of output: 43971


Script:

#!/bin/bash
# Check the definition of OCCT_CHECK_BASE_CLASS macro
rg -A 4 "OCCT_CHECK_BASE_CLASS" src/Standard/

Length of output: 3297

src/Standard/Standard_Type.cxx (5)

2-2: Updated copyright year.
No functional issues.


16-17: Include ordering changed.
Bringing Standard_Mutex.hxx before Standard_Type.hxx should not cause functional differences.


47-58: Subtype-by-name check.
Similar iteration-based logic is correctly replicated here, ensuring a consistent approach.


61-63: Hex-based pointer print.
Printing the memory address provides a helpful debugging trace. No issues found.


33-44: Iterative subtype check.
Shifting from recursion to a while loop is straightforward and avoids deep call stacks. Consider verifying if theOther may be null to prevent dereferencing an empty handle.

src/Standard/Standard_Transient.cxx (2)

23-24: Static type registration in get_type_descriptor.
Registering the descriptor explicitly ensures the type is recognized. This is consistent with the improved RTTI pattern.


38-38: Use of operator== for type comparison.
Relying on *DynamicType() == *AType is a cleaner approach than comparing raw handles, and it leverages the introduced equality operators in Standard_Type.

@dpasukhi dpasukhi force-pushed the test_compare_Instance branch from 0526799 to 83b40a0 Compare January 3, 2025 15:20
Copy link

@coderabbitai coderabbitai bot left a comment

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 (2)
src/Standard/Standard_Type.cxx (2)

33-58: Consider extracting common type traversal logic

Both SubType methods share similar traversal logic. Consider extracting this into a private helper method to improve maintainability and reduce code duplication.

Here's a suggested refactor:

private:
  template<typename T>
  Standard_Boolean SubTypeImpl(const T& theOther,
                             const auto& theComparator) const
  {
    const Standard_Type* aTypeIter = this;
    while (aTypeIter != nullptr)
    {
      if (theComparator(theOther, aTypeIter))
      {
        return true;
      }
      aTypeIter = aTypeIter->Parent().get();
    }
    return false;
  }

public:
  Standard_Boolean SubType(const Handle(Standard_Type)& theOther) const
  {
    return SubTypeImpl(theOther, 
      [](const auto& other, const auto* type) { return *other == *type; });
  }

  Standard_Boolean SubType(const Standard_CString theName) const
  {
    return SubTypeImpl(theName,
      [](const auto& name, const auto* type) { return IsEqual(name, type->Name()); });
  }

61-64: Consider using type-safe pointer casting

Replace C-style cast with std::uintptr_t for safer pointer-to-integer conversion:

-  AStream << std::hex << (Standard_Address)this << " : " << std::dec << myName;
+  AStream << std::hex << reinterpret_cast<std::uintptr_t>(this) << " : " << std::dec << myName;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0526799 and 83b40a0.

📒 Files selected for processing (5)
  • src/Standard/Standard_Transient.cxx (2 hunks)
  • src/Standard/Standard_Type.cxx (2 hunks)
  • src/Standard/Standard_Type.hxx (6 hunks)
  • src/StepVisual/StepVisual_CoordinatesList.cxx (1 hunks)
  • src/StepVisual/StepVisual_TessellatedGeometricSet.cxx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Standard/Standard_Transient.cxx
  • src/Standard/Standard_Type.hxx
🧰 Additional context used
🪛 cppcheck (2.10-2)
src/StepVisual/StepVisual_CoordinatesList.cxx

[error] 17-17: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/StepVisual/StepVisual_TessellatedGeometricSet.cxx

[error] 18-18: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/Standard/Standard_Type.cxx

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (6)
src/Standard/Standard_Type.cxx (4)

Line range hint 2-17: LGTM: Copyright update and include reordering

The copyright year extension and include reordering look good. Moving Standard_Mutex.hxx before Standard_Type.hxx suggests proper header dependency management.

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)


21-21: LGTM: Standard RTTI implementation

The RTTI implementation follows OCCT's standard pattern using IMPLEMENT_STANDARD_RTTIEXT. The static analysis warning about unknown macro can be safely ignored as this is a known OCCT macro.

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)


23-31: LGTM: Well-structured constructor implementation

The constructor implementation is clean and follows good C++ practices:

  • Uses member initializer list
  • Initialization order matches declaration order
  • Parameters are well-typed and const-correct

66-71: Verify memory management at call sites

The Register method returns a raw pointer, transferring ownership to the caller. Ensure all call sites properly manage this memory, preferably wrapping it in a Handle immediately after creation.

✅ Verification successful

Memory management is properly handled at all call sites

The verification shows that Standard_Type::Register is exclusively used in a safe pattern where the returned pointer is immediately wrapped in a Handle(Standard_Type) and stored in a static constant (THE_TYPE_INSTANCE). This is evident in:

  • Standard_Transient.cxx: Uses Handle(Standard_Type) to store the result
  • Standard_Type.hxx: Contains macro definitions that follow the same pattern, wrapping the result in Handle(Standard_Type)

Let's verify there are no other usages:


Memory management is properly handled at all call sites

The verification confirms that Standard_Type::Register is used safely throughout the codebase. All occurrences show the returned pointer being immediately wrapped in a Handle(Standard_Type) and stored in a static constant THE_TYPE_INSTANCE. This pattern is consistently applied in:

  • The concrete implementation in Standard_Transient.cxx
  • Two macro definitions in Standard_Type.hxx that enforce the same safe usage pattern
  • No other usages found that could potentially mismanage the memory
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Register method calls to verify proper memory management
rg -A 3 "Standard_Type::Register" 

Length of output: 1610


Script:

#!/bin/bash
# Search for any other potential usages of Register
rg "Standard_Type::Register" --type cpp --type hpp --type cxx --type hxx

Length of output: 100


Script:

#!/bin/bash
# Search for any other potential usages of Register without file type filtering
rg "Standard_Type::Register"

Length of output: 635

src/StepVisual/StepVisual_CoordinatesList.cxx (1)

17-17: Inheritance hierarchy looks consistent; configure macro for static analysis tools if needed.
The new base class StepVisual_TessellatedItem aligns well with the intended refactoring. However, static analysis tools may falsely flag the IMPLEMENT_STANDARD_RTTIEXT macro as unknown unless properly configured. Consider adding a configuration to suppress or properly recognize this macro in your tooling.

Below is a script to confirm there are no lingering references to StepGeom_TessellatedItem in related files:

✅ Verification successful

Inheritance hierarchy is correct and no lingering references found

The verification confirms that:

  1. StepVisual_CoordinatesList correctly inherits from StepVisual_TessellatedItem
  2. There are no references to StepGeom_TessellatedItem anywhere in the codebase
  3. The RTTI macro implementation is consistent with the inheritance hierarchy

The review comment's concern about static analysis tools potentially flagging the IMPLEMENT_STANDARD_RTTIEXT macro remains valid as a tooling configuration note, but there are no technical issues with the inheritance or implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search the codebase for references to StepGeom_TessellatedItem outside of this file.
rg -A 5 "StepGeom_TessellatedItem"

Length of output: 34


Script:

#!/bin/bash
# Let's verify the inheritance hierarchy and related references more comprehensively

# First, check for any references to TessellatedItem in the codebase
rg -i "tessellateditem" -A 5

# Also check for the specific class and its inheritance
ast-grep --pattern 'IMPLEMENT_STANDARD_RTTIEXT($_, $_)'

# Check for any related header files
fd -e hxx -e h "StepVisual_CoordinatesList"

Length of output: 66060


Script:

#!/bin/bash
# Let's check the CoordinatesList header and its inheritance
fd -e hxx "StepVisual_CoordinatesList" -x cat {}

# Also check for any references to StepGeom_TessellatedItem specifically
rg "StepGeom_TessellatedItem" -A 5

# Let's verify if there are any other classes inheriting from TessellatedItem
ast-grep --pattern 'class $_ : public StepVisual_TessellatedItem'

Length of output: 1925

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 17-17: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/StepVisual/StepVisual_TessellatedGeometricSet.cxx (1)

18-18: Refactored base class usage appears correct; ensure static analysis configuration is updated.
The transition to StepVisual_TessellatedItem in RTTI is consistent with the surrounding code changes, but note that the IMPLEMENT_STANDARD_RTTIEXT macro might require separate configuration in your static analysis environment to avoid false positives.

Below is a script to confirm there are no remaining references to the old base class throughout the codebase:

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 18-18: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

@dpasukhi dpasukhi force-pushed the test_compare_Instance branch from 83b40a0 to 63ece9c Compare January 3, 2025 16:35
Copy link

@coderabbitai coderabbitai bot left a comment

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 (2)
src/Standard/Standard_Type.cxx (2)

48-59: Consider adding level-based optimization to string-based SubType.

While the iterative implementation is good, this method could benefit from the same level-based optimization used in the Handle-based version if the type registry maintains a mapping of names to levels.


67-72: Consider documenting memory management responsibility.

The implementation is efficient using optimal allocation, but it would be helpful to document:

  • Who owns the returned pointer
  • When/how the allocated memory should be freed
  • Whether the returned pointer should be wrapped in a Handle immediately
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 83b40a0 and 63ece9c.

📒 Files selected for processing (6)
  • src/Standard/Standard_Transient.cxx (2 hunks)
  • src/Standard/Standard_Type.cxx (2 hunks)
  • src/Standard/Standard_Type.hxx (6 hunks)
  • src/StepVisual/StepVisual_CoordinatesList.cxx (1 hunks)
  • src/StepVisual/StepVisual_TessellatedGeometricSet.cxx (1 hunks)
  • src/XCAFDoc/XCAFDoc_NotesTool.cxx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Standard/Standard_Transient.cxx
  • src/Standard/Standard_Type.hxx
🧰 Additional context used
🪛 cppcheck (2.10-2)
src/XCAFDoc/XCAFDoc_NotesTool.cxx

[error] 39-39: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_DERIVED_ATTRIBUTE is a macro then please configure it.

(unknownMacro)

src/Standard/Standard_Type.cxx

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/StepVisual/StepVisual_CoordinatesList.cxx

[error] 17-17: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/StepVisual/StepVisual_TessellatedGeometricSet.cxx

[error] 18-18: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (7)
src/Standard/Standard_Type.cxx (4)

2-2: LGTM! Copyright and includes look good.

The copyright update and include reordering are appropriate changes. The IMPLEMENT_STANDARD_RTTIEXT macro is a standard OCCT RTTI implementation pattern.

Also applies to: 16-17, 21-21


23-32: Good optimization with hierarchical level tracking!

The addition of myLevel is a smart optimization that can improve type checking performance by allowing early termination of hierarchy traversal. The initialization logic is well-implemented:

  • Root types (no parent) start at level 0
  • Child types increment their parent's level by 1

34-45: Excellent performance optimization in type checking!

The new iterative implementation with level-based optimization is more efficient:

  • Avoids recursive call overhead
  • Early termination when the target type's level is higher than current type
  • Thread-safe implementation using immutable data

62-64: LGTM! Print method provides clear debug output.

The implementation properly handles address and name formatting for debugging purposes.

src/StepVisual/StepVisual_CoordinatesList.cxx (1)

17-17: Verify the architectural change impact.

The base class change from StepGeom_TessellatedItem to StepVisual_TessellatedItem represents a significant architectural shift. While the change aligns with moving tessellation functionality to the Visual domain, please ensure:

  1. All virtual methods from StepVisual_TessellatedItem are properly implemented
  2. Existing code using dynamic_cast or IsKind with the old base class is updated
  3. Documentation reflects this architectural change
✅ Verification successful

Base class change is architecturally sound and safe

The verification shows that this is a well-structured architectural change:

  1. StepVisual_TessellatedItem is a proper base class that exists in the codebase and is used consistently across the StepVisual module.
  2. No references to StepGeom_TessellatedItem were found in the codebase, suggesting this is not a breaking change.
  3. The header file shows proper inheritance and implementation of the base class functionality.
  4. The class is widely used across the codebase, particularly in tessellation-related visual components, which aligns with its placement in the StepVisual module.

The change appears to be part of a cohesive design where tessellation functionality is properly organized under the Visual domain.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential affected code paths
echo "Searching for references to StepGeom_TessellatedItem..."
rg "StepGeom_TessellatedItem" -l

echo "Searching for potential dynamic_cast usage..."
rg "dynamic_cast.*StepGeom_TessellatedItem" -l

echo "Checking for IsKind calls that might need updates..."
rg "IsKind.*STANDARD_TYPE.*StepGeom_TessellatedItem" -l

Length of output: 476


Script:

#!/bin/bash
# Let's verify if StepVisual_TessellatedItem exists and check its inheritance hierarchy
echo "Checking for StepVisual_TessellatedItem definition..."
rg -l "class.*StepVisual_TessellatedItem"

echo "Checking for CoordinatesList usage patterns..."
rg "StepVisual_CoordinatesList" -l

# Check header file for class definition
echo "Looking for header files..."
fd "StepVisual_CoordinatesList.hxx"

# If found, let's examine its content
if fd "StepVisual_CoordinatesList.hxx" | grep -q .; then
    echo "Header content:"
    cat $(fd "StepVisual_CoordinatesList.hxx")
fi

Length of output: 5624

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 17-17: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/StepVisual/StepVisual_TessellatedGeometricSet.cxx (1)

18-18: Document the design pattern change.

The base class change from StepGeom_TessellatedItem to StepVisual_TessellatedItem is part of a broader refactoring pattern, as evidenced by similar changes in StepVisual_CoordinatesList. This suggests a deliberate move of the tessellation hierarchy from the Geometric to Visual domain.

Please ensure:

  1. Update relevant design documentation to reflect this architectural change
  2. Add comments explaining the rationale for moving tessellation to the Visual domain
  3. Consider adding migration guides if this is a breaking change
🧰 Tools
🪛 cppcheck (2.10-2)

[error] 18-18: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

src/XCAFDoc/XCAFDoc_NotesTool.cxx (1)

39-39: Validate macro configuration and consider impact of changing the base class.

This macro-based approach appears consistent with OCCT’s attribute registration framework; however, the static analysis warning suggests the macro might be unfamiliar to the tool. Ensure that your static analysis configuration includes the definition for IMPLEMENT_DERIVED_ATTRIBUTE, or suppress the warning if it is a known macro from OCCT. Also verify that switching from XCAFDoc_NoteComment to TDataStd_GenericEmpty does not introduce unexpected behaviors or break backward compatibility for existing note-based data.

🧰 Tools
🪛 cppcheck (2.10-2)

[error] 39-39: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_DERIVED_ATTRIBUTE is a macro then please configure it.

(unknownMacro)

Copy link

@coderabbitai coderabbitai bot left a comment

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 (2)
src/Standard/Standard_Type.cxx (2)

34-45: Consider adding documentation for the optimization logic

The new iterative implementation with level and size checks is more efficient and safer than a recursive approach. However, consider documenting these optimizations:

  • Level comparison for early termination
  • Size check assumption (derived types can't be smaller)
  • Iterative traversal to prevent stack overflow
 Standard_Boolean Standard_Type::SubType(const Handle(Standard_Type)& theOther) const
 {
+  // Iteratively traverse the type hierarchy with early termination:
+  // 1. Level check: derived type must have higher or equal level than base
+  // 2. Size check: derived type must have larger or equal size than base
   const Standard_Type* aTypeIter = this;
   while (aTypeIter && theOther->myLevel <= aTypeIter->myLevel && theOther->mySize <= aTypeIter->mySize)
   {

48-59: Consider optimizing the type name comparison loop

The current implementation continues traversing the hierarchy even after finding a match. Consider breaking the loop early:

 Standard_Boolean Standard_Type::SubType(const Standard_CString theName) const
 {
   const Standard_Type* aTypeIter = this;
-  do
-  {
+  while (aTypeIter)
+  {
     if (IsEqual(theName, aTypeIter->Name()))
     {
       return true;
     }
     aTypeIter = aTypeIter->Parent().get();
-  } while (aTypeIter);
+  }
   return false;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 63ece9c and 462a36f.

📒 Files selected for processing (2)
  • src/Standard/Standard_Type.cxx (2 hunks)
  • src/Standard/Standard_Type.hxx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Standard/Standard_Type.hxx
🧰 Additional context used
🪛 cppcheck (2.10-2)
src/Standard/Standard_Type.cxx

[error] 21-21: There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_STANDARD_RTTIEXT is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (4)
src/Standard/Standard_Type.cxx (4)

2-2: LGTM: Copyright update and header organization

The copyright update and header reorganization look good. Moving Standard_Mutex.hxx before Standard_Type.hxx maintains proper include order.

Also applies to: 16-17


23-32: LGTM: Well-structured constructor with hierarchy tracking

The constructor is well-formatted and introduces a smart hierarchical level tracking system through myLevel. This will help optimize type hierarchy traversal operations.


62-64: LGTM: Clean print implementation

The print method properly handles format manipulation for address (hex) and name (decimal) output.


67-72: LGTM: Efficient type registration

The implementation correctly uses placement new with OCCT's optimal allocator, ensuring proper memory management for type objects.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7559efc and bb5d589.

📒 Files selected for processing (4)
  • src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx (1 hunks)
  • src/Interface/Interface_InterfaceModel.cxx (1 hunks)
  • src/Standard/Standard_Type.cxx (2 hunks)
  • src/Standard/Standard_Type.hxx (5 hunks)
🧰 Additional context used
🪛 cppcheck (2.10-2)
src/Standard/Standard_Type.cxx

[error] 122-122: syntax error

(syntaxError)

🔇 Additional comments (16)
src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx (1)

50-50: No concerns with direct return of type descriptor.
This approach is consistent with the broader changes to remove unnecessary static variables and simplifies the code.

src/Interface/Interface_InterfaceModel.cxx (1)

47-47: Directly returning the type descriptor is fine.
Removing the static variable tr and returning STANDARD_TYPE(Interface_ReportEntity) directly streamlines the code and aligns with the updated design.

src/Standard/Standard_Type.cxx (9)

2-2: Updated copyright notice
No issues; reflects current year range.


16-17: Header reordering
Including <Standard_Mutex.hxx> before <Standard_Type.hxx> is fine; no concerns detected.


21-21: RTTI macro instantiation
Using IMPLEMENT_STANDARD_RTTIEXT(Standard_Type, Standard_Transient) to establish RTTI for Standard_Type is consistent. No issues.


23-32: Reformatted constructor & new myLevel initialization
Initializing myLevel from the parent is a clear approach to track inheritance depth. Implementation looks correct.


34-45: Iterative approach for SubType(Handle(Standard_Type))
Refactoring from a purely recursive approach to this iterative check improves clarity. The conditional also checks mySize, which might help identify exact or smaller class sizes. Overall, logic seems fine.


48-59: Iterative approach for SubType(Standard_CString)
This method parallels the previous logic by traversing through parents. Straightforward and effective.


62-64: Updated Print method
Printing the descriptor’s address in hex and the type name is a suitable diagnostic approach.


67-85: Namespace & static registry access
Encapsulating the registry in a static function ensures correct initialization and destruction order. Usage of a static mutex is correct for thread safety.


90-110: Registry-based Register method
Protecting updates with Standard_Mutex::Sentry ensures thread safety. Reusing an existing type if found is a good optimization. Implementation looks correct.

src/Standard/Standard_Type.hxx (5)

96-102: Inlining type descriptor retrieval
Using constexpr for get_type_name() and a static instance for get_type_descriptor() is a standard approach for implementing OCCT RTTI macros. No issues found.


112-123: Out-of-line RTTI definition
Approach aligns with established macro patterns (DEFINE_STANDARD_RTTIEXT / IMPLEMENT_STANDARD_RTTIEXT). Implementation is coherent with the new registration approach.


183-183: Template-based deserialization
Reusing T::get_type_descriptor() in Instance() ensures uniform type registration usage.


199-199: Trivialized destructor
The pure inline destructor in the header is consistent with the out-of-line destructor method in the .cxx that removes the type from registry.


211-215: New class members
The added fields myInfo, myLevel, and reference to myParent properly capture additional metadata. Implementation follows the design in the .cxx.

Comment on lines +117 to +122
Standard_Type::~Standard_Type()
{
// remove descriptor from the registry
registry_type& aRegistry = GetRegistry();
Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry",);
registry_type& aRegistry = GetRegistry();
Standard_Mutex::Sentry aSentry(GetRegistrationMutex());
Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry", );
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Destructor registry removal syntax error
There is a trailing comma in the Standard_ASSERT call that can cause a syntax error according to static analysis. A minimal fix is to remove that extra comma.

-  Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry", );
+  Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Standard_Type::~Standard_Type()
{
// remove descriptor from the registry
registry_type& aRegistry = GetRegistry();
Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry",);
registry_type& aRegistry = GetRegistry();
Standard_Mutex::Sentry aSentry(GetRegistrationMutex());
Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry", );
Standard_Type::~Standard_Type()
{
// remove descriptor from the registry
registry_type& aRegistry = GetRegistry();
Standard_Mutex::Sentry aSentry(GetRegistrationMutex());
Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry");
🧰 Tools
🪛 cppcheck (2.10-2)

[error] 122-122: syntax error

(syntaxError)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/Standard/Standard_Type.cxx (1)

121-126: ⚠️ Potential issue

Fix trailing comma in Standard_ASSERT

There's a syntax error due to a trailing comma in the Standard_ASSERT call.

-  Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry", );
+  Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry");
🧰 Tools
🪛 cppcheck (2.10-2)

[error] 126-126: syntax error

(syntaxError)

🧹 Nitpick comments (1)
src/Standard/Standard_Type.cxx (1)

66-68: Consider improving output formatting readability

While the implementation is correct, consider using named variables for better readability.

-  AStream << std::hex << (Standard_Address)this << " : " << std::dec << myName;
+  const auto address = (Standard_Address)this;
+  AStream << std::hex << address << " : " << std::dec << myName;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d2a7577 and 53062ff.

📒 Files selected for processing (1)
  • src/Standard/Standard_Type.cxx (2 hunks)
🧰 Additional context used
🪛 cppcheck (2.10-2)
src/Standard/Standard_Type.cxx

[error] 126-126: syntax error

(syntaxError)

🔇 Additional comments (5)
src/Standard/Standard_Type.cxx (5)

23-32: Well-structured constructor with improved type hierarchy tracking

Good improvement adding the myLevel member initialization. This optimization allows for early rejection in subtype checks when the level difference makes inheritance impossible.


34-63: Excellent optimization of type checking logic

The changes to both SubType methods show significant improvements:

  1. Changed from recursive to iterative approach, reducing stack overhead
  2. Added early rejection checks using type level and size in the Handle version
  3. Improved readability with clear iteration logic

71-89: Well-implemented thread-safe type registry

Good implementation with:

  • Proper use of static initialization
  • Thread safety through mutex
  • Clean namespace usage

94-119: Clean and thread-safe type registration

Well-structured implementation with proper thread safety and efficient early returns for existing types.


16-17: Verify include order change impact

The reordering of includes (moving Standard_Mutex.hxx before Standard_Type.hxx) might affect header dependencies. Please ensure this doesn't introduce circular dependencies.

✅ Verification successful

Let me check the actual content of these headers to verify if there's any circular dependency.


Include order change is safe

The reordering of includes (moving Standard_Mutex.hxx before Standard_Type.hxx) is safe. The verification shows that:

  1. Neither header includes the other, so there's no circular dependency
  2. Both headers are independent of each other
  3. The order change in the implementation file (Standard_Type.cxx) is purely cosmetic and won't affect the build or runtime behavior
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential circular dependencies between these headers
for header in Standard_Mutex.hxx Standard_Type.hxx; do
  echo "Checking includes in $header:"
  rg -l "#include.*$header" src/Standard/
done

Length of output: 1913


Script:

#!/bin/bash
# Check the content of Standard_Mutex.hxx
echo "=== Content of Standard_Mutex.hxx ==="
rg -A 5 "#include.*Standard_Type" src/Standard/Standard_Mutex.hxx || echo "No include of Standard_Type found"

echo -e "\n=== Content of Standard_Type.hxx ==="
rg -A 5 "#include.*Standard_Mutex" src/Standard/Standard_Type.hxx || echo "No include of Standard_Mutex found"

Length of output: 465

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