Example #1
0
  def eval_cSource(self, cPPAST):
    def preprocess_replace(ctokens):
      return self._eval(ppAst('ReplacementList', {'tokens': ctokens}))
    sourceCode = SourceCodeString(cPPAST.getResource(), cPPAST.getString(), cPPAST.getLine(), cPPAST.getColumn())
    cLex = cLexer(sourceCode, pp_expander=preprocess_replace, context=self.cLexerContext)
    self.cLexerContext = cLex.getContext()

    cLexList = TokenList(cLex)
    self.line += len(list(filter(lambda x: x == '\n', cPPAST.getString()))) + 1
    return cLexList
Example #2
0
 def getGccOutput(self):
   regex = re.compile(r'^\#.*$', re.M)
   null = open('/dev/null', 'w')
   filepath = os.path.join(self.filepath, 'source.c')
   gcc = subprocess.check_output(['gcc', '-std=c99', '-E', filepath], stderr=null)
   null.close()
   gcc = gcc.decode('ascii')
   gcc = regex.sub('', gcc)
   sourcecode = SourceCodeString('<string>', gcc)
   cL = cLexer(sourcecode)
   actualTokens = list(map(mapFuncSimple, list(cL)))
   return '\n'.join(actualTokens)