@@ -20,17 +20,19 @@ fun is_class_access(type_decl) =
2020@unit_check(help="prefixes in defining names", remediation="EASY",
2121 parametric_exemption=true,
2222 category="Style", subcategory="Readability")
23- fun identifier_prefixes(unit,
24- type="-",
25- concurrent="-",
26- access="-",
27- class_access="-",
28- subprogram_access="-",
29- derived=[],
30- constant="-",
31- exception="-",
32- enum="-",
33- exclusive=true) =
23+ fun identifier_prefixes(
24+ unit,
25+ type="-",
26+ concurrent="-",
27+ access="-",
28+ class_access="-",
29+ subprogram_access="-",
30+ derived=[],
31+ constant="-",
32+ exception="-",
33+ enum="-",
34+ exclusive=true
35+ ) =
3436 |" Flag each defining identifier that does not have a prefix corresponding
3537 |" to the kind of declaration it is defined by. The defining names in the
3638 |" following kinds of declarations are checked:
@@ -189,25 +191,32 @@ fun identifier_prefixes(unit,
189191 |" Exc_2 : exception; -- FLAG
190192 |" end Foo;
191193 {
192- fun check_exclusive(str,
193- type_exclusive=true, concurrent_exclusive=true,
194- access_exclusive=true, class_access_exclusive=true,
195- subprogram_access_exclusive=true,
196- constant_exclusive=true, exception_exclusive=true,
197- enum_exclusive=true) =
198- exclusive and
199- ((type_exclusive and str.starts_with(type)) or
200- (concurrent_exclusive and str.starts_with(concurrent)) or
201- (access_exclusive and str.starts_with(access)) or
202- (class_access_exclusive and str.starts_with(class_access)) or
203- (subprogram_access_exclusive and str.starts_with(subprogram_access)) or
204- (constant_exclusive and str.starts_with(constant)) or
205- (exception_exclusive and str.starts_with(exception)) or
206- (enum_exclusive and str.starts_with(enum)));
194+ fun check_exclusive(
195+ str,
196+ type_exclusive=true,
197+ concurrent_exclusive=true,
198+ access_exclusive=true,
199+ class_access_exclusive=true,
200+ subprogram_access_exclusive=true,
201+ constant_exclusive=true,
202+ exception_exclusive=true,
203+ enum_exclusive=true
204+ ) =
205+ exclusive
206+ and (
207+ (type_exclusive and str.starts_with(type))
208+ or (concurrent_exclusive and str.starts_with(concurrent))
209+ or (access_exclusive and str.starts_with(access))
210+ or (class_access_exclusive and str.starts_with(class_access))
211+ or (subprogram_access_exclusive and str.starts_with(subprogram_access))
212+ or (constant_exclusive and str.starts_with(constant))
213+ or (exception_exclusive and str.starts_with(exception))
214+ or (enum_exclusive and str.starts_with(enum))
215+ );
207216
208217 fun check_enum(str) =
209- (enum != "-" and not str.starts_with(enum)) or
210- check_exclusive(str, enum_exclusive=false);
218+ (enum != "-" and not str.starts_with(enum))
219+ or check_exclusive(str, enum_exclusive=false);
211220
212221 val str_prefix = " does not start with ";
213222
@@ -258,9 +267,10 @@ fun identifier_prefixes(unit,
258267 when p is not SingleTaskTypeDecl and concurrent != "-"
259268 =>
260269 p.p_previous_part() is (null | IncompleteTypeDecl) and
261- (if node.f_name.text.starts_with(concurrent)
262- then check_exclusive(node.f_name.text,
263- concurrent_exclusive=false))
270+ (
271+ if node.f_name.text.starts_with(concurrent)
272+ then check_exclusive(node.f_name.text, concurrent_exclusive=false)
273+ )
264274
265275 # 'Class access
266276 | (
@@ -270,71 +280,82 @@ fun identifier_prefixes(unit,
270280 )
271281 ) when class_access != "-"
272282 =>
273- p?.p_previous_part() is (null | IncompleteTypeDecl) and
274- (if node.f_name.text.starts_with(class_access)
275- then check_exclusive(node.f_name.text,
276- class_access_exclusive=false))
283+ p?.p_previous_part() is (null | IncompleteTypeDecl)
284+ and (
285+ if node.f_name.text.starts_with(class_access)
286+ then check_exclusive(node.f_name.text, class_access_exclusive=false)
287+ )
277288
278289 # Subprogram access
279- | (p@TypeDecl(f_type_def: AccessToSubpDef) |
280- p@SubtypeDecl(p_canonical_type():
281- TypeDecl(f_type_def: AccessToSubpDef)))
282- when subprogram_access != "-"
290+ | (
291+ p@TypeDecl(f_type_def: AccessToSubpDef)
292+ | p@SubtypeDecl(
293+ p_canonical_type(): TypeDecl(f_type_def: AccessToSubpDef)
294+ )
295+ ) when subprogram_access != "-"
283296 =>
284- p?.p_previous_part() is (null | IncompleteTypeDecl) and
285- (if node.f_name.text.starts_with(subprogram_access)
286- then check_exclusive(node.f_name.text,
287- subprogram_access_exclusive=false))
297+ p?.p_previous_part() is (null | IncompleteTypeDecl)
298+ and (
299+ if node.f_name.text.starts_with(subprogram_access)
300+ then check_exclusive(node.f_name.text, subprogram_access_exclusive=false)
301+ )
288302
289303 # Other access types
290- | (p@TypeDecl(f_type_def: AccessDef) |
291- p@SubtypeDecl(p_canonical_type(): TypeDecl(f_type_def: AccessDef)))
292- when access != "-"
304+ | (
305+ p@TypeDecl(f_type_def: AccessDef)
306+ | p@SubtypeDecl(p_canonical_type(): TypeDecl(f_type_def: AccessDef))
307+ ) when access != "-"
293308 =>
294- p?.p_previous_part() is (null | IncompleteTypeDecl) and
295- (if node.f_name.text.starts_with(access)
296- then check_exclusive(node.f_name.text,
297- access_exclusive=false,
298- # If both an Access prefix and a Type prefix are
299- # set and the type prefix is a prefix of the access
300- # prefix, we don't want to flag this access because
301- # it broke the exclusivity of the type prefix.
302- type_exclusive=false))
309+ p?.p_previous_part() is (null | IncompleteTypeDecl)
310+ and (
311+ if node.f_name.text.starts_with(access)
312+ then check_exclusive(
313+ node.f_name.text,
314+ access_exclusive=false,
315+ # If both an Access prefix and a Type prefix are
316+ # set and the type prefix is a prefix of the access
317+ # prefix, we don't want to flag this access because
318+ # it broke the exclusivity of the type prefix.
319+ type_exclusive=false
320+ )
321+ )
303322
304323 # (Sub)Types derived from `derived`
305324 | p@(TypeDecl(f_type_def: DerivedTypeDef) | SubtypeDecl)
306- when derived != [] and
307- p.p_canonical_type().p_base_type() is t@BaseTypeDecl
325+ when derived != []
326+ and p.p_canonical_type().p_base_type() is t@BaseTypeDecl
308327 when get_derived(t, derived) != ""
309328 => {
310- val t = p.p_canonical_type().p_base_type();
311- p.p_previous_part() is (null | IncompleteTypeDecl) and
312- not node.f_name.text.starts_with(get_derived(t, derived)
313- .split(":")[2])
314- }
329+ val t = p.p_canonical_type().p_base_type();
330+ p.p_previous_part() is (null | IncompleteTypeDecl)
331+ and not node.f_name.text.starts_with(
332+ get_derived(t, derived).split(":")[2]
333+ )
334+ }
315335
316336 # Exclude IncompleteTypeDecl
317337 | IncompleteTypeDecl => false
318338
319339 # Other types and subtypes
320340 | p@BaseTypeDecl when p is not SingleTaskTypeDecl =>
321- p.p_previous_part() is (null | IncompleteTypeDecl) and
322- ((type != "-" and not node.f_name.text.starts_with(type)) or
323- check_exclusive(node.f_name.text,
324- type_exclusive=false))
341+ p.p_previous_part() is (null | IncompleteTypeDecl)
342+ and (
343+ (type != "-" and not node.f_name.text.starts_with(type))
344+ or check_exclusive(node.f_name.text, type_exclusive=false)
345+ )
325346
326347 # Enums
327348 | EnumLiteralDecl => check_enum(node.f_name.text)
328349
329350 # Look one level up for remaining cases
330351 | p => match p.parent
331352 # Constants
332- | ((ObjectDecl(p_is_constant_object(): true) when not node.p_previous_part())
333- | NumberDecl )
334- =>
335- (constant != "-" and not node.f_name.text.starts_with(constant)) or
336- check_exclusive( node.f_name.text,
337- constant_exclusive=false)
353+ | (
354+ ObjectDecl(p_is_constant_object(): true) when not node.p_previous_part( )
355+ | NumberDecl
356+ ) =>
357+ (constant != "-" and not node.f_name.text.starts_with(constant))
358+ or check_exclusive(node.f_name.text, constant_exclusive=false)
338359
339360
340361 # Function renaming an enum literal
@@ -344,14 +365,17 @@ fun identifier_prefixes(unit,
344365
345366 # Exceptions
346367 | ExceptionDecl =>
347- (exception != "-" and not node.f_name.text.starts_with(exception)) or
348- check_exclusive(node.f_name.text,
349- exception_exclusive=false)
368+ (exception != "-" and not node.f_name.text.starts_with(exception))
369+ or check_exclusive(node.f_name.text, exception_exclusive=false)
350370
351371 # Check all other defining names for exclusion except for completions
352372 # and renaming-as-body
353373 | p2 =>
354- (if p2 is (BodyNode | SubpRenamingDecl) then not p2.p_previous_part()) and
355- (if p2 is ObjectDecl then not node.p_previous_part()) and
356- check_exclusive(node.f_name.text)]
374+ (
375+ if p2 is (BodyNode | SubpRenamingDecl)
376+ then not p2.p_previous_part()
377+ ) and (
378+ if p2 is ObjectDecl
379+ then not node.p_previous_part()
380+ ) and check_exclusive(node.f_name.text)]
357381 }
0 commit comments