Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000773Taste[All Projects] ASN.1 Compiler v4public2018-05-16 07:582018-07-05 08:35
Reportermaxime 
Assigned Togmamais 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusclosedResolutionfixed 
PlatformOSOS Version
Summary0000773:

Renaming policy - forbidden keywords in fields and same field name/type name

Description

In the following to cases:

  • use of a forbidden keyword as field name
  • naming of a field name the same as a type name

I propose to apply a renaming policy to the field names instead of emitting an error.
The prefixed name should be reflected in the Python/XML backends

The objective is to allow these kind of types:

MySeq ::= SEQUENCE {
    main    Main-Cmd,    --  main is a C keyword
    package Package-Cmd  --  package is an Ada keyword
    address Address      --  common pattern in OO programming
}

in that example, the fields could be renamed "MySeq_main" (in C) and "MySeq_address" (in Ada), as it is done when renaming conflicting enumerant.

TagsNo tags attached.
Attached Files

- Relationships
related to 0000411feedbackgmamais 

Improve rename policy for enumerants

 
child of 0000771closedmaxime 

New "forbidden" words break older projects

 

-  Notes
(0003356)
maxime (administrator)
2018-06-11 07:44
edited on: 2018-07-05 08:47

I also suggest to print on the console what the renaming policy is doing, by displaying info messages such as:

[INFO] Renamed field "main" in type "MySeq" to "MySeq_open" ("main" is a C keyword)
[INFO] Renamed field "address" in type "MySeq" to "MySeq_address" (Ada naming conflict with the field type "Address")
(0003357)
maxime (administrator)
2018-06-11 08:54

However, since this would break a lot of code, I think there must be a command line to let the user control what he wants:

--fieldPrefix auto|prefix=user_defined_string

auto: use same policy set for enumerants
prefix=string : let the user define his own prefix for all fields of SEQ/CHOICE

(0003358)
gmamais (developer)
2018-06-12 06:09

I had started the implementation of this mantis but without taking into account the the last two notes.
The current implemantation, which is commited in github, implements the auto functionality when you spefify renamePolicy 1 or renamePolicy 2.
Anyway, I will modify the current implementation to comply with the last two notes.

I have some questions though:
1) auto: use same policy set for enumerants

In your example, the 'address' name conflicts with the 'Address' type. However, this a problem only in Ada not in C.
Do you want the renaming of the address field to take place in both languages or only in Ada?
In my current implementation, I have a seperate field for c and ada (i.e. c_name and ada_name) and so I change the field only for the conflicing language.

2) prefix=string : let the user define his own prefix for all fields of SEQ/CHOICE

I assume that in this case, all sequence/choice children will be prefixed with this value, not only the conflicting ones. Right?
Will this prefix affect the ACN inserted fields?

3)Would you like the c_name / ada_name to be exported in the custom STGs backends?

(0003371)
maxime (administrator)
2018-06-13 14:21

1) Only in Ada

2) yes, all choice/children unconditionally

The ACN inserted fields are never made visible to the user, so internally you may or may not add the prefix. In the ICDs, there should be no prefix.

3) yes, I think it's needed, same as EnumValue (I believe) for conflicting enumerants

thanks!

(0003375)
gmamais (developer)
2018-06-13 18:43
edited on: 2018-06-16 15:20

One more question:
Suppose the following grammar

MySeq ::= SEQUENCE {
   field1  INTEGER,    -- this is OK
   address Address     -- this will conflict in Ada
}

How would you expect the generated Ada code in auto mode?
Option 1: only the affected fields are prefixed. In this case, the generated code would be as the user had defined the SEQUENCE as follows

MySeq ::= SEQUENCE {
   field1  INTEGER,
   MySeq_address Address     -- only this field is prefixed
}

Option 2: all fields are prefixed. In this case, the generated code would be as

MySeq ::= SEQUENCE {
   MySeq_field1  INTEGER     -- all fields are prefixed with
   MySeq_address Address     -- the type name
}

Option 3: Use the value of -renamePolicy used in Enums and hence let the user choose between option 1 or 2. Although, I believe this option may cause confusion.

(0003376)
maxime (administrator)
2018-06-13 18:51

I would expect option 1. The renaming has to be kept local, so that if the user later changes this field, the other existing fields are not all impacted/broken.

(0003377)
gmamais (developer)
2018-06-14 19:02

fixed in the latest GitHub commit as specified.
The new argument is -fp.
If you pass -fp AUTO it does automatic renaming in the conflicting component/alternative names.
if you pass -fp myFieldPrefix_ it adds myFieldPrefix_ to all component/alternative names in the grammar.

