Package pyraf :: Module cl2py
[hide private]
[frames] | no frames]

Module cl2py

source code

cl2py.py: Translate IRAF CL program to Python

$Id: cl2py.py 789 2007-04-17 19:09:03Z nadia@astropy.scipy.org $

R. White, 1999 December 20

Classes [hide private]
  Container
Simple container class (no methods) for holding picklable objects
  Pycode
Container for Python CL translation
  FindLineNumber
Helper class to find first line number in an AST
  ErrorTracker
Mixin class that does error tracking during AST traversal
  ExtractProcInfo
Extract name and args from procedure statement
  Variable
Container for properties of a variable
  ExtractDeclInfo
Extract list of variable definitions from parameter block
  VarList
Scan tree and get info on procedure, parameters, and local variables
  TypeCheck
Determine types of all expressions
  BlockInfo
Helper class to store block structure info for GOTO analysis
  GoToAnalyze
AST traversal for CL GOTO analysis
  CheckArgList
Check task argument list for errors
  Tree2Python
Functions [hide private]
 
cl2py(filename=None, string=None, parlist=None, parfile="", mode="proc", local_vars_dict=None, local_vars_list=None, usecache=1)
Read CL program from file and return pycode object with Python equivalent
source code
 
checkCache(filename, pycode)
Returns true if pycode is up-to-date
source code
 
_checkVars(vars, parlist, parfile)
Check variable list for consistency with the given parlist
source code
 
_funcName(requireType, exprType) source code
 
_arithType(node1, node2) source code
 
_numberType(node) source code
 
_getCLVarType(name)
Returns CL parameter data type if this is a CL variable, "unknown" if not
source code
 
