First cut at include files.

This commit is contained in:
Chris Pressey 2019-10-22 12:54:04 +01:00
parent 987974cc21
commit 175c07781a
2 changed files with 15 additions and 4 deletions

View File

@ -17,7 +17,7 @@ from tempfile import NamedTemporaryFile
import traceback
from sixtypical.symtab import SymbolTable
from sixtypical.parser import Parser, merge_programs
from sixtypical.parser import Parser, load_program, merge_programs
from sixtypical.analyzer import Analyzer
from sixtypical.callgraph import construct_callgraph, prune_unreachable_routines
from sixtypical.outputter import outputter_class_for
@ -30,11 +30,9 @@ def process_input_files(filenames, options):
programs = []
for filename in options.filenames:
text = open(filename).read()
parser = Parser(symtab, text, filename)
program = load_program(filename, symtab)
if options.debug:
print(symtab)
program = parser.program()
programs.append(program)
if options.parse_only:

View File

@ -96,6 +96,12 @@ class Parser(object):
def program(self):
defns = []
routines = []
includes = []
while self.scanner.consume('include'):
filename = self.scanner.token
self.scanner.scan()
program = load_program(filename, self.symtab)
includes.append(program)
while self.scanner.on('typedef', 'const'):
if self.scanner.on('typedef'):
self.typedef()
@ -470,6 +476,13 @@ class Parser(object):
# - - - -
def load_program(filename, symtab):
text = open(filename).read()
parser = Parser(symtab, text, filename)
program = parser.program()
return program
def merge_programs(programs):
"""Assumes that the programs do not have any conflicts."""