Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

Refectoring of the Token class

(1/3) > >>

ollydbg:
We have many discussion on the link: BerliOS Developer: Patch Detail: 3494

The Token class has too many member variables. Some member variables are only used for specific type of Tokens, this waste a lot of memory.

My idea is:

We can create a Token class as a base class, and define some interface (use virtual function), then we can have many derived classes like:


--- Code: ---FunctionToken
ClassToken
TypedefToken
ClassTemplateToken
ClassTemplateSpecilicationToken
VariableToken
...

--- End code ---
What's your opinion?

EDIT:
How can we do the type kind compare?
We have many code to check the m_TokenKind members, like:

--- Code: ---if ((curToken->m_ParentIndex == parent) && (curToken->m_TokenKind & kindMask))

--- End code ---
or

--- Code: ---const Token* tk = tree->at(tree->TokenExists(token->m_BaseType, -1, tkPreprocessor | tkFunction));
--- End code ---

Do we still need to put the m_TokenKind in the base class? so that every derived class has a m_TokenKind variable.

Or, do we need some kind of RTTI? See: Finding the type of an object in C++ - Stack Overflow
and
C++ polymorphism: Checking data type of sub class [duplicate]

MortenMacFly:
Well first of all it hopefully won't conflict with Alphas work.

Using a bit mask and some consts/enums to compare is enough I'd say. If its feasible/doable, the specialisation could be stored into another "specialisation" bitmask. Thus they would become one variable.

So like:
((curToken->m_TokenKind & kindMask) && (curToken->m_TokenKindSpecial & kindMaskSpecial))

oBFusCATed:

--- Quote from: ollydbg on November 27, 2013, 03:16:56 pm ---Do we still need to put the m_TokenKind in the base class? so that every derived class has a m_TokenKind variable.

--- End quote ---
No, you can make a virtual getTokenKind method.


--- Quote from: ollydbg on November 27, 2013, 03:16:56 pm ---Or, do we need some kind of RTTI? See: Finding the type of an object in C++ - Stack Overflow
and
C++ polymorphism: Checking data type of sub class [duplicate]

--- End quote ---
People that are proficient with OOP say that if you need dynamic_cast then you have problems with your design :)

p2rkw:

--- Quote from: oBFusCATed on November 27, 2013, 07:17:19 pm ---People that are proficient with OOP say that if you need dynamic_cast then you have problems with your design :)

--- End quote ---
Tell it to llvm developers: llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates  ;)
In my opinion rare data can be stored in separate hash maps as I did with docentation.

oBFusCATed:

--- Quote from: p2rkw on November 27, 2013, 09:14:11 pm ---Tell it to llvm developers: llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates  ;)

--- End quote ---
This doesn't make my statement invalid. dynamic_cast is useful tool, but should be used with care.

Navigation

[0] Message Index

[#] Next page

Go to full version