ccc: Extend ArgList to support indexing into a synthetic arg array
(for killing off DerivedArg).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61846 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/ccc/ccclib/Arguments.py b/tools/ccc/ccclib/Arguments.py
index ee234f1..0636789 100644
--- a/tools/ccc/ccclib/Arguments.py
+++ b/tools/ccc/ccclib/Arguments.py
@@ -206,20 +206,44 @@
def render(self, args):
return [self.value]
+###
+
+class InputIndex:
+ def __init__(self, sourceId, pos):
+ self.sourceId = sourceId
+ self.pos = pos
+
+ def __repr__(self):
+ return 'InputIndex(%d, %d)' % (self.sourceId, self.pos)
+
class ArgList:
"""ArgList - Collect an input argument vector along with a set of parsed Args
and supporting information."""
def __init__(self, argv):
self.argv = list(argv)
- self.args = []
+ self.syntheticArgv = []
self.lastArgs = {}
+ self.args = []
def getLastArg(self, option):
return self.lastArgs.get(option)
def getInputString(self, index, offset=0):
- return self.argv[index + offset]
+ # Source 0 is argv.
+ if index.sourceId == 0:
+ return self.argv[index.pos + offset]
+
+ # Source 1 is synthetic argv.
+ if index.sourceId == 1:
+ return self.syntheticArgv[index.pos + offset]
+
+ raise RuntimeError,'Unknown source ID for index.'
+
+ def getSyntheticIndex(self, *strings):
+ pos = len(self.syntheticArgv)
+ self.syntheticArgv.extend(strings)
+ return InputIndex(1, pos)
# Support use as a simple arg list.
@@ -460,7 +484,8 @@
iargs = enumerate(argv)
it = iter(iargs)
args = ArgList(argv)
- for i,a in it:
+ for pos,a in it:
+ i = InputIndex(0, pos)
# FIXME: Handle '@'
if not a:
# gcc's handling of empty arguments doesn't make