From 3418a049fa0c7735ba6dd637b89c4397559323e8 Mon Sep 17 00:00:00 2001 From: sebaszm Date: Thu, 27 Jul 2023 12:17:40 +0200 Subject: [PATCH] [JsonGen] Improve name clash detection --- JsonGenerator/source/header_loader.py | 10 +++++--- ProxyStubGenerator/CppParser.py | 34 ++++++++++++++++++--------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/JsonGenerator/source/header_loader.py b/JsonGenerator/source/header_loader.py index f1166e3..261f36b 100644 --- a/JsonGenerator/source/header_loader.py +++ b/JsonGenerator/source/header_loader.py @@ -285,7 +285,7 @@ def ConvertParameter(var): properties["example"] = pair[0] properties["description"] = pair[1] else: - properties["description"] = var.meta.brief + properties["description"] = var.meta.brief.strip() return properties @@ -592,7 +592,7 @@ def BuildResult(vars, is_property=False): obj["obsolete"] = True if method.retval.meta.brief: - obj["summary"] = method.retval.meta.brief + obj["summary"] = method.retval.meta.brief.strip() if method.retval.meta.details: obj["description"] = method.retval.meta.details @@ -646,10 +646,14 @@ def BuildResult(vars, is_property=False): varsidx = 1 else: raise CppParseError(method.vars[0], "failed to determine type of notification id parameter") + if method.retval.meta.is_listener: obj["statuslistener"] = True params = BuildParameters(method.vars[varsidx:], rpc_format, False) + retvals = BuildResult(method.vars[varsidx:]) + if retvals and retvals["type"] != "null": + raise CppParseError(method, "output parameters are invalid for JSON-RPC events") if method.retval.meta.is_deprecated: obj["deprecated"] = True @@ -657,7 +661,7 @@ def BuildResult(vars, is_property=False): obj["obsolete"] = True if method.retval.meta.brief: - obj["summary"] = method.retval.meta.brief + obj["summary"] = method.retval.meta.brief.strip() if method.retval.meta.details: obj["description"] = method.retval.meta.details diff --git a/ProxyStubGenerator/CppParser.py b/ProxyStubGenerator/CppParser.py index 2baca7f..9bc95a5 100755 --- a/ProxyStubGenerator/CppParser.py +++ b/ProxyStubGenerator/CppParser.py @@ -542,8 +542,12 @@ def __Search(tree, found, T): else: ref |= Ref.POINTER elif self.type[typeIdx] == "&": + if ref & Ref.POINTER: + raise ParserError("pointer to a reference is not valid C++") ref |= Ref.REFERENCE elif self.type[typeIdx] == "&&": + if ref & Ref.POINTER: + raise ParserError("pointer to a reference is not valid C++") ref |= Ref.RVALUE_REFERENCE elif self.type[typeIdx] == "const": ref |= Ref.CONST @@ -1039,18 +1043,22 @@ def __init__(self, parent_block, name, ret_type, valid_specifiers=["static", "ex self.stub = False self.is_excluded = False - for method in self.parent.methods: - if method.name == self.name: - if self.parent.is_json: - if method.retval.meta.is_property: - if method.retval.meta.text: - self.retval.meta.text = method.retval.meta.text - if method.retval.meta.alt: - self.retval.meta.alt = method.retval.meta.alt - elif not method.omit and not method.is_excluded and not method.retval.meta.text: - raise ParserError("'%s': JSON-RPC name clash detected, resolve with @text tag" % method.name) + def Append(self): + if not self.is_excluded and not self.omit: + test_name = self.retval.meta.text if self.retval.meta.text else self.name + for method in self.parent.methods: + name = method.retval.meta.text if method.retval.meta.text else method.name + if name == test_name: + if self.parent.is_json: + if method.retval.meta.is_property: + if method.retval.meta.text: + self.retval.meta.text = method.retval.meta.text + if method.retval.meta.alt: + self.retval.meta.alt = method.retval.meta.alt + elif not method.omit and not method.is_excluded: + raise ParserError("'%s': JSON-RPC name clash detected, resolve with @text tag" % name) - break + break self.parent.methods.append(self) @@ -1987,6 +1995,8 @@ def Parse(contents,log = None): raise ParserError("@compliant used without @json") if collapsed_next or extended_next: raise ParserError("@compliant and @uncompliant used together") + if exclude_next: + raise ParserError("@json:omit is invalid here (applies to methods only)") json_next = False json_version = "" @@ -2133,6 +2143,8 @@ def Parse(contents,log = None): method.specifiers.append(" ".join(last_template_def)) last_template_def = [] + method.Append() + # try to detect a function/macro call function_call = not ret_type and ((name != current_block[-1].name) and (name != ("~" + current_block[-1].name)))