forked from wskellenger-intrepid/warning_scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gcc.py
63 lines (49 loc) · 1.87 KB
/
Gcc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pyparsing as pp
from pathlib import Path
from Warning import Warning
from LineParser import LineParser
import pp_defs
from linecache import getline
from util import getpathfrom
#TODO: IMPLEMENT
all_warnings = {
}
#example
# /full/path/to/helloworld.h:230:7: warning: 'DiagnosticJobImpl' has a field 'DiagnosticJobImpl::m_eCANTxType' whose type uses the anonymous namespace [enabled by default]
class GccLineParser(LineParser):
grammar = pp.SkipTo(pp_defs.GCCPOSITIONINFO)("file") + pp_defs.GCCPOSITIONINFO("pos") \
+ pp.Literal("warning:") + pp.White() \
+ pp.SkipTo(pp_defs.BRACKETED("warningid") + pp.LineEnd(), include=True)("message")
def setGrammar(self, grammar):
self.grammar = grammar
def setLine(self, rawline):
self.rawline = rawline
def parseLine(self):
try:
self.matches = self.grammar.parseString(self.rawline)
except:
self.matches = None
def getWarningObject(self):
warningobj = None
if (self.matches != None):
warningobj = Warning()
try:
pos = self.matches["pos"]
warningobj.linenumber = int(pos[0])
if len(self.matches["pos"]) == 2:
warningobj.colnumber = int(pos[1])
except:
print("Error: Parser failed to match on line: {0}".format(self.rawline))
try:
warningobj.warningid = self.matches["warningid"].strip()
except:
warningobj.warningid = ""
try:
warningobj.warningmessage = self.matches["message"].strip()
except:
warningobj.warningmessage = ""
try:
warningobj.fullpath = Path(self.matches["file"])
except:
warningobj.fullpath = ""
return warningobj