addons: Fix __repr__ methods (#2448)

This commit fixes __repr__ methods introduced in d538315268. Fields that recursively links to other cppcheckdata objects was removed to avoid max recursion depth crash on printing.
This commit is contained in:
Georgy Komarov 2019-12-15 21:46:54 +03:00 committed by Daniel Marjamäki
parent c46e44e39e
commit 88a3b4c685
1 changed files with 15 additions and 20 deletions

View File

@ -270,15 +270,13 @@ class Token:
self.column = int(element.get('column')) self.column = int(element.get('column'))
def __repr__(self): def __repr__(self):
attrs = ["Id", "str", "next", "previous", "scopeId", attrs = ["Id", "str", "scopeId", "isName", "isUnsigned", "isSigned",
"scope", "isName", "isUnsigned", "isSigned", "isNumber", "isInt", "isFloat", "isString", "strlen",
"isNumber", "isInt", "isFloat", "isString", "strlen", "isChar", "isOp", "isArithmeticalOp", "isComparisonOp",
"isChar", "isOp", "isArithmeticalOp", "isComparisonOp", "isLogicalOp", "isExpandedMacro", "linkId", "varId",
"isLogicalOp", "isExpandedMacro", "linkId", "link", "variableId", "functionId", "valuesId", "valueType",
"varId", "variableId", "variable", "functionId", "function", "typeScopeId", "astParentId", "astOperand1Id", "file",
"valuesId", "values", "valueType", "typeScopeId", "typeScope", "linenr", "column"]
"astParentId", "astParent", "astOperand1Id", "astOperand1",
"astOperand2Id", "astOperand2", "file", "linenr", "column"]
return "{}({})".format( return "{}({})".format(
"Token", "Token",
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
@ -356,8 +354,7 @@ class Scope:
'Switch', 'Try', 'Catch', 'Unconditional', 'Lambda')) 'Switch', 'Try', 'Catch', 'Unconditional', 'Lambda'))
def __repr__(self): def __repr__(self):
attrs = ["Id", "className", "functionId", "function", attrs = ["Id", "className", "functionId", "bodyStartId", "bodyEndId",
"bodyStartId", "bodyStart", "bodyEndId", "bodyEnd",
"nestedInId", "nestedIn", "type", "isExecutable"] "nestedInId", "nestedIn", "type", "isExecutable"]
return "{}({})".format( return "{}({})".format(
"Scope", "Scope",
@ -415,7 +412,7 @@ class Function:
def __repr__(self): def __repr__(self):
attrs = ["Id", "tokenDefId", "name", "type", "isVirtual", attrs = ["Id", "tokenDefId", "name", "type", "isVirtual",
"isImplicitlyVirtual", "isStatic", "argument", "argumentId"] "isImplicitlyVirtual", "isStatic", "argumentId"]
return "{}({})".format( return "{}({})".format(
"Function", "Function",
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
@ -500,11 +497,10 @@ class Variable:
self.constness = int(self.constness) self.constness = int(self.constness)
def __repr__(self): def __repr__(self):
attrs = ["Id", "nameTokenId", "nameToken", "typeStartTokenId", attrs = ["Id", "nameTokenId", "typeStartTokenId", "typeEndTokenId",
"typeStartToken", "typeEndTokenId", "typeEndToken", "access", "scopeId", "isArgument", "isArray", "isClass",
"access", "scopeId", "scope", "isArgument", "isArray", "isConst", "isGlobal", "isExtern", "isLocal", "isPointer",
"isClass", "isConst", "isGlobal", "isExtern", "isLocal", "isReference", "isStatic", "constness", ]
"isPointer", "isReference", "isStatic", "constness", ]
return "{}({})".format( return "{}({})".format(
"Variable", "Variable",
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
@ -736,8 +732,7 @@ class Configuration:
variable.setId(IdMap) variable.setId(IdMap)
def __repr__(self): def __repr__(self):
attrs = ["name", "directives", "tokenlist", attrs = ["name"]
"scopes", "functions", "variables", "valueflow"]
return "{}({})".format( return "{}({})".format(
"Configuration", "Configuration",
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
@ -885,7 +880,7 @@ class CppcheckData:
self.configurations.append(Configuration(cfgnode)) self.configurations.append(Configuration(cfgnode))
def __repr__(self): def __repr__(self):
attrs = ["configurations", ] attrs = ["configurations", "platform"]
return "{}({})".format( return "{}({})".format(
"CppcheckData", "CppcheckData",
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))