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

[StubGen] Also bring in PODs on header inclusion #135

Merged
merged 2 commits into from
Oct 18, 2024
Merged
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
30 changes: 24 additions & 6 deletions ProxyStubGenerator/CppParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ def __init__(self, parent_block, name=""):
self.namespaces = []
self.methods = []
self.omit = False
self.omit_mode = False
self.stub = -False
if self.parent != None: # case for global namespace
if isinstance(self.parent, Namespace):
Expand Down Expand Up @@ -1041,6 +1042,7 @@ def __init__(self, parent_block, name):
self.ancestors = [] # parent classes
self._current_access = "public"
self.omit = False
self.omit_mode = False
self.stub = False
self.is_json = False
self.json_version = ""
Expand All @@ -1056,6 +1058,9 @@ def __init__(self, parent_block, name):
if sum([1 for x in self.parent.classes if x.name == name]) == 0:
self.parent.classes.append(self)

def IsPOD(self):
return (not self.methods and self.vars)

def IsAbstract(self):
return any([m.IsPureVirtual() for m in self.methods])

Expand Down Expand Up @@ -1123,6 +1128,7 @@ def __init__(self, parent_block, name):
self.classes = []
self._current_access = "public"
self.omit = False
self.omit_mode = False
self.stub = False
self.parent.unions.append(self)

Expand Down Expand Up @@ -1298,8 +1304,7 @@ def __str__(self):

def __repr__(self):
cv = " " + self.CVString() if self.CVString() else ""
return "method %s %s '%s' (%s)%s %s" % (self.access, TypeStr(self.type), self.name, ", ".join(
[str(v) for v in self.vars]), cv, str(self.specifiers))
return "method %s %s '%s' (%s)%s %s" % (self.access, TypeStr(self.retval.type), self.name, ", ".join([str(v) for v in self.vars]), cv, str(self.specifiers))


class Destructor(Method):
Expand Down Expand Up @@ -2135,6 +2140,7 @@ def Parse(contents,log = None):

if omit_mode:
new_class.omit = True
new_class.omit_mode = True
if omit_next:
new_class.omit = True
omit_next = False
Expand Down Expand Up @@ -2189,6 +2195,9 @@ def Parse(contents,log = None):
# Inherit omiting...
new_class.omit = True

if new_class.parent.omit_mode:
new_class.omit_mode = True

if last_template_def:
new_class.specifiers.append(" ".join(last_template_def))
last_template_def = []
Expand Down Expand Up @@ -2403,13 +2412,19 @@ def Parse(contents,log = None):

# Handle closing a compound block/composite type
elif tokens[i] == '}':
if isinstance(current_block[-1], Class) and (tokens[i + 1] != ';'):
raise ParserError("missing semicolon after a class definition; variable definitions following a class are not supported (%s)" %
current_block[-1].full_name)
if isinstance(current_block[-1], Class):
if (tokens[i + 1] != ';'):
raise ParserError("missing semicolon after a class definition; variable definitions following a class are not supported (%s)" % current_block[-1].full_name)

if current_block[-1].omit_mode and current_block[-1].IsPOD():
# it was POD after all, don't remove it from import
current_block[-1].omit = False

if len(current_block) > 1:
current_block.pop()
else:
raise ParserError("unmatched brace '{'")

i += 1
next_block = Block(current_block[-1]) # new anonymous scope

Expand All @@ -2421,12 +2436,15 @@ def Parse(contents,log = None):
j = i - 1
while j >= min_index and tokens[j] not in ['{', '}', ';', ":"]:
j -= 1

identifier = tokens[j + 1:i]
if len(identifier) != 0 and not current_block[-1].omit:

if identifier:
if isinstance(current_block[-1], Class):
Attribute(current_block[-1], identifier)
else:
Variable(current_block[-1], identifier)

i += 1

# Parse constants and member constants
Expand Down