mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Import the changes to cpreproc.py from the preprocessor branch
These changes make it ready for prime time, but main.py still does not expose the functionality. Changes include: - Instead of passing paths, we pass parameters, which are parsed to extract the paths (no syspaths, only regular paths) and the defines. - Errors in the preprocessor are reported to the caller (i.e. to main).
This commit is contained in:
parent
13e48ff956
commit
8db8872dbe
1 changed files with 32 additions and 10 deletions
42
cpreproc.py
42
cpreproc.py
|
@ -577,31 +577,53 @@ class Evaluator(object):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class Preproc(preprocessor.Preprocessor):
|
class Preproc(preprocessor.Preprocessor):
|
||||||
def __init__(self, input, defines=(), sysincpaths=(), incpaths=()):
|
def __init__(self, input, params=()):
|
||||||
super(Preproc, self).__init__()
|
super(Preproc, self).__init__()
|
||||||
self.auto_pragma_once_enabled = False
|
self.auto_pragma_once_enabled = False
|
||||||
for define in defines:
|
for v in params:
|
||||||
self.define('%s %s' % define)
|
if v.startswith('-I'):
|
||||||
|
self.add_path(v[2:])
|
||||||
for v in sysincpaths:
|
elif v.startswith('-D'):
|
||||||
self.add_path(v)
|
defn = v[2:]
|
||||||
for v in incpaths:
|
if '=' not in defn:
|
||||||
self.add_path(v)
|
defn += '=1'
|
||||||
|
if defn.startswith('='):
|
||||||
|
self.on_error("\nError: Empty macro name in definition.\n")
|
||||||
|
return
|
||||||
|
defn = defn.replace('=', ' ', 1)
|
||||||
|
self.define(defn)
|
||||||
|
elif v.startswith('-U'):
|
||||||
|
defn = v[2:]
|
||||||
|
if defn in self.macros:
|
||||||
|
del self.macros[defn]
|
||||||
|
else:
|
||||||
|
self.on_error("\nError: Option for the internal"
|
||||||
|
" preprocessor not -D, -U or -I:\n %s\n" % v)
|
||||||
|
return
|
||||||
|
|
||||||
self.ignore = set()
|
self.ignore = set()
|
||||||
self.parser = self.parsegen(input, '<stdin>', '<stdin>')
|
self.parser = self.parsegen(input, '<stdin>', '<stdin>')
|
||||||
|
self.errors_present = False
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
if self.errors_present:
|
||||||
|
return True, '', {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import StringIO
|
import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import io as StringIO
|
import io as StringIO
|
||||||
ret = StringIO.StringIO()
|
ret = StringIO.StringIO()
|
||||||
self.write(ret)
|
self.write(ret)
|
||||||
return (ret.getvalue(), self.macros)
|
return (self.errors_present, ret.getvalue(), self.macros)
|
||||||
|
|
||||||
|
def on_error(self, *args, **kwargs):
|
||||||
|
"""Flag that errors are present when called."""
|
||||||
|
self.errors_present = True
|
||||||
|
return super(Preproc, self).on_error(*args, **kwargs)
|
||||||
|
|
||||||
def on_include_not_found(self, is_system_include, curdir, includepath):
|
def on_include_not_found(self, is_system_include, curdir, includepath):
|
||||||
"""Don't pass through the #include line if the file does not exist"""
|
"""Don't pass through the #include line if the file does not exist."""
|
||||||
self.on_error(self.lastdirective.source, self.lastdirective.lineno,
|
self.on_error(self.lastdirective.source, self.lastdirective.lineno,
|
||||||
"Include file not found: %s" % includepath)
|
"Include file not found: %s" % includepath)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue