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

Fix function parameter types #157

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions source/api/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ parseParameters(
{
for(ParmVarDecl const* P : D->parameters())
{
// KRYSTIAN NOTE: call getOriginalType if we want to preserve
// top-level cv-qualfiers/array types/function types
FieldTypeInfo& FieldInfo = I.Params.emplace_back(
getTypeInfoForType(P->getOriginalType()),
getTypeInfoForType(P->getType()),
P->getNameAsString());
FieldInfo.DefaultValue = getSourceCode(
D, P->getDefaultArgRange());
Expand Down Expand Up @@ -1292,10 +1294,17 @@ ASTVisitor::
WalkUpFromParmVarDecl(
ParmVarDecl* D)
{
// We do nothing here, to prevent ParmVarDecl
// from appearing as VarDecl. We pick up the
// function parameters as a group from the
// FunctionDecl instead of visiting ParmVarDecl.
Assert(shouldTraversePostOrder() &&
"expected post-order traversal");
Copy link
Member

Choose a reason for hiding this comment

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

oh man I hate this "text" in the assert

Copy link
Member Author

@sdkrystian sdkrystian May 4, 2023

Choose a reason for hiding this comment

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

How about "modifying a ParamVarDecl here requires post-order traversal"?

Copy link
Member

Choose a reason for hiding this comment

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

I dont want any text at all, it is gratuituous because the assert will probably never go off so we are paying for a string for nothing. I edited the code already to remove the text and just leave a comment.


// apply the type adjustments specified in [dcl.fct] p5
// to ensure that the USR of the corresponding function matches
// other declarations of the function that have parameters declared
// with different top-level cv-qualifiers
D->setType(astContext_->
getSignatureParameterType(D->getType()));
// since we parse function parameters when we visit
// the actual function declarations, do nothing else
return true;
}

Expand Down
5 changes: 5 additions & 0 deletions source/api/AST/ASTVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class ASTVisitor
void buildVar(VarDecl* D);

public:
bool shouldTraversePostOrder() const
{
return true;
}

void HandleTranslationUnit(ASTContext& Context) override;
bool WalkUpFromNamespaceDecl(NamespaceDecl* D);
bool WalkUpFromCXXRecordDecl(CXXRecordDecl* D);
Expand Down
24 changes: 24 additions & 0 deletions test-files/old-tests/function-parm-decay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma clang diagnostic ignored "-Wdeprecated-volatile"

void f(const int x);
void f(volatile int x);
void f(const volatile int x);
void f(int x);

void g(int* x);
void g(int* const x);
void g(int x[]);
void g(int x[4]);

void h(int x(bool));
void h(int x(const bool));
void h(int (*x)(bool));
void h(int (*x)(const bool));

using T = int;
using U = const int;

void i(T);
void i(U);
void i(const T);
void i(const U);
42 changes: 42 additions & 0 deletions test-files/old-tests/function-parm-decay.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<mrdox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdox/raw/develop/mrdox.rnc">
<namespace name="">
<function name="g" id="CJhykN8TDmEo0Pl8UC2D9+rotIs=">
<file path="function-parm-decay.cpp" line="8"/>
<file path="function-parm-decay.cpp" line="9"/>
<file path="function-parm-decay.cpp" line="10"/>
<file path="function-parm-decay.cpp" line="11"/>
<param name="x" type="int *"/>
</function>
<function name="h" id="O4TonOdK6PIf6z1nHqJsqg7QfBw=">
<file path="function-parm-decay.cpp" line="13"/>
<file path="function-parm-decay.cpp" line="14"/>
<file path="function-parm-decay.cpp" line="15"/>
<file path="function-parm-decay.cpp" line="16"/>
<param name="x" type="int (*)(_Bool)"/>
</function>
<function name="i" id="UTOfie03KjmJww3mduHOqLZB5aI=">
<file path="function-parm-decay.cpp" line="21"/>
<file path="function-parm-decay.cpp" line="22"/>
<file path="function-parm-decay.cpp" line="23"/>
<file path="function-parm-decay.cpp" line="24"/>
<param type="T"/>
</function>
<function name="f" id="ackjGh57CJQLwtO8PihiSPPKIBY=">
<file path="function-parm-decay.cpp" line="3"/>
<file path="function-parm-decay.cpp" line="4"/>
<file path="function-parm-decay.cpp" line="5"/>
<file path="function-parm-decay.cpp" line="6"/>
<param name="x" type="int"/>
</function>
<alias name="T" id="PvNOREc+JWxdkVgvSz+jC45IbGQ=">
<file path="function-parm-decay.cpp" line="18" class="def"/>
<type name="int"/>
</alias>
<alias name="U" id="h6hupdyuT6SfsCGFl6UUFGtvrcc=">
<file path="function-parm-decay.cpp" line="19" class="def"/>
<type name="const int"/>
</alias>
</namespace>
</mrdox>