Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changes in token.h/cpp:

- Properly set Token::_type to eVariable, eFunction or eName, depending on _function, _variable or _varId being set.
- Token can't be a variable and a function at a time - put Token::_function and Token::_variable into a union.
  • Loading branch information...
commit 3a35944c9ec3520d21f637a954d53e5c75ac6f25 1 parent 99a73fe
@PKEuS PKEuS authored
Showing with 17 additions and 7 deletions.
  1. +3 −3 lib/token.cpp
  2. +14 −4 lib/token.h
View
6 lib/token.cpp
@@ -34,8 +34,7 @@ Token::Token(Token **t) :
_previous(0),
_link(0),
_scope(0),
- _function(0),
- _variable(0),
+ _function(0), // Initialize whole union
_str(""),
_varId(0),
_fileIndex(0),
@@ -68,7 +67,8 @@ void Token::update_property_info()
else if (_str[0] == '_' || std::isalpha(_str[0])) { // Name
if (_varId)
_type = eVariable;
- _type = eName;
+ else if (_type != eVariable && _type != eFunction && _type != eType)
+ _type = eName;
} else if (std::isdigit(_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit(_str[1])))
_type = eNumber;
else if (_str.length() > 1 && _str[0] == '"' && _str[_str.length()-1] == '"')
View
18 lib/token.h
@@ -464,13 +464,17 @@ class CPPCHECKLIB Token {
*/
void function(const Function *f) {
_function = f;
+ if (f)
+ _type = eFunction;
+ else if (_type == eFunction)
+ _type = eName;
}
/**
* Returns a pointer to the Function associated with this token.
*/
const Function *function() const {
- return _function;
+ return _type == eFunction ? _function : 0;
}
/**
@@ -479,13 +483,17 @@ class CPPCHECKLIB Token {
*/
void variable(const Variable *v) {
_variable = v;
+ if (v || _varId)
+ _type = eVariable;
+ else if (_type == eVariable)
+ _type = eName;
}
/**
* Returns a pointer to the variable associated with this token.
*/
const Variable *variable() const {
- return _variable;
+ return _type == eVariable ? _variable : 0;
}
/**
@@ -581,8 +589,10 @@ class CPPCHECKLIB Token {
// symbol database information
const Scope *_scope;
- const Function *_function;
- const Variable *_variable;
+ union {
+ const Function *_function;
+ const Variable *_variable;
+ };
std::string _str;
unsigned int _varId;
Please sign in to comment.
Something went wrong with that request. Please try again.