Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion expander.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ def is_ignored_line(self, line) -> bool:
return True
return False

def in_block_comment_after(self, line: str, in_comment: bool) -> bool:
# returns whether a /* */ comment is still open at the end of line
i = 0
quote = None # type: Optional[str]
while i < len(line):
if in_comment:
if line.startswith('*/', i):
in_comment = False
i += 1
elif quote:
if line[i] == '\\':
i += 1
elif line[i] == quote:
quote = None
elif line.startswith('//', i):
break
elif line.startswith('/*', i):
in_comment = True
i += 1
elif line[i] in '"\'':
quote = line[i]
i += 1
return in_comment

def __init__(self, lib_paths: List[Path]):
self.lib_paths = lib_paths

Expand Down Expand Up @@ -67,9 +91,11 @@ def expand(self, source: str, origname) -> str:
self.included = set()
result = [] # type: List[str]
linenum = 0
in_comment = False
for line in source.splitlines():
linenum += 1
m = self.atcoder_include.match(line)
m = None if in_comment else self.atcoder_include.match(line)
in_comment = self.in_block_comment_after(line, in_comment)
if m:
acl_path = self.find_acl(m.group(1))
result.extend(self.expand_acl(acl_path))
Expand Down
12 changes: 12 additions & 0 deletions test/expander/comment_out_multiline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
#include <atcoder/dsu>
*/
/* comment */ /*
#include <atcoder/dsu>
*/
const char *s = "/*";
#include <atcoder/dsu>

int main() {
atcoder::dsu uf(10);
}
4 changes: 4 additions & 0 deletions test/test_expander.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def test_comment_out(self):
self.compile_test(Path('test/expander/comment_out.cpp'),
expander_args=['--lib', str(Path.cwd().resolve())])

def test_comment_out_multiline(self):
self.compile_test(Path('test/expander/comment_out_multiline.cpp'),
expander_args=['--lib', str(Path.cwd().resolve())])

def test_env_value(self):
env = environ.copy()
env['CPLUS_INCLUDE_PATH'] = str(Path.cwd().resolve())
Expand Down