MATLAB Answers

Custom rule to be added to polyspace

Kavya Sathyavelu 님이 질문을 제출함. 12 Nov 2019
최근 활동 Anirban 님이 편집함. 13 Nov 2019
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."

  댓글 수: 0

로그인 to comment.

제품


릴리스

R2019b

답변 수: 1

Anirban 님의 답변 13 Nov 2019
Anirban 님이 편집함. 13 Nov 2019

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.

  댓글 수: 0

로그인 to comment.



Translated by