Exemplo n.º 1
0
def parse(testcode, withSystemMacros=True, withGlobalIncludeWrappers=False):
    state = cparser.State()
    if withSystemMacros: state.autoSetupSystemMacros()
    if withGlobalIncludeWrappers: state.autoSetupGlobalIncludeWrappers()
    cparser.parse_code(testcode, state)
    if state._errors:
        print "parsing errors:"
        pprint(state._errors)
        assert False, "there are parsing errors"
    return state
Exemplo n.º 2
0
def parse(filename, state = None):
	if state is None:
		state = cparser.State()
		state.autoSetupSystemMacros()
	
	wrappedState = StateWrapper(state)
	preprocessed = wrappedState.preprocess_file(filename, local=True)
	tokens = cparser.cpre2_parse(wrappedState, preprocessed)
	cparser.cpre3_parse(wrappedState, tokens)
	
	return state
Exemplo n.º 3
0
 def __init__(self, debug=False):
     """
     :param bool debug:
     """
     self.debug = debug
     self.state = cparser.State()
     self.state.autoSetupSystemMacros()
     self.state.autoSetupGlobalIncludeWrappers()
     self.state.readLocalInclude = self._read_local_include_handler
     self.interp = interpreter.Interpreter()
     self.interp.register(self.state)
def prepareState():
    state = cparser.State()
    state.autoSetupSystemMacros()
    state.autoSetupGlobalIncludeWrappers()

    def readInclude(fn):
        if fn == "<input>":
            reader = input_reader_handler(state)
            return reader, None
        return cparser.State.readLocalInclude(state, fn)

    state.readLocalInclude = readInclude
    return state
Exemplo n.º 5
0
def parse(testcode, withSystemMacros=True, withGlobalIncludeWrappers=False):
    """
    :param str testcode:
    :param bool withSystemMacros:
    :param bool withGlobalIncludeWrappers:
    :rtype: cparser.State
    """
    state = cparser.State()
    if withSystemMacros:
        state.autoSetupSystemMacros()
    if withGlobalIncludeWrappers:
        state.autoSetupGlobalIncludeWrappers()
    cparser.parse_code(testcode, state)
    if state._errors:
        print("parsing errors:")
        pprint(state._errors)
        assert False, "there are parsing errors"
    return state
Exemplo n.º 6
0
def newState(testcode,
             testfn="test.c",
             withSystemMacros=True,
             withGlobalIncludeWrappers=False):
    state = cparser.State()
    if withSystemMacros: state.autoSetupSystemMacros()
    if withGlobalIncludeWrappers: state.autoSetupGlobalIncludeWrappers()

    origReadLocal = state.readLocalInclude

    def readLocalIncludeWrapper(fn):
        if fn == testfn:

            def reader():
                for c in testcode:
                    yield c

            reader = reader()
            return reader, fn
        return origReadLocal(fn)

    state.readLocalInclude = readLocalIncludeWrapper

    return state
Exemplo n.º 7
0
def prepareState():
    state = cparser.State()
    state.autoSetupSystemMacros()
    state.autoSetupGlobalIncludeWrappers()
    return state