SonarOpenCommunity / sonar-cxx

SonarQube C++ Community plugin (cxx plugin): This plugin adds C++ support to SonarQube with the focus on integration of existing C++ tools.
GNU Lesser General Public License v3.0
998 stars 365 forks source link

An argument called "final" generates a parsing error #410

Closed iwill80 closed 9 years ago

iwill80 commented 9 years ago

Hello, I'm using cxx plugin version 0.9.2 and I found a strange parsing error analyzing. After many attempts I found that the error was caused by an argument called "final". For example, if you have a C function declared as follow:

int foo(int final);

it will produce the following error:

14:12:03.079 ERROR - Unable to parse file: xxx com.sonar.sslr.api.RecognitionException: Parse error at line 715 column 8 failed to match all of: templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName operatorFunctionId literalOperatorId operatorFunctionId conversionFunctionId literalOperatorId ptrDeclarator templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName operatorFunctionId literalOperatorId operatorFunctionId conversionFunctionId literalOperatorId declarator functionDefinition templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName operatorFunctionId literalOperatorId operatorFunctionId conversionFunctionId literalOperatorId ptrDeclarator templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName templateName templateName enumName typedefName originalNamespaceName namespaceAlias decltypeSpecifier templateName operatorFunctionId literalOperatorId operatorFunctionId conversionFunctionId literalOperatorId declarator initDeclarator initDeclaratorList ... 714: --> int foo(int final); 716: ... Failed at rules: /-templateName /-simpleTemplateId | /-templateName | /-simpleTemplateId +-className +-enumName +-typedefName /-typeName | /-originalNamespaceName | +-namespaceAlias +-namespaceName +-decltypeSpecifier /-nestedNameSpecifier /-ptrOperator | /-templateName | /-simpleTemplateId | | /-templateName | | /-simpleTemplateId | +-className | +-enumName | +-typedefName | /-typeName | | /-originalNamespaceName | | +-namespaceAlias | +-namespaceName | +-decltypeSpecifier | /-nestedNameSpecifier | | /-templateName | | /-simpleTemplateId | +-className | | /-templateName | | /-simpleTemplateId | | | /-templateName | | | /-simpleTemplateId | | +-className | | +-enumName | | +-typedefName | | /-typeName | | | /-originalNamespaceName | | | +-namespaceAlias | | +-namespaceName | | +-decltypeSpecifier | | /-nestedNameSpecifier | | /-qualifiedId | | | /-templateName | | | /-simpleTemplateId | | | +-operatorFunctionId | | | +-literalOperatorId | | | /-templateId | | | +-operatorFunctionId | | | +-conversionFunctionId | | | +-literalOperatorId | | +-unqualifiedId | +-idExpression | /-declaratorId +-noptrDeclarator /-ptrDeclarator /-noptrDeclarator consumed from (715, 7) to (715, 8): ( /-ptrDeclarator +-ptrDeclarator consumed from (715, 7) to (715, 8): ( | /-templateName | /-simpleTemplateId | | /-templateName | | /-simpleTemplateId | +-className | +-enumName | +-typedefName | /-typeName | | /-originalNamespaceName | | +-namespaceAlias | +-namespaceName | +-decltypeSpecifier | /-nestedNameSpecifier | /-ptrOperator | | /-templateName | | /-simpleTemplateId | | | /-templateName | | | /-simpleTemplateId | | +-className | | +-enumName | | +-typedefName | | /-typeName | | | /-originalNamespaceName | | | +-namespaceAlias | | +-namespaceName | | +-decltypeSpecifier | | /-nestedNameSpecifier | | | /-templateName | | | /-simpleTemplateId | | +-className | | | /-templateName | | | /-simpleTemplateId | | | | /-templateName | | | | /-simpleTemplateId | | | +-className | | | +-enumName | | | +-typedefName | | | /-typeName | | | | /-originalNamespaceName | | | | +-namespaceAlias | | | +-namespaceName | | | +-decltypeSpecifier | | | /-nestedNameSpecifier | | | /-qualifiedId | | | | /-templateName | | | | /-simpleTemplateId | | | | +-operatorFunctionId | | | | +-literalOperatorId | | | | /-templateId | | | | +-operatorFunctionId | | | | +-conversionFunctionId | | | | +-literalOperatorId | | | +-unqualifiedId | | +-idExpression | | /-declaratorId | +-noptrDeclarator | /-ptrDeclarator +-noptrDeclarator consumed from (715, 7) to (715, 8): ( /-declarator +-declarator consumed from (715, 7) to (715, 8): ( /-functionDefinition consumed from (715, 0) to (715, 7): int foo +-functionDefinition consumed from (715, 0) to (715, 8): int foo ( | /-templateName | /-simpleTemplateId | | /-templateName | | /-simpleTemplateId | +-className | +-enumName | +-typedefName | /-typeName | | /-originalNamespaceName | | +-namespaceAlias | +-namespaceName | +-decltypeSpecifier | /-nestedNameSpecifier | /-ptrOperator | | /-templateName | | /-simpleTemplateId | | | /-templateName | | | /-simpleTemplateId | | +-className | | +-enumName | | +-typedefName | | /-typeName | | | /-originalNamespaceName | | | +-namespaceAlias | | +-namespaceName | | +-decltypeSpecifier | | /-nestedNameSpecifier | | | /-templateName | | | /-simpleTemplateId | | +-className | | | /-templateName | | | /-simpleTemplateId | | | | /-templateName | | | | /-simpleTemplateId | | | +-className | | | +-enumName | | | +-typedefName | | | /-typeName | | | | /-originalNamespaceName | | | | +-namespaceAlias | | | +-namespaceName | | | +-decltypeSpecifier | | | /-nestedNameSpecifier | | | /-qualifiedId | | | | /-templateName | | | | /-simpleTemplateId | | | | +-operatorFunctionId | | | | +-literalOperatorId | | | | /-templateId | | | | +-operatorFunctionId | | | | +-conversionFunctionId | | | | +-literalOperatorId | | | +-unqualifiedId | | +-idExpression | | /-declaratorId | +-noptrDeclarator | /-ptrDeclarator | /-noptrDeclarator consumed from (715, 7) to (715, 8): ( | /-ptrDeclarator | +-ptrDeclarator consumed from (715, 7) to (715, 8): ( | | /-templateName | | /-simpleTemplateId | | | /-templateName | | | /-simpleTemplateId | | +-className | | +-enumName | | +-typedefName | | /-typeName | | | /-originalNamespaceName | | | +-namespaceAlias | | +-namespaceName | | +-decltypeSpecifier | | /-nestedNameSpecifier | | /-ptrOperator | | | /-templateName | | | /-simpleTemplateId | | | | /-templateName | | | | /-simpleTemplateId | | | +-className | | | +-enumName | | | +-typedefName | | | /-typeName | | | | /-originalNamespaceName | | | | +-namespaceAlias | | | +-namespaceName | | | +-decltypeSpecifier | | | /-nestedNameSpecifier | | | | /-templateName | | | | /-simpleTemplateId | | | +-className | | | | /-templateName | | | | /-simpleTemplateId | | | | | /-templateName | | | | | /-simpleTemplateId | | | | +-className | | | | +-enumName | | | | +-typedefName | | | | /-typeName | | | | | /-originalNamespaceName | | | | | +-namespaceAlias | | | | +-namespaceName | | | | +-decltypeSpecifier | | | | /-nestedNameSpecifier | | | | /-qualifiedId | | | | | /-templateName | | | | | /-simpleTemplateId | | | | | +-operatorFunctionId | | | | | +-literalOperatorId | | | | | /-templateId | | | | | +-operatorFunctionId | | | | | +-conversionFunctionId | | | | | +-literalOperatorId | | | | +-unqualifiedId | | | +-idExpression | | | /-declaratorId | | +-noptrDeclarator | | /-ptrDeclarator | +-noptrDeclarator consumed from (715, 7) to (715, 8): ( | /-declarator | +-declarator consumed from (715, 7) to (715, 8): ( | /-initDeclarator | +-initDeclarator consumed from (715, 7) to (715, 8): ( | /-initDeclaratorList | +-initDeclaratorList consumed from (715, 7) to (715, 8): ( | /-simpleDeclaration consumed from (715, 0) to (715, 7): int foo +-blockDeclaration /-declaration declarationSeq consumed from (115, 0) to (713, 19): ... , hpn_timestamp_t * f , const char flag ) ; linkageSpecification consumed from (108, 3) to (108, 15): extern \"C\" { declaration translationUnit

at org.sonar.sslr.internal.vm.Machine.parse(Machine.java:86) ~[sslr-core-1.19.2.jar:na]
at com.sonar.sslr.impl.Parser.parse(Parser.java:87) ~[sslr-core-1.19.2.jar:na]
at com.sonar.sslr.impl.Parser.parse(Parser.java:72) ~[sslr-core-1.19.2.jar:na]
at com.sonar.sslr.squid.AstScanner.scanFiles(AstScanner.java:92) ~[sslr-squid-bridge-2.3.jar:na]
at org.sonar.plugins.cxx.squid.CxxSquidSensor.analyse(CxxSquidSensor.java:96) [sonar-cxx-plugin-0.9.1.jar:na]
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:119) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:194) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:233) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:228) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:221) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:125) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:173) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67) [sonar-batch-maven-compat-4.5.2.jar:na]
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48) [sonar-runner-batch7922701449330401015.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) [sonar-runner-dist-2.4.jar:na]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_20]
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.api.Runner.execute(Runner.java:100) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.executeTask(Main.java:70) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.execute(Main.java:59) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.main(Main.java:53) [sonar-runner-dist-2.4.jar:na]

If you just rename the argument into _final no error will be find.

guwirth commented 9 years ago

final is a C++ keyword: http://en.cppreference.com/w/cpp/language/final Parser/plugin is mainly a C++ parser.

See sonar.cxx.cFilesPatterns for more C compatibility.

iwill80 commented 9 years ago

Same issue configuring file patterns as follow:

sonar.cxx.cFilesPatterns=.c,.h

Il giorno 30/gen/2015, alle ore 15:44, "Günter Wirth" notifications@github.com ha scritto:

final is a C++ keyword: http://en.cppreference.com/w/cpp/language/final Parser/plugin is mainly a C++ parser.

See sonar.cxx.cFilesPatterns for more C compatibility.

— Reply to this email directly or view it on GitHub.

guwirth commented 9 years ago

Feature was added with #291. Looking to the sources keyword final is not supported by the solution.

https://github.com/wenns/sonar-cxx/blob/79894beea01bd829275c8c6e5502855bcf063cb1/cxx-squid/src/main/java/org/sonar/cxx/preprocessor/StandardDefinitions.java

public static Map<String, String> compatibilityMacros()