bgenVariable.py :  » Language-Interface » ChinesePython » chinesepython2.1.3-0.4 » Tools » bgen » bgen » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » ChinesePython 
ChinesePython » chinesepython2.1.3 0.4 » Tools » bgen » bgen » bgenVariable.py
"""Variables, arguments and argument transfer modes etc."""


# Values to represent argument transfer modes
InMode    = 1 # input-only argument
OutMode   = 2 # output-only argument
InOutMode = 3 # input-output argument
ModeMask  = 3 # bits to keep for mode


# Special cases for mode/flags argument
# XXX This is still a mess!
SelfMode   =  4+InMode  # this is 'self' -- don't declare it
ReturnMode =  8+OutMode # this is the function return value
ErrorMode  = 16+OutMode # this is an error status -- turn it into an exception


class Variable:

  """A Variable holds a type, a name, a transfer mode and flags.

  Most of its methods call the correponding type method with the
  variable name.
  """

  def __init__(self, type, name = None, flags = InMode):
    """Call with a type, a name and flags.

    If name is None, it muse be set later.
    flags defaults to InMode.
    """
    self.type = type
    self.name = name
    self.flags = flags
    self.mode = flags & ModeMask

  def declare(self):
    """Declare the variable if necessary.

    If it is "self", it is not declared.
    """
    if self.flags != SelfMode:
      self.type.declare(self.name)

  def getargsFormat(self):
    """Call the type's getargsFormatmethod."""
    return self.type.getargsFormat()

  def getargsArgs(self):
    """Call the type's getargsArgsmethod."""
    return self.type.getargsArgs(self.name)

  def getargsCheck(self):
    return self.type.getargsCheck(self.name)

  def passArgument(self):
    """Return the string required to pass the variable as argument.

    For "in" arguments, return the variable name.
    For "out" and "in out" arguments,
    return its name prefixed with "&".
    """
    if self.mode == InMode:
      return self.type.passInput(self.name)
    if self.mode in (OutMode, InOutMode):
      return self.type.passOutput(self.name)
    # XXX Shouldn't get here
    return "/*mode?*/" + self.type.passInput(self.name)

  def errorCheck(self):
    """Check for an error if necessary.

    This only generates code if the variable's mode is ErrorMode.
    """
    if self.flags == ErrorMode:
      self.type.errorCheck(self.name)

  def mkvalueFormat (self):
    """Call the type's mkvalueFormat method."""
    return self.type.mkvalueFormat()

  def mkvalueArgs(self):
    """Call the type's mkvalueArgs method."""
    return self.type.mkvalueArgs(self.name)

  def cleanup(self):
    """Call the type's cleanup method."""
    return self.type.cleanup(self.name)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.