Skip to content

[clang][docs] Add documentation for APValue constructors #109994

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

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

tbaederr
Copy link
Contributor

I always get confused when looking at these.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

I always get confused when looking at these.


Full diff: https://github.com/llvm/llvm-project/pull/109994.diff

1 Files Affected:

  • (modified) clang/include/clang/AST/APValue.h (+40)
diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h
index c4206b73b11562..61d51523937494 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -314,51 +314,91 @@ class APValue {
   DataType Data;
 
 public:
+  /// Creates an empty APValue of type None.
   APValue() : Kind(None) {}
+  /// Creates an integer APValue holding the given value.
   explicit APValue(APSInt I) : Kind(None) {
     MakeInt(); setInt(std::move(I));
   }
+  /// Creates a float APValue holding the given value.
   explicit APValue(APFloat F) : Kind(None) {
     MakeFloat(); setFloat(std::move(F));
   }
+  /// Creates an fixed-point APValue holding the given value.
   explicit APValue(APFixedPoint FX) : Kind(None) {
     MakeFixedPoint(std::move(FX));
   }
+  /// Creates a vector APValue with \p N elements. The elements
+  /// are read from \p E.
   explicit APValue(const APValue *E, unsigned N) : Kind(None) {
     MakeVector(); setVector(E, N);
   }
+  /// Creates an integer complex APValue with the given real and imaginary
+  /// values.
   APValue(APSInt R, APSInt I) : Kind(None) {
     MakeComplexInt(); setComplexInt(std::move(R), std::move(I));
   }
+  /// Creates a float complex APValue with the given real and imaginary values.
   APValue(APFloat R, APFloat I) : Kind(None) {
     MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I));
   }
   APValue(const APValue &RHS);
   APValue(APValue &&RHS);
+  /// Creates an lvalue APValue without an lvalue path.
+  /// \param B The base of the lvalue.
+  /// \param O The offset of the lvalue.
+  /// \param N Marker. Pass an empty NoValuePath.
+  /// \param IsNullPtr Whether this lvalue is a null pointer.
   APValue(LValueBase B, const CharUnits &O, NoLValuePath N,
           bool IsNullPtr = false)
       : Kind(None) {
     MakeLValue(); setLValue(B, O, N, IsNullPtr);
   }
+  /// Creates an lvalue APValue with an lvalue path.
+  /// \param B The base of the lvalue.
+  /// \param O The offset of the lvalue.
+  /// \param Path The lvalue path.
+  /// \param OnePastTheEnd Whether this lvalue is one-past-the-end of the
+  /// subobject it points to.
+  /// \param IsNullPtr Whether this lvalue is a null pointer.
   APValue(LValueBase B, const CharUnits &O, ArrayRef<LValuePathEntry> Path,
           bool OnePastTheEnd, bool IsNullPtr = false)
       : Kind(None) {
     MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr);
   }
+  /// Creates a new array APValue.
+  /// \param UninitArray Marker. Pass an empty UninitArray.
+  /// \param InitElts Number of elements you're going to initialize in the
+  /// array.
+  /// \param Size Full size of the array.
   APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(None) {
     MakeArray(InitElts, Size);
   }
+  /// Creates a new struct APValue.
+  /// \param UninitStruct Marker. Pass an empty UninitStruct.
+  /// \param B Number of bases.
+  /// \param M Number of members.
   APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) {
     MakeStruct(B, M);
   }
+  /// Creates a new union APValue.
+  /// \param D The FieldDecl of the active union member.
+  /// \param V The value of the active union member.
   explicit APValue(const FieldDecl *D, const APValue &V = APValue())
       : Kind(None) {
     MakeUnion(); setUnion(D, V);
   }
+  /// Creates a new member pointer APValue.
+  /// \param Member Declaration of the member
+  /// \param IsDerivedMember Whether member is a derived one.
+  /// \param Path The path of the member.
   APValue(const ValueDecl *Member, bool IsDerivedMember,
           ArrayRef<const CXXRecordDecl*> Path) : Kind(None) {
     MakeMemberPointer(Member, IsDerivedMember, Path);
   }
+  /// Creates a new address label diff APValue.
+  /// \param LHSExpr The left-hand side of the difference.
+  /// \param RHSExpr The right-hand side of the difference.
   APValue(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr)
       : Kind(None) {
     MakeAddrLabelDiff(); setAddrLabelDiff(LHSExpr, RHSExpr);

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

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

LGTM overall; I just have some minor comments

/// Creates a new struct APValue.
/// \param UninitStruct Marker. Pass an empty UninitStruct.
/// \param B Number of bases.
/// \param M Number of members.
APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like these parameters should have more descriptive names, because just B meaning ‘number of bases’ is rather horrible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's one reason why I wrote this patch.

/// \param B The base of the lvalue.
/// \param O The offset of the lvalue.
/// \param N Marker. Pass an empty NoValuePath.
/// \param IsNullPtr Whether this lvalue is a null pointer.
APValue(LValueBase B, const CharUnits &O, NoLValuePath N,
Copy link
Member

Choose a reason for hiding this comment

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

Same here actually; not having single-letter parameter names would probably also help...

Copy link
Member

@Sirraide Sirraide Oct 2, 2024

Choose a reason for hiding this comment

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

(and imo the NoLValuePath parameter shouldn’t even have a name to indicate it’s really just a marker; you can just make a new one in the call to setLValue() since that’s a no-op anyway)

@tbaederr tbaederr merged commit bba3849 into llvm:main Oct 4, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants