Custom rule to be added to polyspace

12 次查看(过去 30 天)
Is it possible to have the following custom rule added to the polyspace code prover?
"Identifiers should consist of English language words, abbreviations or acronyms connected
with underscore characters. Variable identifiers should have the first letter of each word capitalized and each
letter of an acronym shall be uppercase as well. At least one letter of the function or variable name must be
lowercase. Functions identifiers may be either 1) all small case or 2) have the first letter of each word
capitalized. Whichever method is chosen it should apply to all newly defined function names."

回答(1 个)

Anirban
Anirban 2019-11-13
编辑:Anirban 2019-11-13
The Polyspace custom rules use regular expressions to detect patterns, so you can go as far as regular expressions can take you. For instance, you can create a rule that variable identifiers must have the first letter capitalized. See a similar tutorial here: https://www.mathworks.com/help/codeprover/ug/create-a-custom-coding-rules-file.html
Likewise, you can also enforce that a function name can consist of several parts separated by underscores only and each part must have the first letter capitalized. There are many sites such as https://regex101.com/ where you can build regular expressions on the fly and test your expressions.
However, some of the things you are asking will also require a dictionary that you can compare against. The dictionary should not only have English words but also acronyms (you might want to explicitly build the acronyms part of the dictionary). You cannot yet create such a dictionary with Polyspace and create a custom rule that compares against items from the dictionary.

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by