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.
This commit is contained in:
parent
99a73fe1d3
commit
3a35944c9e
|
@ -34,8 +34,7 @@ Token::Token(Token **t) :
|
||||||
_previous(0),
|
_previous(0),
|
||||||
_link(0),
|
_link(0),
|
||||||
_scope(0),
|
_scope(0),
|
||||||
_function(0),
|
_function(0), // Initialize whole union
|
||||||
_variable(0),
|
|
||||||
_str(""),
|
_str(""),
|
||||||
_varId(0),
|
_varId(0),
|
||||||
_fileIndex(0),
|
_fileIndex(0),
|
||||||
|
@ -68,7 +67,8 @@ void Token::update_property_info()
|
||||||
else if (_str[0] == '_' || std::isalpha(_str[0])) { // Name
|
else if (_str[0] == '_' || std::isalpha(_str[0])) { // Name
|
||||||
if (_varId)
|
if (_varId)
|
||||||
_type = eVariable;
|
_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])))
|
} else if (std::isdigit(_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit(_str[1])))
|
||||||
_type = eNumber;
|
_type = eNumber;
|
||||||
else if (_str.length() > 1 && _str[0] == '"' && _str[_str.length()-1] == '"')
|
else if (_str.length() > 1 && _str[0] == '"' && _str[_str.length()-1] == '"')
|
||||||
|
|
18
lib/token.h
18
lib/token.h
|
@ -464,13 +464,17 @@ public:
|
||||||
*/
|
*/
|
||||||
void function(const Function *f) {
|
void function(const Function *f) {
|
||||||
_function = f;
|
_function = f;
|
||||||
|
if (f)
|
||||||
|
_type = eFunction;
|
||||||
|
else if (_type == eFunction)
|
||||||
|
_type = eName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the Function associated with this token.
|
* Returns a pointer to the Function associated with this token.
|
||||||
*/
|
*/
|
||||||
const Function *function() const {
|
const Function *function() const {
|
||||||
return _function;
|
return _type == eFunction ? _function : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -479,13 +483,17 @@ public:
|
||||||
*/
|
*/
|
||||||
void variable(const Variable *v) {
|
void variable(const Variable *v) {
|
||||||
_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.
|
* Returns a pointer to the variable associated with this token.
|
||||||
*/
|
*/
|
||||||
const Variable *variable() const {
|
const Variable *variable() const {
|
||||||
return _variable;
|
return _type == eVariable ? _variable : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -581,8 +589,10 @@ private:
|
||||||
|
|
||||||
// symbol database information
|
// symbol database information
|
||||||
const Scope *_scope;
|
const Scope *_scope;
|
||||||
const Function *_function;
|
union {
|
||||||
const Variable *_variable;
|
const Function *_function;
|
||||||
|
const Variable *_variable;
|
||||||
|
};
|
||||||
|
|
||||||
std::string _str;
|
std::string _str;
|
||||||
unsigned int _varId;
|
unsigned int _varId;
|
||||||
|
|
Loading…
Reference in New Issue