diff --git a/lib/token.cpp b/lib/token.cpp index 7bbe95278..3cb874b07 100644 --- a/lib/token.cpp +++ b/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] == '"') diff --git a/lib/token.h b/lib/token.h index 31a64bef0..da857b193 100644 --- a/lib/token.h +++ b/lib/token.h @@ -464,13 +464,17 @@ public: */ 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 @@ public: */ 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 @@ private: // 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;