@@ -678,7 +678,6 @@ def acceptPreformatted(self, node, memo):
678678 return acceptPreformatted
679679
680680 acceptArrayElementAccess = makeNodePreformattedExpr (FS .l + '[' + FS .r + ']' )
681- acceptCastExpr = makeNodePreformattedExpr (FS .l + '(' + FS .r + ')' ) # problem?
682681 acceptDiv = makeNodePreformattedExpr (FS .l + ' / ' + FS .r )
683682 acceptLogicalAnd = makeNodePreformattedExpr (FS .l + ' and ' + FS .r )
684683 acceptLogicalNot = makeNodePreformattedExpr ('not ' + FS .l )
@@ -690,6 +689,34 @@ def acceptPreformatted(self, node, memo):
690689 acceptUnaryMinus = makeNodePreformattedExpr ('-' + FS .l )
691690 acceptUnaryPlus = makeNodePreformattedExpr ('+' + FS .l )
692691
692+ def acceptCastExpr (self , node , memo ):
693+ """ Accept and process a cast expression. """
694+ # If the type of casting is a primitive type,
695+ # then do the cast, else drop it.
696+ factory = self .factory .expr
697+ typeTok = node .firstChildOfType (tokens .TYPE )
698+ typeIdent = typeTok .firstChild ()
699+ typeName = typeIdent .text
700+ if typeIdent .type == tokens .QUALIFIED_TYPE_IDENT :
701+ typeName = typeIdent .firstChild ().text
702+
703+ if typeName in tokens .primitiveTypeNames :
704+ # Cast using the primitive type constructor
705+ self .fs = typeName + '(' + FS .r + ')'
706+ else :
707+ mode = self .config .last ('objCastMode' )
708+ if mode == 'drop' :
709+ # Use drop policy
710+ self .fs = FS .r
711+ elif mode == 'ctor' :
712+ # Make constructor
713+ self .fs = FS .l + '(' + FS .r + ')'
714+ else :
715+ warn ('Couldn\' t perform cast operation. ' + typeName + \
716+ ' is not a primitive and objCastMode in the config file has wrong value.' )
717+ self .left , self .right = visitors = factory (parent = self ), factory (parent = self )
718+ self .zipWalk (node .children , visitors , memo )
719+
693720 def makeAcceptPrePost (suffix , pre ):
694721 """ Make an accept method for pre- and post- assignment expressions. """
695722 def acceptPrePost (self , node , memo ):
0 commit comments