Пример #1
0
def setCanonFlags(config):
    setPrePostFlags(config)
    # configure forward/reverse mode
    if config.mode:
        if config.mode[0] == 'f':
            UnitCanonicalizer.setHoistConstantsFlag(False)
            UnitCanonicalizer.setHoistStringsFlag(False)
        elif config.mode[0] == 'r':
            UnitCanonicalizer.setHoistConstantsFlag(True)
            UnitCanonicalizer.setHoistStringsFlag(False)
    # set symtab type defaults
    if config.r8:
        Symtab.setTypeDefaults((fs.DoubleStmt, []), (fs.IntegerStmt, []))
    if config.removeFunction:
        UnitCanonicalizer.setKeepFunctionDef(False)
    if config.hoistConstantsFlag:
        UnitCanonicalizer.setHoistConstantsFlag(config.hoistConstantsFlag)
    if config.hoistStringsFlag:
        UnitCanonicalizer.setHoistStringsFlag(config.hoistStringsFlag)
    if config.subroutinizeIntegerFunctions:
        UnitCanonicalizer.setSubroutinizeIntegerFunctions(True)
    if config.keepGoing:
        CanonError.keepGoing()
    if config.warn:
        DebugManager.warnOnlyOn(config.warn)
    if config.progress:
        DebugManager.dumpProgress()
    if config.includePaths:
        Ffile.setIncludeSearchPath(config.includePaths)
    if config.nonStandard:
        useNonStandard(config.nonStandard)
    if (config.overloading):
        UnitCanonicalizer.setOverloadingMode()
Пример #2
0
def setSourceProcessingFlags(config):
    # set outputFormat explicitly if format or output file are supplied by user.
    # otherwise, outputFormat is set to inputFormat during parsing
    if config.outputFormat == None:
        if config.outputFile:
            ext = os.path.splitext(config.outputFile)[1]
            config.outputFormat = Ffile.get_format(ext)
            setOutputFormat(config.outputFormat)
    elif (config.outputFormat <> 'fixed') and (config.outputFormat <> 'free'):
        opt.error(
            "outputFormat option must be specified with either 'fixed' or 'free' as an argument"
        )
    else:
        setOutputFormat(config.outputFormat)
    if config.outputLineLength:
        setOutputLineLength(config.outputLineLength)
    if config.inputLineLength:
        setInputLineLength(config.inputLineLength)
    # set symtab type defaults
    Symtab.setTypeDefaults((fs.RealStmt, []), (fs.IntegerStmt, []))
    # parse info units
    if config.infoUnitFile:
        from PyFort.fortUnit import fortUnitIterator
        for aUnit in fortUnitIterator(config.infoUnitFile, config.inputFormat):
            # need to parse this so the type information is available, but do not modify or print units
            pass
    # set verbosity
    DebugManager.setVerbose(config.isVerbose)
    DebugManager.setQuiet(config.noWarnings)
    DebugManager.setCheck(config.check)
Пример #3
0
 def setUp(self):
     self.typetab = Typetab()
     s = Symtab()
     s.enter_name('TOP', C1.topSE)
     ts = Symtab(s)
     ts.enter_name('foo', C1.fooSE)
     self.symtab = ts
Пример #4
0
    def setUp(self):
        t = Symtab()
        t.enter_name('TOP', C1.topSE)

        ts = Symtab(t)
        ts.enter_name('fOo', C1.fooSE)
        self.ts = ts
Пример #5
0
def _beginProcedureUnit(aProcedureDeclStmt, cur):
    '''
    called for function/subroutine statements within an interface block
    '''
    localSymtab = Symtab(cur.val.symtab)
    DebugManager.debug('[Line '+str(aProcedureDeclStmt.lineNumber)+']: stmt2unit._beginProcedureUnit:' \
                      +' called for '+aProcedureDeclStmt.__class__.__name__+': "'+str(aProcedureDeclStmt)+'"' \
                      +' changing from current symtab "'+str(cur.val.symtab)+'"' \
                      +' to local symtab "'+str(localSymtab)+'"')
    entry = aProcedureDeclStmt.makeSymtabEntry(localSymtab)
    localSymtab.enter_name(aProcedureDeclStmt.name, entry)
    cur.val.symtab.enter_name(aProcedureDeclStmt.name, entry)
    cur.val.symtab = localSymtab
    if (isinstance(aProcedureDeclStmt, fs.FunctionStmt)):
        cur.val._in_iface._in_procedureFuncDecl = aProcedureDeclStmt
    return aProcedureDeclStmt
def __skipThisType(onlyRequired,key,typeClass,aRanks):
    return ((onlyRequired
             and
             (((key,typeClass,aRanks) not in _requiredSubroutinizedIntrinsics)
              or 
              (Symtab.getRealTypeDefault()[0]==fs.DoubleStmt
               and
               typeClass==fs.RealStmt
               and
               (key, fs.DoubleStmt,aRanks) in _requiredSubroutinizedIntrinsics)))
            or
            (not onlyRequired
             and
             Symtab.getRealTypeDefault()[0]==fs.DoubleStmt
             and
             typeClass==fs.RealStmt))
Пример #7
0
def _beginInterface(anInterfaceStmt, cur):
    if (anInterfaceStmt.name):
        cur.val.symtab.enter_name(
            anInterfaceStmt.name,
            SymtabEntry(SymtabEntry.InterfaceEntryKind()))
    cur.val._in_iface = InterfaceInfo(anInterfaceStmt.name, cur.val._in_iface)
    DebugManager.debug('[Line ' + str(anInterfaceStmt.lineNumber) +
                       ']: stmt2unit._beginInterface(' + str(anInterfaceStmt) +
                       ')')
    if (anInterfaceStmt.name):
        # collect all the procedurenames in a mock symtab...
        localSymtab = Symtab(cur.val.symtab)
        cur.val.symtab = localSymtab
    # local attribute added on to convey the name to _endInterface
    return anInterfaceStmt
Пример #8
0
 def __init__(self, parent=None, fmod=None):
     'create a unit'
     self.cmnt = None
     self.uinfo = None
     self.decls = []
     self.execs = []
     self.contains = []
     self.ulist = []
     self.end = []
     self.parent = parent
     if parent:
         self.nestLevel = parent.nestLevel + 1
     else:
         self.nestLevel = 0
     self.symtab = Symtab(_symtab_of(parent))
     self.fmod = fmod
     self._in_iface = None  # this would be set to an InterfaceInfo instance if we are in an interface
     self._in_drvdType = None  # this would be set to the name of the derived type being processed
     self._drvdTypeDefaultAccess = None  # this would be set for access while the derived type is being processed
     self._in_functionDecl = None  # this will be set to the FunctionDeclStmt if a function is being processed
     self._in_subroutineDecl = None  # this will be set to the SubroutineDeclStmt if a subroutine is being processed
     DebugManager.debug('new unit created: ' + str(self) +
                        ', new symtab being created = ' + str(self.symtab))
Пример #9
0
from Setup import *
from unittest import *
from useparse import *

from PyUtil.symtab import Symtab, globalTypeTable
from PyUtil.typetab import TypetabEntry

from PyFort.inference import expressionType, _TypeContext, _kw2type, _lenfn
import PyFort.fortStmts as fortStmts
from PyFort.fortStmts import LogicalStmt, CharacterStmt, IntegerStmt, RealStmt, DoubleStmt, ComplexStmt, DoubleCplexStmt
from PyFort.fortStmts import _Prec, _Kind, _F77Len

Symtab.setTypeDefaults((fortStmts.RealStmt, []), (fortStmts.IntegerStmt, []))
theSymtab = Symtab()


class TypeUtils(TestCase):
    '''Typing, and misc xform utilities
    '''
    def test1(self):
        '_kw2type'
        self.assertEquals(_kw2type('real'), fortStmts.RealStmt)
        self.assertEquals(_kw2type('doubleprecision'), fortStmts.DoubleStmt)
        self.assertEquals(_kw2type('integer'), fortStmts.IntegerStmt)
        self.assertEquals(_kw2type('logical'), fortStmts.LogicalStmt)

    def test2(self):
        '_lenfn'
        self.assertEquals(str(_lenfn(15)), '*15')

Пример #10
0
 def __init__(self):
     self.symtab = Symtab()
Пример #11
0
from Setup import *
from unittest import *

from PyUtil.symtab import Symtab, globalTypeTable
from PyFort.inference import expressionType

from PyFort.stmt2unit import *
from PyFort.stmt2unit import _implicit

from useparse import *

Symtab.setTypeDefaults((fs.RealStmt,[]),(fs.IntegerStmt,[]))

class U(object):
    def __init__(self):
        self.symtab = Symtab()

class _curr(object):
    def __init__(self):
        self.val = U()

class C1(TestCase):
    def test1(self):
        'implicit action'

        cur = _curr()

        # s0 = pps('parameter (special=2)')
        # s1 = pps('implicit integer(special) (a-f)')
        # sr = _implicit(s1,cur)
        v = cur.val.symtab
Пример #12
0
from unittest import *
from PyUtil.errors import UserError
from PyUtil.symtab import Symtab
from PyFort.fortUnit import fortUnitIterator
from PyFort.fortStmts import RealStmt, IntegerStmt
from PyFort.flow import setOutputFormat
from Canon.canon import UnitCanonicalizer, CanonError
from PyUtil.debugManager import DebugManager
from PyFort.flow import setOutputFormat
'''
Unit tests for canonicalizer

'''
DebugManager.setQuiet(True)

Symtab.setTypeDefaults((RealStmt, []), (IntegerStmt, []))


def compareFiles(assertFunc,
                 originalFileName,
                 RefFileName,
                 format,
                 hoistStrings=False):
    try:
        (fd, testFileName) = tempfile.mkstemp()
        testFile = open(testFileName, 'w')
        setOutputFormat(format)
        UnitCanonicalizer.setHoistStringsFlag(hoistStrings)
        for aUnit in fortUnitIterator(fname_t(originalFileName), format):
            setOutputFormat(format)
            UnitCanonicalizer(aUnit).canonicalizeUnit().printit(testFile)