_convFunc(var, value) source code
Variables [hide private]
  _parser = None
  _longTypeName = {"s": "string", "f": "file", "struct": "struct...
  _SpecialArgs = {'taskObj': None,}
  _typeDict = {'int': 'int', 'real': 'float', 'double': 'float',...
  _rfuncDict = {'int': {'int': None, 'float': None, 'string': 'i...
  _numberTypes = ['float', 'int', 'unknown']
  _CLVarDict = {}
  _translateList = {"{": "", "}": "", ";": "", "!": "not ", "//"...
  _taskList = {"print": "clPrint", "_curpack": "curpack", "_allo...
  _functionList = {"int": "iraf.integer", "str": "str", "abs": "...
  _functionType = {"int": "int", "real": "float", "sin": "float"...
  _LogOpDict = {"&&": " and ", "||": " or ",}
  _RedirDict = {">": "Stdout", ">>": "StdoutAppend", ">&": "Stde...
  _bothSpaceList = {"=": 1, "ASSIGNOP": 1, "COMPOP": 1, "+": 1, ...
  _trailSpaceList = {",": 1, "REDIR": 1, "IF": 1, "WHILE": 1,}
  _stringTypes = {"string": 1, "char": 1, "file": 1, "struct": 1...

Imports: cStringIO, os, sys, GenericASTTraversal, AST, Token, clscan, clparse, codeCache, Verbose, irafpar, minmatch, irafutils, irafglobals


Function Details [hide private]

cl2py(filename=None, string=None, parlist=None, parfile="", mode="proc", local_vars_dict=None, local_vars_list=None, usecache=1)

source code 
Read CL program from file and return pycode object with Python equivalent

filename: Name of the CL source file or a filehandle from which the
        source code can be read.
string: String containing the source code.  Either filename or string must be
        specified; if both are specified, only filename is used
parlist: IrafParList object with list of parameters (which may have already
        been defined from a .par file)
parfile: Name of the .par file used to define parlist.  parlist may be
        defined even if parfile is null, but a null parfile is interpreted
        to mean that the parameter definitions in the CL script should
        override the parlist.  If parfile is not null, it is an error if
        the CL script parameters conflict with the parlist.
mode: Mode of translation.  Default "proc" creates a procedure script
        (which defines a Python function.)  Normally CL scripts will be
        translated using this default.  If mode is "single" then the
        necessary environment is assumed to be set and the Python
        code simply gets executed directly.  This is used in the
        CL compatibility mode and other places where a single line of
        CL must be executed.
        Mode also determines whether parameter sets are saved in calls
        to CL tasks.  In "single" mode parameters do get saved; in
        "proc" mode they do not get saved.  This is intended to be
        consistent with the behavior of the IRAF CL, where parameter
        changes in scripts are not preserved.
local_vars_dict, local_vars_list: Initial definitions of local variables.
        May be modified by declarations in the CL code.  This is used only for
        "single" mode to allow definitions to persist across statements.
usecache: Set to false value to omit use of code cache for either saving
        or retrieving code.  This is useful mainly for compiler testing.

_getCLVarType(name)

source code 

Returns CL parameter data type if this is a CL variable, "unknown" if not

Note that this can be incorrect about the data type for CL variables that are masked by package level variables. Too bad, that is just too ugly to be believed anyway. Don't do that.


Variables Details [hide private]

_longTypeName

Value:
{"s": "string", "f": "file", "struct": "struct", "i": "int", "b": "boo\
l", "r": "real", "d": "double", "gcur": "gcur", "imcur": "imcur", "uke\
y": "ukey", "pset": "pset",}

_typeDict

Value:
{'int': 'int', 'real': 'float', 'double': 'float', 'bool': 'bool', 'st\
ring': 'string', 'char': 'string', 'struct': 'string', 'file': 'string\
', 'gcur': 'string', 'imcur': 'string', 'ukey': 'string', 'pset': 'unk\
nown',}

_rfuncDict

Value:
{'int': {'int': None, 'float': None, 'string': 'int', 'bool': None, 'u\
nknown': 'int', 'indef': None}, 'float': {'int': None, 'float': None, \
'string': 'float', 'bool': 'float', 'unknown': 'float', 'indef': None}\
, 'string': {'int': 'str', 'float': 'str', 'string': None, 'bool': 'ir\
af.bool2str', 'unknown': 'str', 'indef': None}, 'bool': {'int': 'iraf.\
boolean', 'float': 'iraf.boolean', 'string': 'iraf.boolean', 'bool': N\
one, 'unknown': 'iraf.boolean', 'indef': None}, 'indef': {'int': None,\
 'float': None, 'string': None, 'bool': None, 'unknown': None, 'indef'\
...

_translateList

Value:
{"{": "", "}": "", ";": "", "!": "not ", "//": " + ",}

_taskList

Value:
{"print": "clPrint", "_curpack": "curpack", "_allocate": "clAllocate",\
 "_deallocate": "clDeallocate", "_devstatus": "clDevstatus",}

_functionList

Value:
{"int": "iraf.integer", "str": "str", "abs": "iraf.absvalue", "min": "\
iraf.minimum", "max": "iraf.maximum",}

_functionType

Value:
{"int": "int", "real": "float", "sin": "float", "cos": "float", "tan":\
 "float", "atan2": "float", "exp": "float", "log": "float", "log10": "\
float", "sqrt": "float", "frac": "float", "abs": "float", "min": "unkn\
own", "max": "unknown", "fscan": "int", "scan": "int", "fscanf": "int"\
, "scanf": "int", "nscan": "int", "stridx": "int", "strlen": "int", "s\
tr": "string", "substr": "string", "envget": "string", "mktemp": "stri\
ng", "radix": "string", "osfn": "string", "_curpack": "string", "defpa\
r": "bool", "access": "bool", "defvar": "bool", "deftask": "bool", "de\
...

_RedirDict

Value:
{">": "Stdout", ">>": "StdoutAppend", ">&": "Stderr", ">>&": "StderrAp\
pend", "<": "Stdin",}

_bothSpaceList

Value:
{"=": 1, "ASSIGNOP": 1, "COMPOP": 1, "+": 1, "-": 1, "/": 1, "*": 1, "\
//": 1,}

_stringTypes

Value:
{"string": 1, "char": 1, "file": 1, "struct": 1, "gcur": 1, "imcur": 1\
, "ukey": 1, "pset": 1,}