xml dump: add more token attributes

This commit is contained in:
Daniel Marjamäki 2014-07-21 12:44:53 +02:00
parent 46a0ab1754
commit c5e9da2984
2 changed files with 84 additions and 23 deletions

View File

@ -3827,6 +3827,31 @@ void Tokenizer::dump(std::ostream &out) const
out << " <token id=\"" << tok << "\" file=\"" << toxml(list.file(tok)) << "\" linenr=\"" << tok->linenr() << '\"';
out << " str=\"" << toxml(tok->str()) << '\"';
out << " scope=\"" << tok->scope() << '\"';
if (tok->isName())
out << " type=\"name\"";
else if (tok->isNumber()) {
out << " type=\"number\"";
if (MathLib::isInt(tok->str()))
out << " isInt=\"True\"";
if (MathLib::isFloat(tok->str()))
out << " isFloat=\"True\"";
} else if (tok->type() == Token::eString)
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
else if (tok->type() == Token::eChar)
out << " type=\"char\"";
else if (tok->isBoolean())
out << " type=\"boolean\"";
else if (tok->isOp()) {
out << " type=\"op\"";
if (tok->isArithmeticalOp())
out << " isArithmeticalOp=\"True\"";
else if (tok->isAssignmentOp())
out << " isAssignmentOp=\"True\"";
else if (tok->isComparisonOp())
out << " isComparisonOp=\"True\"";
else if (tok->type() == Token::eLogicalOp)
out << " isLogicalOp=\"True\"";
}
if (tok->link())
out << " link=\"" << tok->link() << '\"';
if (tok->varId() > 0U)

View File

@ -4,29 +4,41 @@
from lxml import etree
class Token:
Id = None
str = None
next = None
previous = None
scopeId = None
scope = None
linkId = None
link = None
varId = None
variableId = None
variable = None
functionId = None
function = None
valuesId = None
values = None
astParentId = None
astParent = None
astOperand1Id = None
astOperand1 = None
astOperand2Id = None
astOperand2 = None
file = None
linenr = None
Id = None
str = None
next = None
previous = None
scopeId = None
scope = None
isName = None
isNumber = None
isInt = None
isFloat = None
isString = None
strlen = None
isChar = None
isOp = None
isArithmeticalOp = None
isAssignmentOp = None
isComparisonOp = None
isLogicalOp = None
linkId = None
link = None
varId = None
variableId = None
variable = None
functionId = None
function = None
valuesId = None
values = None
astParentId = None
astParent = None
astOperand1Id = None
astOperand1 = None
astOperand2Id = None
astOperand2 = None
file = None
linenr = None
def __init__(self, element):
self.Id = element.get('id')
@ -35,6 +47,30 @@ class Token:
self.previous = None
self.scopeId = element.get('scope')
self.scope = None
type = element.get('type')
if type == 'name':
self.isName = True
elif type == 'number':
self.isNumber = True
if element.get('isInt'):
self.isInt = True
elif element.get('isFloat'):
self.isFloat = True
elif type == 'string':
self.isString = True
self.strlen = int(element.get('strlen'))
elif type == 'char':
self.isChar = True
elif type == 'op':
self.isOp = True
if element.get('isArithmeticalOp'):
self.isArithmeticalOp = True
elif element.get('isAssignmentOp'):
self.isAssignmentOp = True
elif element.get('isComparisonOp'):
self.isComparisonOp = True
elif element.get('isLogicalOp'):
self.isLogicalOp = True
self.linkId = element.get('link')
self.link = None
self.varId = element.get('varId')