Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -961,34 +961,30 @@ private static void declarations(LexerfulGrammarBuilder b) {
b.sequence(CxxKeyword.ALIGNAS, "(", assignmentExpression, b.optional("..."), ")")
));

b.rule(attributeList).is(
b.firstOf(
b.sequence(attribute, "...", b.zeroOrMore(",", attribute, "...")),
b.sequence(b.optional(attribute), b.zeroOrMore(",", b.optional(attribute)))
));
b.rule(attributeList).is(b.optional(attribute), b.zeroOrMore(",", attribute));

b.rule(attribute).is(attributeToken, b.optional(attributeArgumentClause));

b.rule(attributeToken).is(
b.firstOf(
attributeScopedToken,
IDENTIFIER
IDENTIFIER,
attributeScopedToken
));

b.rule(attributeScopedToken).is(attributeNamespace, "::", IDENTIFIER);

b.rule(attributeNamespace).is(IDENTIFIER);

b.rule(attributeArgumentClause).is("(", balancedTokenSeq, ")");
b.rule(attributeArgumentClause).is(balancedTokenSeq);

b.rule(balancedTokenSeq).is(b.zeroOrMore(balancedToken));

b.rule(balancedToken).is(
b.firstOf(
IDENTIFIER,
b.sequence("(", balancedTokenSeq, ")"),
b.sequence("{", balancedTokenSeq, "}"),
b.sequence("[", balancedTokenSeq, "]")
b.sequence("[", balancedTokenSeq, "]"),
b.oneOrMore(b.nextNot(b.firstOf("(", ")", "{", "}", "[", "]", EOF)), b.anyToken())
));
}

Expand Down Expand Up @@ -1200,7 +1196,7 @@ private static void classes(LexerfulGrammarBuilder b) {

b.rule(classHead).is(
b.firstOf(
b.sequence(b.optional(cliTopLevelVisibility), b.optional(vcAtlAttribute), classKey, b.optional(attributeSpecifierSeq), classHeadName, b.optional(classVirtSpecifier), b.optional(baseClause)),
b.sequence(b.optional(cliTopLevelVisibility), b.optional(vcAtlAttribute), classKey, b.optional(attributeSpecifierSeq), classHeadName, b.optional(classVirtSpecifier), b.optional(baseClause), b.optional(attributeSpecifierSeq)),
b.sequence(b.optional(cliTopLevelVisibility), b.optional(vcAtlAttribute), classKey, b.optional(attributeSpecifierSeq), b.optional(baseClause))
)
);
Expand Down
52 changes: 52 additions & 0 deletions cxx-squid/src/test/java/org/sonar/cxx/parser/AttributeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Sonar C++ Plugin (Community)
* Copyright (C) 2011 Waleri Enns and CONTACT Software GmbH
* dev@sonar.codehaus.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.cxx.parser;

import static org.sonar.sslr.tests.Assertions.assertThat;

import org.junit.Test;

public class AttributeTest extends ParserBaseTest {

@Test
public void classSpecifier_reallife() {
p.setRootRule(g.rule(CxxGrammarImpl.attributeSpecifierSeq));

assertThat(p).matches("[[attr]]");
assertThat(p).matches("[[attr(a)]]");
assertThat(p).matches("[[attr(\"text\")]]");
assertThat(p).matches("[[attr(true)]]");
assertThat(p).matches("[[attr(int)]]");
assertThat(p).matches("[[attr(a, b, c)]]");
assertThat(p).matches("[[nmspc::attr]]");
assertThat(p).matches("[[nmspc::attr(args)]]");
assertThat(p).matches("[[attr1, attr2, attr3(args)]]");
assertThat(p).matches("[[db::id, db::auto, db::type(\"INT\")]]");
assertThat(p).matches("[[omp::parallel(clause,clause)]]");

assertThat(p).matches("[[noreturn]]");
assertThat(p).matches("[[carries_dependency]]");
assertThat(p).matches("[[deprecated]]");
assertThat(p).matches("[[deprecated(\"reason\")]]");

assertThat(p).matches("[[attr1]] [[attr2]] [[attr3]]");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ public void attributeList() {
.matches("")
.matches("attribute")
.matches("attribute , attribute")
.matches("attribute , ")
.matches("attribute , attribute , attribute")
.matches("attribute ...")
.matches("attribute ... , attribute ...");
.matches("attribute , attribute , attribute");
}

@Test
Expand Down Expand Up @@ -129,15 +126,6 @@ public void attributeToken() {
.matches("attributeScopedToken");
}

@Test
public void attributeTokenXXXX() {
p.setRootRule(g.rule(CxxGrammarImpl.attributeToken));

assertThat(p)
.matches("foo")
.matches("foo :: bar");
}

@Test
public void attributeScopedToken() {
p.setRootRule(g.rule(CxxGrammarImpl.attributeScopedToken));
Expand Down Expand Up @@ -165,7 +153,7 @@ public void attributeArgumentClause() {
p.setRootRule(g.rule(CxxGrammarImpl.attributeArgumentClause));
g.rule(CxxGrammarImpl.balancedTokenSeq).mock();

assertThat(p).matches("( balancedTokenSeq )");
assertThat(p).matches("balancedTokenSeq");
}

public void attributeArgumentClauseXXXX() {
Expand Down
22 changes: 10 additions & 12 deletions cxx-squid/src/test/resources/parser/own/C++11/attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ int [[attr4]] a [10] [[attr5]];

[[attr1]] void [[attr2]] func(int [[attr3]] p) [[attr4]]
{
//@todo
// [[attr4(arg1, arg2)]] if (cond)
// {
// [[vendor::attr5]] return i;
// }
[[attr4(arg1, arg2)]] if (cond)
{
[[vendor::attr5]] return i;
}
}

//@todo
//[[attr1]] class C [[attr2]]
//{
//
// C::C [[attr6]] () [[attr7]];
//
//} [[attr3]] c [[attr4]], d [[attr5]];
[[attr1]] class C [[attr2]]
{

C::C [[attr6]] () [[attr7]];

} [[attr3]] c [[attr4]], d [[attr5]];
// attr1 applies to declarator-ids c, d
// attr2 applies to the definition of class C
// attr3 applies to type C
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[[deprecated]] int f();

//@todo
//[[deprecated("g() is thread-unsafe. Use h() instead")]]
//void g( int& x );
[[deprecated("g() is thread-unsafe. Use h() instead")]]
void g( int& x );

void h( int& x );

Expand Down