See test case
v4Tests/test-cases/acn/16-mantis/01-keywords.asn1

(0003378)
maxime (administrator)
2018-06-16 14:49

Thanks!

Please note that in the command line help, you miss the keyword ENUMERATED here:

RGB ::= ENUMERATED {red, green, blue} 
FavColors = {red, yellow}    <- Here, should be FavColors ::= ENUMERATED ...
(0003379)
maxime (administrator)
2018-06-16 15:19

I updated xml.stg and python.stg to use sCName and sAdaName in the generated custom STGs

(0003380)
maxime (administrator)
2018-06-16 15:22

I have tried using the name "open" for a field, however it does not get renamed - I think reserved keywords should be renamed - depending on the language -> sCName should be impacted, but not sAdaName

(0003381)
gmamais (developer)
2018-06-16 17:01

open is not a C or Ada keyword and that is why is not renamed.

The list of keywords per language are
let c_keyworkds = [ "auto"; "break"; "case"; "char"; "const"; "continue"; "default"; "do"; "double"; "else"; "enum"; "extern"; "float"; "for"; "goto"; "if"; "int"; "long"; "register"; "return"; "short"; "signed"; "sizeof"; "static"; "struct"; "switch"; "typedef"; "union"; "unsigned"; "void"; "volatile"; "while"; ]

let ada_keyworkds = [ "abort"; "else"; "new"; "return"; "abs"; "elsif"; "not"; "reverse"; "abstract"; "end"; "null"; "accept"; "entry"; "select"; "access"; "exception"; "of"; "separate"; "aliased"; "exit"; "or"; "some"; "all"; "others"; "subtype"; "and"; "for"; "out"; "synchronized"; "array"; "function"; "overriding"; "at"; "tagged"; "generic"; "package"; "task"; "begin"; "goto"; "pragma"; "terminate"; "body"; "private"; "then"; "if"; "procedure"; "type"; "case"; "in"; "protected"; "constant"; "interface"; "until"; "is"; "raise"; "use"; "declare"; "range"; "delay"; "limited"; "record"; "when"; "delta"; "loop"; "rem"; "while"; "digits"; "renames"; "with"; "do"; "mod"; "requeue"; "xor" ]

Regarding the type typo in help message, I will fix it in the next commit.

(0003382)
gmamais (developer)
2018-06-16 17:07

typo fixed.

(0003383)
maxime (administrator)
2018-06-16 18:24

Thanks! I think we are all good now (indeed, you are right about "open" - sorry for the confusion).

Closing!!

We'll now need to update the B mappers (to use the new CName/AdaName) and Opengeode code generator.


- Issue History
Date Modified Username Field Change
2018-05-16 07:58 maxime New Issue
2018-05-16 07:58 maxime Status

new => assigned

2018-05-16 07:58 maxime Assigned To

=> gmamais

2018-05-16 07:58 maxime Relationship added

child of 0000771

2018-06-11 07:44 maxime Note Added: 0003356
2018-06-11 08:54 maxime Note Added: 0003357
2018-06-12 06:09 gmamais Note Added: 0003358
2018-06-12 18:06 gmamais Status

assigned => feedback

2018-06-13 14:21 maxime Note Added: 0003371
2018-06-13 14:21 maxime Status

feedback => assigned

2018-06-13 18:43 gmamais Note Added: 0003375
2018-06-13 18:51 maxime Note Added: 0003376
2018-06-14 19:02 gmamais Note Added: 0003377
2018-06-14 19:02 gmamais Status

assigned => resolved

2018-06-14 19:02 gmamais Resolution

open => fixed

2018-06-16 14:49 maxime Note Added: 0003378
2018-06-16 15:19 maxime Note Added: 0003379
2018-06-16 15:20 maxime Note Edited: 0003375 View Revisions
2018-06-16 15:22 maxime Note Added: 0003380
2018-06-16 17:01 gmamais Note Added: 0003381
2018-06-16 17:01 gmamais Status

resolved => new

2018-06-16 17:07 gmamais Note Added: 0003382
2018-06-16 17:07 gmamais Status

new => resolved

2018-06-16 18:24 maxime Note Added: 0003383
2018-06-16 18:24 maxime Status

resolved => closed

2018-06-16 18:26 maxime Description Updated View Revisions
2018-06-16 18:27 maxime Description Updated View Revisions
2018-07-05 08:35 maxime Relationship added

related to 0000411

2018-07-05 08:47 maxime Note Edited: 0003356 View Revisions


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker