Skip to content

Commit d75083f

Browse files
committed
Fix bug and add tests
1 parent 6af545b commit d75083f

File tree

3 files changed

+83
-16
lines changed

3 files changed

+83
-16
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,11 +2458,38 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
24582458
self.nameStack,
24592459
". Separating processing",
24602460
)
2461-
orig_nameStack = self.nameStack[:]
2461+
i = leftMostComma - 2 # start right before the first var name
2462+
typeFound = []
2463+
typeEndIndex = 0
2464+
2465+
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
2466+
if self.nameStack[i] == "*" or self.nameStack[i] == "&":
2467+
if i > 0 and self.nameStack[i - 1] == "const": # handle declarations like "int const& const_int_ref;" correctly
2468+
i -= 1; # skip next const
2469+
else: # the real type declaration starts (ends) at index i
2470+
typeEndIndex = i + 1
2471+
typeFound.extend(self.nameStack[0:i + 1])
24622472

2463-
type_nameStack = orig_nameStack[: leftMostComma - 1]
2464-
for name in orig_nameStack[leftMostComma - 1 :: 2]:
2465-
self.nameStack = type_nameStack + [name]
2473+
break
2474+
2475+
i-= 1
2476+
2477+
nameStacks = []
2478+
currStack = typeFound.copy()
2479+
2480+
for word in self.nameStack[typeEndIndex:]:
2481+
if word == ",":
2482+
nameStacks.append(currStack)
2483+
currStack = typeFound.copy() # reset currStack
2484+
continue
2485+
2486+
currStack.append(word)
2487+
2488+
if not currStack == typeFound: # add last var in the list
2489+
nameStacks.append(currStack)
2490+
2491+
for nameStack in nameStacks:
2492+
self.nameStack = nameStack
24662493
self._evaluate_property_stack(
24672494
clearStack=False, addToVar=addToVar
24682495
)

test/TestSampleClass.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SampleClass: public BaseSampleClass
5252

5353
double prop7; //!< prop7 description
5454
//!< with two lines
55-
55+
5656
/// prop8 description
5757
int prop8;
5858
};
@@ -642,6 +642,7 @@ class Grape
642642
int a, b,c;
643643
map<string, int> d;
644644
map<string, int> e, f;
645+
const int* g, const& h, const* i, j;
645646
};
646647

647648
// Bug BitBucket #14
@@ -719,7 +720,7 @@ struct Lemon
719720
virtual void foo() final;
720721
virtual void foo2();
721722
};
722-
723+
723724
struct Lime final : Lemon
724725
{
725726
void abc();
@@ -749,12 +750,12 @@ union olive {
749750

750751
// Sourceforge bug 61
751752
typedef struct
752-
{
753-
enum BeetEnum : int
754-
{
753+
{
754+
enum BeetEnum : int
755+
{
755756
FAIL = 0,
756757
PASS = 1
757-
};
758+
};
758759
} BeetStruct;
759760

760761
void set_callback(int* b, long (*callback) (struct test_st *, int, const char*, int long, long, long));

test/test_CppHeaderParser.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ class functions_TestCase(unittest.TestCase):
17521752
def setUp(self):
17531753
self.cppHeader = CppHeaderParser.CppHeader(
17541754
"""\
1755-
void global_funct1(int i);
1755+
void global_funct1(int i);
17561756
int global_funct2(void);
17571757
""",
17581758
"string",
@@ -1787,7 +1787,7 @@ class functions2_TestCase(unittest.TestCase):
17871787
def setUp(self):
17881788
self.cppHeader = CppHeaderParser.CppHeader(
17891789
"""\
1790-
void global_funct1(int i);
1790+
void global_funct1(int i);
17911791
int global_funct2(void){
17921792
// do something
17931793
}
@@ -2171,6 +2171,45 @@ def test_f_exists(self):
21712171
self.cppHeader.classes["Grape"]["properties"]["public"][5]["name"], "f"
21722172
)
21732173

2174+
def test_g_exists(self):
2175+
self.assertEqual(
2176+
self.cppHeader.classes["Grape"]["properties"]["public"][6]["name"], "g"
2177+
)
2178+
2179+
def test_g_type(self):
2180+
self.assertEqual(
2181+
self.cppHeader.classes["Grape"]["properties"]["public"][6]["type"], "const int *"
2182+
)
2183+
2184+
def test_h_exists(self):
2185+
self.assertEqual(
2186+
self.cppHeader.classes["Grape"]["properties"]["public"][7]["name"], "h"
2187+
)
2188+
2189+
def test_h_type(self):
2190+
self.assertEqual(
2191+
self.cppHeader.classes["Grape"]["properties"]["public"][7]["type"], "const int const &"
2192+
)
2193+
2194+
def test_i_exists(self):
2195+
self.assertEqual(
2196+
self.cppHeader.classes["Grape"]["properties"]["public"][8]["name"], "i"
2197+
)
2198+
2199+
def test_i_type(self):
2200+
self.assertEqual(
2201+
self.cppHeader.classes["Grape"]["properties"]["public"][8]["type"], "const int const *"
2202+
)
2203+
2204+
def test_j_exists(self):
2205+
self.assertEqual(
2206+
self.cppHeader.classes["Grape"]["properties"]["public"][9]["name"], "j"
2207+
)
2208+
2209+
def test_j_type(self):
2210+
self.assertEqual(
2211+
self.cppHeader.classes["Grape"]["properties"]["public"][9]["type"], "const int"
2212+
)
21742213

21752214
# Bug BitBucket #14
21762215
class Avacado_TestCase(unittest.TestCase):
@@ -2433,7 +2472,7 @@ def setUp(self):
24332472
virtual void foo() final;
24342473
virtual void foo2();
24352474
};
2436-
2475+
24372476
struct Lime final : Lemon
24382477
{
24392478
void abc();
@@ -3488,7 +3527,7 @@ class StaticAssert_TestCase(unittest.TestCase):
34883527
def setUp(self):
34893528
self.cppHeader = CppHeaderParser.CppHeader(
34903529
"""
3491-
static_assert(sizeof(int) == 4,
3530+
static_assert(sizeof(int) == 4,
34923531
"integer size is wrong"
34933532
"for some reason");
34943533
""",
@@ -3511,7 +3550,7 @@ def setUp(self):
35113550
}
35123551
35133552
void fn();
3514-
3553+
35153554
std::vector<int> m_stuff;
35163555
};
35173556
@@ -3859,7 +3898,7 @@ def setUp(self):
38593898
template <class SomeType> class A {
38603899
public:
38613900
typedef B <SomeType> C;
3862-
3901+
38633902
A();
38643903
38653904
protected:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy