Skip to content

Fix nested lookups for parameters and return types #35

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
Jan 2, 2020
Merged
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
61 changes: 51 additions & 10 deletions CppHeaderParser/CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ def get_pure_virtual_methods(self, type="public"):
r[meth["name"]] = meth
return r

def _lookup_type(self, name):
# TODO: should have indexes for these lookups... and they
# should be more unified
for access in supportedAccessSpecifier:
for e in self["enums"][access]:
if e.get("name") == name:
return {
"enum": self["name"] + "::" + e["name"],
"type": e["name"],
"namespace": e["namespace"],
}
for n in self["nested_classes"]:
if n["name"] == name:
return {"raw_type": self["name"] + "::" + n["name"], "type": n["name"]}

def __init__(self, nameStack, curTemplate, doxygen, location):
self["nested_classes"] = []
self["parent"] = None
Expand Down Expand Up @@ -1505,15 +1520,21 @@ def resolve_type(self, string, result): # recursive
else:
used = None

# Search for using directives in parents
parent = result["parent"]
while parent:
p_using = parent.get("using")
if p_using:
used = p_using.get(alias)
if used:
break
parent = parent["parent"]
# Search for in parents
if not used:
parent = result["parent"]
while parent:
p_using = parent.get("using")
if p_using:
used = p_using.get(alias)
if used:
break
lookup = getattr(parent, "_lookup_type", None)
if lookup:
used = lookup(alias)
if used:
break
parent = parent["parent"]

if not used and self.using:
# search for type in all enclosing namespaces
Expand All @@ -1525,7 +1546,7 @@ def resolve_type(self, string, result): # recursive
break

if used:
for i in ("type", "namespace", "ctypes_type", "raw_type"):
for i in ("enum", "type", "namespace", "ctypes_type", "raw_type"):
if i in used:
result[i] = used[i]
result["unresolved"] = False
Expand Down Expand Up @@ -1860,6 +1881,26 @@ def finalize(self):
if meth["pure_virtual"]:
cls["abstract"] = True

# hack
rtnType = {
"aliases": [],
"parent": cls,
"unresolved": True,
"constant": 0,
"constexpr": 0,
"static": 0,
"pointer": 0,
"reference": 0,
}
self.resolve_type(meth["rtnType"], rtnType)
if not rtnType["unresolved"]:
if "enum" in rtnType:
meth["rtnType"] = rtnType["enum"]
elif "raw_type" in rtnType:
meth["rtnType"] = rtnType["raw_type"]

# TODO: all of this needs to die and be replaced by CppVariable

if (
not meth["returns_fundamental"]
and meth["returns"] in C99_NONSTANDARD
Expand Down
34 changes: 34 additions & 0 deletions test/test_CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3488,5 +3488,39 @@ def test_enum(self):
)


class NestedResolving_TestCase(unittest.TestCase):
def setUp(self):
self.cppHeader = CppHeaderParser.CppHeader(
"""
struct A {

enum { ANON };

struct B {};
enum C { X };

B fnested(B b);
C fenum(C c);
};

""",
"string",
)

def test_nothing(self):
c = self.cppHeader.classes["A"]
fn = c["methods"]["public"][0]
self.assertEqual(fn["name"], "fnested")
self.assertEqual(fn["rtnType"], "A::B")
self.assertEqual(len(fn["parameters"]), 1)
self.assertEqual(fn["parameters"][0]["raw_type"], "A::B")

fn = c["methods"]["public"][1]
self.assertEqual(fn["name"], "fenum")
self.assertEqual(fn["rtnType"], "A::C")
self.assertEqual(len(fn["parameters"]), 1)
self.assertEqual(fn["parameters"][0]["enum"], "A::C")


if __name__ == "__main__":
unittest.main()
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