Skip to content

Commit bc63fe9

Browse files
authored
Merge pull request #171 from ssvb/origname
expander.py: trace line numbers back to the original source file
2 parents 4b044e4 + 7d6622e commit bc63fe9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

expander.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ def expand_acl(self, acl_file_path: Path) -> List[str]:
6363
result.append(line)
6464
return result
6565

66-
def expand(self, source: str) -> str:
66+
def expand(self, source: str, origname) -> str:
6767
self.included = set()
6868
result = [] # type: List[str]
69+
linenum = 0
6970
for line in source.splitlines():
71+
linenum += 1
7072
m = self.atcoder_include.match(line)
7173
if m:
7274
acl_path = self.find_acl(m.group(1))
7375
result.extend(self.expand_acl(acl_path))
76+
if origname:
77+
result.append('#line ' + str(linenum + 1) + ' "' + origname + '"')
7478
continue
7579

7680
result.append(line)
@@ -88,6 +92,8 @@ def expand(self, source: str) -> str:
8892
parser.add_argument('-c', '--console',
8993
action='store_true', help='Print to Console')
9094
parser.add_argument('--lib', help='Path to Atcoder Library')
95+
parser.add_argument('--origname', help='report line numbers from the original ' +
96+
'source file in GCC/Clang error messages')
9197
opts = parser.parse_args()
9298

9399
lib_paths = []
@@ -99,7 +105,7 @@ def expand(self, source: str) -> str:
99105
lib_paths.append(Path.cwd())
100106
expander = Expander(lib_paths)
101107
source = open(opts.source).read()
102-
output = expander.expand(source)
108+
output = expander.expand(source, opts.origname)
103109

104110
if opts.console:
105111
print(output)

0 commit comments

Comments
 (0)