[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevelop] languages/cpp: use a quint16 instead of an int for TokenType
From:       Milian Wolff <mail () milianw ! de>
Date:       2012-03-01 0:23:38
Message-ID: 20120301002338.2843EA60A9 () git ! kde ! org
[Download RAW message or body]

Git commit 0e9c1916f4dda49500ba686d6c696558e5cdb5c2 by Milian Wolff.
Committed on 01/03/2012 at 01:05.
Pushed by mwolff into branch 'master'.

use a quint16 instead of an int for TokenType

this does not have a big impact on memory consumption
due to alignment of the Token class

M  +5    -5    languages/cpp/cppduchain/builtinoperators.cpp
M  +1    -1    languages/cpp/cppduchain/builtinoperators.h
M  +1    -1    languages/cpp/cppduchain/declarationbuilder.cpp
M  +10   -10   languages/cpp/cppduchain/expressionvisitor.cpp
M  +3    -3    languages/cpp/parser/lexer.h

http://commits.kde.org/kdevelop/0e9c1916f4dda49500ba686d6c696558e5cdb5c2

diff --git a/languages/cpp/cppduchain/builtinoperators.cpp \
b/languages/cpp/cppduchain/builtinoperators.cpp index 940a9e6..0def471 100644
--- a/languages/cpp/cppduchain/builtinoperators.cpp
+++ b/languages/cpp/cppduchain/builtinoperators.cpp
@@ -35,7 +35,7 @@ struct ConstantBinaryExpressionEvaluator {
   /**
    * Writes the results into endValue, type, and modifier.
    * */
-  ConstantBinaryExpressionEvaluator( uint _type, uint _modifier, int tokenKind, \
ConstantIntegralType* left, ConstantIntegralType* right ) { +  \
ConstantBinaryExpressionEvaluator( uint _type, uint _modifier, quint16 tokenKind, \
ConstantIntegralType* left, ConstantIntegralType* right ) {  endValue = 0;
 
     type = _type;
@@ -93,7 +93,7 @@ struct ConstantBinaryExpressionEvaluator {
   }
 
   //This function is used to disable some operators on bool and double values
-  void evaluateSpecialTokens( int tokenKind, ConstantIntegralType* left, \
ConstantIntegralType* right ) { +  void evaluateSpecialTokens( quint16 tokenKind, \
ConstantIntegralType* left, ConstantIntegralType* right ) {  switch( tokenKind ) {
       case '%':
         if(right->ConstantIntegralType::value<Type>())
@@ -136,14 +136,14 @@ struct ConstantBinaryExpressionEvaluator {
 };
 
 template<>
-void ConstantBinaryExpressionEvaluator<double>::evaluateSpecialTokens( int \
tokenKind, ConstantIntegralType* left, ConstantIntegralType* right ) { +void \
ConstantBinaryExpressionEvaluator<double>::evaluateSpecialTokens( quint16 tokenKind, \
ConstantIntegralType* left, ConstantIntegralType* right ) {  Q_UNUSED(tokenKind);
   Q_UNUSED(left);
   Q_UNUSED(right);
 }
 
 template<>
-void ConstantBinaryExpressionEvaluator<float>::evaluateSpecialTokens( int tokenKind, \
ConstantIntegralType* left, ConstantIntegralType* right ) { +void \
ConstantBinaryExpressionEvaluator<float>::evaluateSpecialTokens( quint16 tokenKind, \
ConstantIntegralType* left, ConstantIntegralType* right ) {  Q_UNUSED(tokenKind);
   Q_UNUSED(left);
   Q_UNUSED(right);
@@ -151,7 +151,7 @@ void \
ConstantBinaryExpressionEvaluator<float>::evaluateSpecialTokens( int tokenK  
 
 
-AbstractType::Ptr binaryOperatorReturnType(AbstractType::Ptr left, AbstractType::Ptr \
right, int tokenKind) { +AbstractType::Ptr binaryOperatorReturnType(AbstractType::Ptr \
left, AbstractType::Ptr right, quint16 tokenKind) {  
   if(!left || !right)
     return AbstractType::Ptr();
diff --git a/languages/cpp/cppduchain/builtinoperators.h \
b/languages/cpp/cppduchain/builtinoperators.h index 43cf1df..e1c80fc 100644
--- a/languages/cpp/cppduchain/builtinoperators.h
+++ b/languages/cpp/cppduchain/builtinoperators.h
@@ -25,6 +25,6 @@
 ///Returns the type that the builtin binary operator given through @param tokenKind \
with the given left and right operand types yields.  ///When the types are constant \
integral types with values, the returned type will also have the value evaluated  \
                ///@return Zero if the given types can not be handled by a builtin \
                operator
-KDevelop::AbstractType::Ptr binaryOperatorReturnType(KDevelop::AbstractType::Ptr \
left, KDevelop::AbstractType::Ptr right, int tokenKind); +KDevelop::AbstractType::Ptr \
binaryOperatorReturnType(KDevelop::AbstractType::Ptr left, \
KDevelop::AbstractType::Ptr right, quint16 tokenKind);  
 #endif
diff --git a/languages/cpp/cppduchain/declarationbuilder.cpp \
b/languages/cpp/cppduchain/declarationbuilder.cpp index e7e9522..f21464f 100644
--- a/languages/cpp/cppduchain/declarationbuilder.cpp
+++ b/languages/cpp/cppduchain/declarationbuilder.cpp
@@ -1175,7 +1175,7 @@ void DeclarationBuilder::visitBaseSpecifier(BaseSpecifierAST \
*node) {  instance.access = KDevelop::Declaration::Private;
 
       if( node->access_specifier ) {
-        int tk = editor()->parseSession()->token_stream->token(node->access_specifier).kind;
 +        quint16 tk = \
editor()->parseSession()->token_stream->token(node->access_specifier).kind;  
         switch( tk ) {
           case Token_private:
diff --git a/languages/cpp/cppduchain/expressionvisitor.cpp \
b/languages/cpp/cppduchain/expressionvisitor.cpp index 5a0908b..77a0e0b 100644
--- a/languages/cpp/cppduchain/expressionvisitor.cpp
+++ b/languages/cpp/cppduchain/expressionvisitor.cpp
@@ -110,8 +110,8 @@ bool isNumber( const IndexedString& str ) {
   return str == _0 || str == _1 || str == _2 || str == _3 || str == _4 || str == _5 \
|| str == _6 || str == _7 || str == _8 || str == _9;  }
 
-QHash<int, QString> initOperatorNames() {
-  QHash<int, QString> ret;
+QHash<quint16, QString> initOperatorNames() {
+  QHash<quint16, QString> ret;
   ret['+'] = "+";
   ret['-'] = "-";
   ret['*'] = "*";
@@ -140,11 +140,11 @@ QHash<int, QString> initOperatorNames() {
   return ret;
 }
 
-QHash<int, QString> operatorNames = initOperatorNames();
+QHash<quint16, QString> operatorNames = initOperatorNames();
 //BUG use the much more complete list from tokens.cpp
-QString operatorNameFromTokenKind( int tokenKind )
+QString operatorNameFromTokenKind( quint16 tokenKind )
 {
-  QHash<int, QString>::const_iterator it = operatorNames.constFind(tokenKind);
+  QHash<quint16, QString>::const_iterator it = operatorNames.constFind(tokenKind);
   if( it == operatorNames.constEnd() )
     return QString();
   else
@@ -858,7 +858,7 @@ struct ConstantUnaryExpressionEvaluator {
   /**
    * Writes the results into endValue, type, and modifier.
    * */
-  ConstantUnaryExpressionEvaluator( int tokenKind, ConstantIntegralType* left ) {
+  ConstantUnaryExpressionEvaluator( quint16 tokenKind, ConstantIntegralType* left ) \
{  endValue = 0;
     type = left->dataType();
     modifier = left->modifiers();
@@ -878,7 +878,7 @@ struct ConstantUnaryExpressionEvaluator {
   }
 
   //This function is used to disable some operators on bool and double values
-  void evaluateSpecialTokens( int tokenKind, ConstantIntegralType* left ) {
+  void evaluateSpecialTokens( quint16 tokenKind, ConstantIntegralType* left ) {
     switch( tokenKind ) {
       case '~':
         endValue = ~left->value<Type>();
@@ -898,13 +898,13 @@ struct ConstantUnaryExpressionEvaluator {
 };
 
 template<>
-void ConstantUnaryExpressionEvaluator<double>::evaluateSpecialTokens( int tokenKind, \
ConstantIntegralType* left ) { +void \
ConstantUnaryExpressionEvaluator<double>::evaluateSpecialTokens( quint16 tokenKind, \
ConstantIntegralType* left ) {  Q_UNUSED(tokenKind);
   Q_UNUSED(left);
 }
 
 template<>
-void ConstantUnaryExpressionEvaluator<float>::evaluateSpecialTokens( int tokenKind, \
ConstantIntegralType* left ) { +void \
ConstantUnaryExpressionEvaluator<float>::evaluateSpecialTokens( quint16 tokenKind, \
ConstantIntegralType* left ) {  Q_UNUSED(tokenKind);
   Q_UNUSED(left);
 }
@@ -1050,7 +1050,7 @@ void ExpressionVisitor::createDelayedType( AST* node , bool \
expression ) {  return;
     }
 
-    int tokenKind = tokenFromIndex(node->op).kind;
+    quint16 tokenKind = tokenFromIndex(node->op).kind;
 
     if(rightType && leftType && rightInstance && leftInstance) {
       LOCKDUCHAIN;
diff --git a/languages/cpp/parser/lexer.h b/languages/cpp/parser/lexer.h
index d97e2cb..b370f89 100644
--- a/languages/cpp/parser/lexer.h
+++ b/languages/cpp/parser/lexer.h
@@ -40,7 +40,7 @@ class KDEVCPPPARSER_EXPORT Token
 {
 public:
   ///kind of the token @see TOKEN_KIND enum reference.
-  int kind;
+  quint16 kind;
   ///position in the preprocessed buffer
   uint position;
   ///size of the token in the preprocessed buffer. Do not confuse this with \
symbolLength. @@ -109,11 +109,11 @@ public:
   { return index++; }
 
   /**@return the kind of the next (LA) token in the stream.*/
-  inline int lookAhead(uint i = 0) const
+  inline quint16 lookAhead(uint i = 0) const
   { return at(index + i).kind; }
 
   /**@return the kind of the current token in the stream.*/
-  inline int kind(uint i) const
+  inline quint16 kind(uint i) const
   { return at(i).kind; }
 
   /**@return the position of the current token in the c++ source buffer.*/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic