Changeset 5


Ignore:
Timestamp:
Jan 5, 2011, 2:35:16 PM (14 years ago)
Author:
franck
Message:

mpy includes file when it is in brackets (i.e. [file]) only if file has at least 1 extension.
[vci.ports] good
[vci.mpy.ports] good
[vciports] bad

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mpy.py

    r4 r5  
    2525# TODO add unitary tests
    2626# TODO add [ and { despecialization
    27 # TODO save the directory exploration to do it only once per session
    28 # -------------------------------------------------------------------------------------------------
    29 _date = '2009-12-30 16:00'
    30 _version = '1.07'
     27# -------------------------------------------------------------------------------------------------
     28_date = '2011-01-05 14:30'
     29_version = '1.08'
    3130_authors = 'Franck Wajsburt'
    3231_organization = '(UPMC/LIP6/SOC)'
     
    4039==========================================================================='''
    4140
    42 import os, sys, pdb
     41import os, sys, pdb, math, re
    4342from optparse import OptionParser
    4443from datetime import datetime
     
    287286                        # test if buf is a file name, if yes includes file
    288287                        # therefore pushes the current file and opens the new
    289                         incname = _mpyfindfile(buf,mpyidir)
    290                         if incname != '':
    291                            if mpydebug == True:
    292                               _mpylog("\nInclude  to %s from %s" % (mpyout, incname))
    293 
    294                            # push known parameters of the current opened file
    295                            opened_mpyin.append((mpyin, mpybuf, mpyfname,
     288
     289                        if re.match("\w*(\.\w*)+",buf):
     290                           incname = _mpyfindfile(buf,mpyidir)
     291                           if incname != '':
     292                              if mpydebug == True:
     293                                 _mpylog("\nInclude  to %s from %s" % (mpyout, incname))
     294
     295                              # push known parameters of the current opened file
     296                              opened_mpyin.append((mpyin, mpybuf, mpyfname,
    296297                                                mpylineno, mpycharno, mpylength))
    297298
    298                            # old values required for test of recursivity just below
    299                            oldmpyfname = mpyfname
    300                            oldmpylineno = mpylineno
    301 
    302                            # open the include file
    303                            mpyin, mpyfname = _mpyopen(realfname = incname)
    304                            mpybuf = mpyin.read(-1)
    305                            mpylineno = 1
    306                            mpycharno = 0
    307                            mpylength = len(mpybuf)
    308                            level = 0
    309                            buf = mode = ''
    310 
    311                            # test recursive include
    312                            for f in opened_mpyin[:-1]:
    313                               if mpyfname in f:
    314                                  _exit ("%s[%d]: forbidden recursive inclusion on %s"
    315                                         % (oldmpyfname, oldmpylineno, mpyfname))
     299                              # old values required for test of recursivity just below
     300                              oldmpyfname = mpyfname
     301                              oldmpylineno = mpylineno
     302
     303                              # open the include file
     304                              mpyin, mpyfname = _mpyopen(realfname = incname)
     305                              mpybuf = mpyin.read(-1)
     306                              mpylineno = 1
     307                              mpycharno = 0
     308                              mpylength = len(mpybuf)
     309                              level = 0
     310                              buf = mode = ''
     311
     312                              # test recursive include
     313                              for f in opened_mpyin[:-1]:
     314                                 if mpyfname in f:
     315                                    _exit ("%s[%d]: forbidden recursive inclusion on %s"
     316                                           % (oldmpyfname, oldmpylineno, mpyfname))
    316317
    317318                        # just evaluate buf
     
    431432
    432433# -------------------------------------------------------------------------------------------------
     434
     435def log2(x):
     436    return int(math.ceil(math.log(x,2)))
     437
     438# -------------------------------------------------------------------------------------------------
    433439# define globals dictionnary
    434440# -------------------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.