GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cast fully handled. For objects and primitives · iuliux/java2python@db60b70

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java2python
    • compiler
      • visitor.py
    • config
      • default.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java2python/compiler/visitor.py‎

Copy file name to clipboardExpand all lines: java2python/compiler/visitor.py
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ def acceptPreformatted(self, node, memo):
689689
acceptUnaryMinus = makeNodePreformattedExpr('-' + FS.l)
690690
acceptUnaryPlus = makeNodePreformattedExpr('+' + FS.l)
691691

692-
def acceptCastExpr(self, node, memo): # problem?
692+
def acceptCastExpr(self, node, memo):
693693
""" Accept and process a cast expression. """
694694
# If the type of casting is a primitive type,
695695
# then do the cast, else drop it.
@@ -699,12 +699,21 @@ def acceptCastExpr(self, node, memo): # problem?
699699
typeName = typeIdent.text
700700
if typeIdent.type == tokens.QUALIFIED_TYPE_IDENT:
701701
typeName = typeIdent.firstChild().text
702-
702+
703703
if typeName in tokens.primitiveTypeNames:
704704
# Cast using the primitive type constructor
705705
self.fs = typeName + '(' + FS.r + ')'
706706
else:
707-
self.fs = FS.r
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.')
708717
self.left, self.right = visitors = factory(parent=self), factory(parent=self)
709718
self.zipWalk(node.children, visitors, memo)
710719

Collapse file

‎java2python/config/default.py‎

Copy file name to clipboardExpand all lines: java2python/config/default.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@
173173
# convenience.
174174

175175

176+
# Specifies how cast operations of non-primitive types are handled
177+
# (primitive types are automatically handled)
178+
# Valid values:
179+
# - 'drop': completely drops type and cast info
180+
# - 'ctor': converts the cast in a constructor call
181+
# E.g.: (Cast) x -> Cast(x)
182+
objCastMode = 'drop'
183+
184+
176185
# module output subs.
177186
moduleOutputSubs = [
178187
(r'System\.out\.println\((.*)\)', r'print \1'),

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.