Skip to content

Bug-Fix for multi-keyword variable-list parsing for properties #52

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 31 additions & 4 deletions CppHeaderParser/CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2458,11 +2458,38 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
self.nameStack,
". Separating processing",
)
orig_nameStack = self.nameStack[:]
i = leftMostComma - 2 # start right before the first var name
typeFound = []
typeEndIndex = 0

while not i < 0: # find the type by assuming that the first non-ptr/ref related word before the first varname has to be the end of the type stack
if self.nameStack[i] == "*" or self.nameStack[i] == "&":
if i > 0 and self.nameStack[i - 1] == "const": # handle declarations like "int const& const_int_ref;" correctly
i -= 1; # skip next const
else: # the real type declaration starts (ends) at index i
typeEndIndex = i + 1
typeFound.extend(self.nameStack[0:i + 1])

type_nameStack = orig_nameStack[: leftMostComma - 1]
for name in orig_nameStack[leftMostComma - 1 :: 2]:
self.nameStack = type_nameStack + [name]
break

i-= 1

nameStacks = []
currStack = typeFound.copy()

for word in self.nameStack[typeEndIndex:]:
if word == ",":
nameStacks.append(currStack)
currStack = typeFound.copy() # reset currStack
continue

currStack.append(word)

if not currStack == typeFound: # add last var in the list
nameStacks.append(currStack)

for nameStack in nameStacks:
self.nameStack = nameStack
self._evaluate_property_stack(
clearStack=False, addToVar=addToVar
)
Expand Down
13 changes: 7 additions & 6 deletions test/TestSampleClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SampleClass: public BaseSampleClass

double prop7; //!< prop7 description
//!< with two lines

/// prop8 description
int prop8;
};
Expand Down Expand Up @@ -642,6 +642,7 @@ class Grape
int a, b,c;
map<string, int> d;
map<string, int> e, f;
const int* g, const& h, const* i, j;
};

// Bug BitBucket #14
Expand Down Expand Up @@ -719,7 +720,7 @@ struct Lemon
virtual void foo() final;
virtual void foo2();
};

struct Lime final : Lemon
{
void abc();
Expand Down Expand Up @@ -749,12 +750,12 @@ union olive {

// Sourceforge bug 61
typedef struct
{
enum BeetEnum : int
{
{
enum BeetEnum : int
{
FAIL = 0,
PASS = 1
};
};
} BeetStruct;

void set_callback(int* b, long (*callback) (struct test_st *, int, const char*, int long, long, long));
Expand Down
51 changes: 45 additions & 6 deletions test/test_CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ class functions_TestCase(unittest.TestCase):
def setUp(self):
self.cppHeader = CppHeaderParser.CppHeader(
"""\
void global_funct1(int i);
void global_funct1(int i);
int global_funct2(void);
""",
"string",
Expand Down Expand Up @@ -1787,7 +1787,7 @@ class functions2_TestCase(unittest.TestCase):
def setUp(self):
self.cppHeader = CppHeaderParser.CppHeader(
"""\
void global_funct1(int i);
void global_funct1(int i);
int global_funct2(void){
// do something
}
Expand Down Expand Up @@ -2171,6 +2171,45 @@ def test_f_exists(self):
self.cppHeader.classes["Grape"]["properties"]["public"][5]["name"], "f"
)

def test_g_exists(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][6]["name"], "g"
)

def test_g_type(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][6]["type"], "const int *"
)

def test_h_exists(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][7]["name"], "h"
)

def test_h_type(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][7]["type"], "const int const &"
)

def test_i_exists(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][8]["name"], "i"
)

def test_i_type(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][8]["type"], "const int const *"
)

def test_j_exists(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][9]["name"], "j"
)

def test_j_type(self):
self.assertEqual(
self.cppHeader.classes["Grape"]["properties"]["public"][9]["type"], "const int"
)

# Bug BitBucket #14
class Avacado_TestCase(unittest.TestCase):
Expand Down Expand Up @@ -2433,7 +2472,7 @@ def setUp(self):
virtual void foo() final;
virtual void foo2();
};

struct Lime final : Lemon
{
void abc();
Expand Down Expand Up @@ -3488,7 +3527,7 @@ class StaticAssert_TestCase(unittest.TestCase):
def setUp(self):
self.cppHeader = CppHeaderParser.CppHeader(
"""
static_assert(sizeof(int) == 4,
static_assert(sizeof(int) == 4,
"integer size is wrong"
"for some reason");
""",
Expand All @@ -3511,7 +3550,7 @@ def setUp(self):
}

void fn();

std::vector<int> m_stuff;
};

Expand Down Expand Up @@ -3859,7 +3898,7 @@ def setUp(self):
template <class SomeType> class A {
public:
typedef B <SomeType> C;

A();

protected:
Expand Down