Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Codan develoepement, new checker
  • From: Nathan Ridge <zeratul976@xxxxxxxxxxx>
  • Date: Thu, 24 Oct 2019 22:01:07 +0000
  • Accept-language: en-CA, en-US
  • Arc-authentication-results: i=1; 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed;; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NlNXeHxFCX+YIglxSt1p+PA+GX0KZRwr9Va9zTWuwYM=; b=eLoBpu+IzEnV6cKGbU5H/Wzola4o/ZAk6TehNLNvGJ59sfepYjBoRHzlxKYTGOf3yKp56QJVAxysGUI97wwUYTv+HqO3F2PND+tODSwzXnGmVFKJQ30wMVY0D/9UillbKEsn0yIyB9e4nTemp16KNtpzgTKliyizdsz4afm16qsH1B8humjHCnoekzC+AgqwrKuc9I00vwERIYzOCBuk1eZgBkwEhXWl0njt3hFa3MP9UO+6dDCYB/Rbjr7VH4hsyjxoYVPww5rz1STBKg5rkvU5sskdrZVYMxx0WIEvPBKvnwMUu6Re9n7ZEuEL9Y8jvc0iTH0A2ZHF/quq4+XOuQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901;; cv=none; b=EhncGkgBBHDLVg/RVg1pUWelNRcQYVTNtpVnD+HY/o64x4Takhz1ij3UYI8rYggXAvwHoDotoya6Qu9INNoDwHL0NEsqq699pcvJQIttZjc0e70G3DEV49wxG4L0xzLzd4lpko5mMuHr7zXIapyWv+AEzia2rr/YVSSm7wdm99MSV0eyXaIAlhz7fju5Ez1jABL1a4ATtLu/tu0FjgRgvogM/Rhk6bXaLAUjBf8cfb8r+HuYNg9mpthkwhEocdncuq0F26jsTfIjBVze/aY5miDooSBOH9ma1fIVnkNP9qDFWzh1pBawCwEbtet9BgkirlX9X4TAX8jUK1hBE/CNfA==
  • Delivered-to: cdt-dev@xxxxxxxxxxx
  • List-archive: <>
  • List-help: <>
  • List-subscribe: <>, <>
  • List-unsubscribe: <>, <>
  • Thread-index: AQHVd2GDwD0PC6dgSUqy3AmCaTRn7KdD1lGAgAUF9QCAABJeAIACS5cAgAo2JgCAAIiXgIAUf1s1gAAFqFE=
  • Thread-topic: [cdt-dev] Codan develoepement, new checker

Macros can be visited by calling dedicated methods on IASTTranslationUnit, such as getMacroDefinitions() or getAllPreprocessorStatements().

Since macro definitions cannot be nested the way regular declarations can, there is no need for a recursive traversal mechanism like ASTVisitor.

Hope that helps,

From: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> on behalf of Alena Laskavaia <elaskavaia.cdt@xxxxxxxxx>
Sent: October 24, 2019 9:38 PM
To: Viktor Csoma; CDT General developers list.
Subject: Re: [cdt-dev] Codan develoepement, new checker

Do you actually want to visit preprocessor directives or you want to visit constants?
Because people can write code like this too

const int FOO=0x0abc;

If you visit actual constants you can cover both inline usage and macro usage (just reporting will be tricky)

For the macros it be tricky because they not part of AST they part of their own macro structures, not sure visitors are called on them. Maybe search of other checkers use that.

On Thu, Oct 24, 2019 at 12:19 PM Viktor Csoma <gusztav1906@xxxxxxxxx<mailto:gusztav1906@xxxxxxxxx>> wrote:
Thank for your answer,
I checked the topics you mentioned and also understood (to some extent) the implementation code of the "NamingConventionFunctionChecker" checker, which I believe I should modify slightly to check the syntax of object-style macros (e.g. " #define MacroName 0x0AFF ").
I also checked the ASTVisitor pattern and by this point I think I need to write a visit method for IASTPreprocessorMacroDefinition (instead of IASTDeclaration in"NamingConventionFunctionChecker") and check for instanceof IASTPreprocessorObjectStyleMacroDefinition (instead of IASTFunctionDefinition).
I tried to run the plugin including my new checker in debug mode and the problem is that whatever I do,  this visit function never gets called. (I also observed the NamingConventionFunctionChecker in Debug mode to see how it is working).
Is it possible to visit preprocessor macros with the ASTVisitor pattern? Is there any example checker that implements similar functionality?
Thank you very much,

Alena Laskavaia <elaskavaia.cdt@xxxxxxxxx<mailto:elaskavaia.cdt@xxxxxxxxx>> ezt írta (időpont: 2019. okt. 11., P, 22:39):
This is very abstract question. Are you asking how to write checker or how to program on Java?
For checker to know what to do you need exact description. In your example its pretty trivial, you can hook ast visitor on the constant/literal node (you have to know what AST is)
check if this is this is hex one then do some string manipulations to to determine if lowcases is used.

On Fri, Oct 11, 2019 at 8:30 AM Viktor Csoma <gusztav1906@xxxxxxxxx<mailto:gusztav1906@xxxxxxxxx>> wrote:
Thank you all for your  help. I managed to add a checker and a problem to org.eclipse.cdt.codan.checkers and launch an Eclipse where I could set whether I wanted to check for a certain syntax error or not. To do that I only copied the Naming Convention Function Checker to my own checker Java function (it threw two errors if both of them were enabled). My next step would be to implement some simple syntax checkers  e.g. if a hexadecimal is used in a given format (i.e lower case x, uppercase letters). Unfortunately I have never implemented such a thing in Java, therefore I would like to ask for a guide or any material that would help me understand the code or the methodology (even some keywords would do).
Thank you very much.
Best regards,

cdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
cdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top