cppcheckdata: Added doxygen comments

This commit is contained in:
Daniel Marjamäki 2015-08-26 18:10:33 +02:00
parent 39dd71e49b
commit eb3b3de81f
2 changed files with 1954 additions and 42 deletions

1792
addons/cppcheckdata.doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,77 +1,151 @@
# Python module that loads a cppcheck dump
# License: No restrictions, use this as you need.
## @mainpage cppcheckdata
#
# @brief This is a Python module that helps you access Cppcheck dump data.<br><br>
#
# License: No restrictions, use this as you need.<br><br>
#
import xml.etree.ElementTree as ET
# Token class. Contains information about each token in the source code.
## Token class. Contains information about each token in the source code.
#
# The CppcheckData.tokenlist is a list of Token items
#
# C++ class: http://cppcheck.sourceforge.net/devinfo/doxyoutput/classToken.html
#
# To iterate through all tokens use such code:
# @code
# data = CppcheckData.parsedump(...)
# code = ''
# for token in data.tokenlist:
# code = code + token.str + ' '
# print(code)
# @endcode
#
class Token:
Id = None
# Token string
## Token string
str = None
# Next token in tokenlist. For last token, next is None.
## Next token in tokenlist. For last token, next is None.
next = None
# Previous token in tokenlist. For first token, previous is None,
## Previous token in tokenlist. For first token, previous is None,
previous = None
linkId = None
# Linked token in tokenlist. Each '(', '[' and '{' are linked to the
## Linked token in tokenlist. Each '(', '[' and '{' are linked to the
# corresponding '}', ']' and ')'. For templates, the '<' is linked to
# the corresponding '>'.
link = None
scopeId = None
# Scope information for this token. See the Scope class.
## Scope information for this token. See the Scope class.
scope = None
# Is this token a symbol name
## Is this token a symbol name
isName = False
# Is this token a number, for example 123, 12.34
## Is this token a number, for example 123, 12.34
isNumber = False
# Is this token a int value such as 1234
## Is this token a int value such as 1234
isInt = False
# Is this token a int value such as 12.34
## Is this token a int value such as 12.34
isFloat = False
# Is this token a string literal such as "hello"
## Is this token a string literal such as "hello"
isString = False
# string length for string literal
## string length for string literal
strlen = None
# Is this token a char literal such as 'x'
## Is this token a char literal such as 'x'
isChar = False
# Is this token a operator
## Is this token a operator
isOp = False
# Is this token a arithmetic operator
## Is this token a arithmetic operator
isArithmeticalOp = False
# Is this token a assignment operator
## Is this token a assignment operator
isAssignmentOp = False
# Is this token a comparison operator
## Is this token a comparison operator
isComparisonOp = False
# Is this token a logical operator: && ||
## Is this token a logical operator: && ||
isLogicalOp = False
# varId for token, each variable has a unique non-zero id
## varId for token, each variable has a unique non-zero id
varId = None
variableId = None
# Variable information for this token. See the Variable class.
## Variable information for this token. See the Variable class.
#
# Example code:
# @code
# data = CppcheckData.parsedump(...)
# code = ''
# for token in data.tokenlist:
# code = code + token.str
# if token.variable:
# if token.variable.isLocal:
# code = code + ':localvar'
# if token.variable.isArgument:
# code = code + ':arg'
# code = code + ' '
# print(code)
# @endcode
variable = None
functionId = None
# If this token points at a function call, this attribute has the Function
## If this token points at a function call, this attribute has the Function
# information. See the Function class.
function = None
valuesId = None
# Possible values of token
## Possible values of token
#
# Example code:
# @code
# data = CppcheckData.parsedump(...)
# code = ''
# for token in data.tokenlist:
# code = code + token.str
# if token.values:
# # print values..
# code = code + '{'
# for value in token.values:
# if value.intvalue:
# code = code + str(value.intvalue) + ' '
# code = code + '}'
# code = code + ' '
# print(code)
# @endcode
values = None
astParentId = None
# syntax tree parent
## syntax tree parent
astParent = None
astOperand1Id = None
# syntax tree operand1
## syntax tree operand1
#
# Example code:
# @code
# data = CppcheckData.parsedump(...)
# for token in data.tokenlist:
#
# # is this a addition?
# if token.str == '+':
#
# # print LHS operand
# print(token.astOperand1.str)
#
# @endcode
astOperand1 = None
astOperand2Id = None
# syntax tree operand2
## syntax tree operand2
#
# Example code:
# @code
# data = CppcheckData.parsedump(...)
# for token in data.tokenlist:
#
# # is this a division?
# if token.str == '/':
#
# # print RHS operand
# print(token.astOperand2.str)
#
# @endcode
astOperand2 = None
# file name
## file name
file = None
# line number
## line number
linenr = None
def __init__(self, element):
@ -133,7 +207,7 @@ class Token:
self.astOperand1 = IdMap[self.astOperand1Id]
self.astOperand2 = IdMap[self.astOperand2Id]
# Get value if it exists
## Get value if it exists
# Returns None if it doesn't exist
def getValue(self, v):
if not self.values:
@ -143,14 +217,20 @@ class Token:
return value
return None
## Scope. Information about global scope, function scopes, class scopes, inner scopes, etc.
# C++ class: http://cppcheck.sourceforge.net/devinfo/doxyoutput/classScope.html
class Scope:
Id = None
classStartId = None
## The { Token for this scope
classStart = None
classEndId = None
## The } Token for this scope
classEnd = None
## Name of this scope. For a function scope, this is the function name, For a class scope, this is the class name.
className = None
## Type of scope: Global, Function, Class, If, While
type = None
def __init__(self, element):
@ -169,7 +249,8 @@ class Scope:
self.classEnd = IdMap[self.classEndId]
self.nestedIn = IdMap[self.nestedInId]
## Information about a function
# C++ class: http://cppcheck.sourceforge.net/devinfo/doxyoutput/classFunction.html
class Function:
Id = None
argument = None
@ -192,21 +273,32 @@ class Function:
self.argument[argnr] = IdMap[argid]
self.tokenDef = IdMap[self.tokenDefId]
## Information about a variable
# C++ class: http://cppcheck.sourceforge.net/devinfo/doxyoutput/classVariable.html
class Variable:
Id = None
nameTokenId = None
# name token in variable declaration
nameToken = None
typeStartTokenId = None
## start token of variable declaration
typeStartToken = None
typeEndTokenId = None
## end token of variable declaration
typeEndToken = None
## Is this variable a function argument?
isArgument = False
## Is this variable an array?
isArray = False
## Is this variable a class or struct?
isClass = False
## Is this variable a local variable?
isLocal = False
## Is this variable a pointer
isPointer = False
## Is this variable a reference
isReference = False
## Is this variable static?
isStatic = False
def __init__(self, element):
@ -230,12 +322,18 @@ class Variable:
self.typeStartToken = IdMap[self.typeStartTokenId]
self.typeEndToken = IdMap[self.typeEndTokenId]
## ValueFlow class
class ValueFlow:
## ValueFlow::Value class
# Each possible value has a ValueFlow::Value item.
# Each ValueFlow::Value either has a intvalue or tokvalue
# C++ class: http://cppcheck.sourceforge.net/devinfo/doxyoutput/classValueFlow_1_1Value.html
class Value:
# integer value
intvalue = None
# token value
tokvalue = None
# condition where this Value comes from
condition = None
def __init__(self, element):
@ -248,6 +346,8 @@ class ValueFlow:
self.condition = int(self.condition)
Id = None
## Possible values
values = None
def __init__(self, element):
@ -256,12 +356,34 @@ class ValueFlow:
for value in element:
self.values.append(ValueFlow.Value(value))
## Class that makes cppcheck dump data available
#
# To iterate through all tokens use such code:
# @code
# data = CppcheckData.parsedump(...)
# code = ''
# for token in data.tokenlist:
# code = code + token.str + ' '
# print(code)
# @endcode
#
# To iterate through all scopes (functions, types, etc) use such code:
# @code
# data = CppcheckData.parsedump(...)
# for scope in data.scopes:
# print('type:' + scope.type + ' name:' + scope.className)
# @endcode
#
class CppcheckData:
## List of Token items
tokenlist = []
## List of Scope items
scopes = []
## List of Function items
functions = []
## List of Variable items
variables = []
## List of ValueFlow values
valueflow = []
def __init__(self, filename):
@ -321,13 +443,11 @@ class CppcheckData:
for variable in self.variables:
variable.setId(IdMap)
## parse a cppcheck dump file
def parsedump(filename):
return CppcheckData(filename)
# Check if type of ast node is float/double
## Check if type of ast node is float/double
def astIsFloat(token):
if not token:
return False