Skip to content

Commit 791fb09

Browse files
committed
Update syntax checking, add it to CI pipeline.
Comments to switch syntax checking on and off. Address false positives among OpDiLib's files. Fix syntax checking of a single file. Merge branch 'revisit/syntax' into develop
2 parents d431a7f + 8d9356e commit 791fb09

7 files changed

Lines changed: 43 additions & 16 deletions

.gitlab-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ output:
5656
- export OUTPUT_INSTRUMENT=yes
5757
- export STDERR_OUTPUT_IS_ERROR=no
5858
- make all
59+
60+
syntax:
61+
image: ubuntu:24.04
62+
script:
63+
- apt update
64+
- DEBIAN_FRONTEND=noninteractive apt install -y tzdata
65+
- apt install -y python3
66+
- python3 syntax/check.py -r syntax/opdi.syntax.json tests macroexample.cpp omptexample.cpp

syntax/check.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def check_file(code_file, syntax_file, verbose):
123123
stack = []
124124

125125
state = State.CODE
126+
enabled = True
126127

127128
# parse line by line
128129
while True:
@@ -132,6 +133,20 @@ def check_file(code_file, syntax_file, verbose):
132133
break
133134
line = line.strip()
134135

136+
# identify comments that enable/disable syntax checking
137+
if line.startswith("//"):
138+
if line[2:].strip() == "opdi-syntax-on":
139+
print_status("enable syntax checking", line_no, line, verbose)
140+
enabled = True
141+
continue
142+
if line[2:].strip() == "opdi-syntax-off":
143+
print_status("disable syntax checking", line_no, line, verbose)
144+
enabled = False
145+
continue
146+
147+
if not enabled:
148+
continue
149+
135150
# eliminate /* */ comments within this line
136151
begin = line.find("/*")
137152
while begin != -1 and line.find("*/", begin) != -1:
@@ -237,7 +252,7 @@ def main():
237252

238253
for path in args.path:
239254
if os.path.isfile(path):
240-
result = check_and_report_result(args.file, args.syntax, args.stop_on_error, args.quiet, args.verbose)
255+
result = check_and_report_result(path, args.syntax, args.stop_on_error, args.quiet, args.verbose)
241256
all_fine = all_fine and result
242257
elif os.path.isdir(path):
243258
if args.recursive:

tests/tests/TestExternalFunctionGlobal.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ struct TestExternalFunctionGlobal : public TestBase<4, 1, 3, TestExternalFunctio
9898
eh->addOutput(intermediate[i]);
9999
}
100100
}
101-
#if _OPENMP >= 202011
102-
OPDI_END_MASKED
103-
#else
101+
#if _OPENMP < 202011
104102
OPDI_END_MASTER
103+
#else
104+
OPDI_END_MASKED
105105
#endif
106106

107107
OPDI_BARRIER()
@@ -129,10 +129,10 @@ struct TestExternalFunctionGlobal : public TestBase<4, 1, 3, TestExternalFunctio
129129
{
130130
delete eh;
131131
}
132-
#if _OPENMP >= 202011
133-
OPDI_END_MASKED
134-
#else
132+
#if _OPENMP < 202011
135133
OPDI_END_MASTER
134+
#else
135+
OPDI_END_MASKED
136136
#endif
137137
}
138138
OPDI_END_PARALLEL

tests/tests/TestExternalFunctionLogicCalls.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ struct TestExternalFunctionLogicCalls : public TestBase<4, 1, 3, TestExternalFun
131131
eh->addOutput(intermediate[i]);
132132
}
133133
}
134-
#if _OPENMP >= 202011
135-
OPDI_END_MASKED
136-
#else
134+
#if _OPENMP < 202011
137135
OPDI_END_MASTER
136+
#else
137+
OPDI_END_MASKED
138138
#endif
139139

140140
OPDI_BARRIER()
@@ -162,10 +162,10 @@ struct TestExternalFunctionLogicCalls : public TestBase<4, 1, 3, TestExternalFun
162162
{
163163
delete eh;
164164
}
165-
#if _OPENMP >= 202011
166-
OPDI_END_MASKED
167-
#else
165+
#if _OPENMP < 202011
168166
OPDI_END_MASTER
167+
#else
168+
OPDI_END_MASKED
169169
#endif
170170
}
171171
OPDI_END_PARALLEL

tests/tests/TestMasked.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ struct TestMasked : public TestBase<4, 1, 3, TestMasked<_Case>> {
6161
out[0] += jobResults[i];
6262
}
6363
}
64-
#if _OPENMP >= 202011
65-
OPDI_END_MASKED
66-
#else
64+
#if _OPENMP < 202011
6765
OPDI_END_MASTER
66+
#else
67+
OPDI_END_MASKED
6868
#endif
6969
}
7070
OPDI_END_PARALLEL

tests/tests/TestParallelCopyin.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ struct TestParallelCopyin : public TestBase<4, 1, 3, TestParallelCopyin<_Case>>
6969
#if !defined(__GNUC__) || defined(__clang__)
7070
OPDI_PARALLEL(copyin(helper))
7171
#else
72+
// opdi-syntax-off
7273
OPDI_PARALLEL(firstprivate(helper))
74+
// opdi-syntax-on
7375
#endif
7476
{
7577
int nThreads = omp_get_num_threads();

tests/tests/TestSingleCopyprivateNowait.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ struct TestSingleCopyprivateNowait : public TestBase<4, 1, 3, TestSingleCopypriv
5656
#if _OPENMP >= 202411
5757
OPDI_SINGLE_COPYPRIVATE_NOWAIT(copyprivate(helper))
5858
#else
59+
// opdi-syntax-off
5960
OPDI_SINGLE_COPYPRIVATE(copyprivate(helper))
61+
// opdi-syntax-on
6062
#endif
6163
{
6264
for (int i = 0; i < N / 2; ++i) {

0 commit comments

Comments
 (0)