mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Fixed 39701 [Parser] Extended syntax for template instantiation is not supported (GCC, C++)
This commit is contained in:
parent
f1617823d5
commit
69c2f46f4b
7 changed files with 65 additions and 27 deletions
|
@ -87,18 +87,6 @@ public class ASTFailedTests extends BaseASTTest
|
||||||
assertCodeFailsParse("register int *foo asm (\"a5\");");
|
assertCodeFailsParse("register int *foo asm (\"a5\");");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug39701A() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("extern template int max (int, int);");
|
|
||||||
}
|
|
||||||
public void testBug39701B() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("inline template class Foo<int>;");
|
|
||||||
}
|
|
||||||
public void testBug39701C() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("static template class Foo<int>;");
|
|
||||||
}
|
|
||||||
public void testBug39702() throws Exception
|
public void testBug39702() throws Exception
|
||||||
{
|
{
|
||||||
Writer code = new StringWriter();
|
Writer code = new StringWriter();
|
||||||
|
|
|
@ -160,17 +160,4 @@ public class FailedCompleteParseASTTest extends CompleteParseBaseTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGNUExternalTemplate_bug71603() throws Exception {
|
|
||||||
try {
|
|
||||||
parse("template <typename T> \n class A {}; \n extern template class A<int>; \n"); //$NON-NLS-1$
|
|
||||||
fail();
|
|
||||||
} catch (ParserException e) {
|
|
||||||
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
// Iterator i = parse("template <typename T> \n class A {}; \n extern template class A<int>; \n").getDeclarations();
|
|
||||||
// IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next();
|
|
||||||
// IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration();
|
|
||||||
// IASTTemplateInstantiation ti = (IASTTemplateInstantiation) i.next();
|
|
||||||
// assertFalse(i.hasNext());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,12 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTUtil;
|
import org.eclipse.cdt.core.parser.ast.ASTUtil;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression;
|
import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression;
|
||||||
|
@ -235,4 +238,13 @@ public class GCCCompleteParseExtensionsTest extends CompleteParseBaseTest {
|
||||||
|
|
||||||
parse( writer.toString(), true, ParserLanguage.C );
|
parse( writer.toString(), true, ParserLanguage.C );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGNUExternalTemplate_bug71603() throws Exception {
|
||||||
|
Iterator i = parse("template <typename T> \n class A {}; \n extern template class A<int>; \n").getDeclarations(); //$NON-NLS-1$
|
||||||
|
IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next();
|
||||||
|
IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration();
|
||||||
|
IASTTemplateInstantiation ti = (IASTTemplateInstantiation) i.next();
|
||||||
|
assertFalse(i.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,4 +150,17 @@ public class GCCQuickParseExtensionsTest extends BaseASTTest {
|
||||||
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
||||||
writer.write( "z; }) zoot;\n" );//$NON-NLS-1$
|
writer.write( "z; }) zoot;\n" );//$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug39701A() throws Exception
|
||||||
|
{
|
||||||
|
parse("extern template int max (int, int);"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
public void testBug39701B() throws Exception
|
||||||
|
{
|
||||||
|
parse("inline template class Foo<int>;"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
public void testBug39701C() throws Exception
|
||||||
|
{
|
||||||
|
parse("static template class Foo<int>;"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,4 +76,8 @@ public interface IParserExtension {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Kind getExpressionKindForStatement();
|
public Kind getExpressionKindForStatement();
|
||||||
|
|
||||||
|
public boolean supportsExtendedTemplateInstantiationSyntax();
|
||||||
|
|
||||||
|
public boolean isValidModifierForInstantiation( IToken la );
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,4 +463,27 @@ public class GCCParserExtension implements IParserExtension {
|
||||||
return IASTGCCExpression.Kind.STATEMENT_EXPRESSION;
|
return IASTGCCExpression.Kind.STATEMENT_EXPRESSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.extension.IParserExtension#supportsExtendedTemplateInstantiationSyntax()
|
||||||
|
*/
|
||||||
|
public boolean supportsExtendedTemplateInstantiationSyntax() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.extension.IParserExtension#isValidModifierForInstantiation(org.eclipse.cdt.core.parser.IToken)
|
||||||
|
*/
|
||||||
|
public boolean isValidModifierForInstantiation(IToken la) {
|
||||||
|
if( la == null ) return false;
|
||||||
|
switch( la.getType() )
|
||||||
|
{
|
||||||
|
case IToken.t_static:
|
||||||
|
case IToken.t_inline:
|
||||||
|
case IToken.t_extern:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3346,7 +3346,15 @@ public class Parser implements IParserData, IParser
|
||||||
consume(IToken.t_template);
|
consume(IToken.t_template);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
firstToken = consume(IToken.t_template);
|
{
|
||||||
|
if( extension.supportsExtendedTemplateInstantiationSyntax() && extension.isValidModifierForInstantiation(LA(1)))
|
||||||
|
{
|
||||||
|
firstToken = consume(); // consume the modifier
|
||||||
|
consume( IToken.t_template );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
firstToken = consume(IToken.t_template);
|
||||||
|
}
|
||||||
if (LT(1) != IToken.tLT)
|
if (LT(1) != IToken.tLT)
|
||||||
{
|
{
|
||||||
// explicit-instantiation
|
// explicit-instantiation
|
||||||
|
@ -3721,7 +3729,10 @@ public class Parser implements IParserData, IParser
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default :
|
default :
|
||||||
resultDeclaration = simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind, overideKey);
|
if( extension.supportsExtendedTemplateInstantiationSyntax() && extension.isValidModifierForInstantiation(LA(1)) && LT(2) == IToken.t_template )
|
||||||
|
resultDeclaration = templateDeclaration(scope);
|
||||||
|
else
|
||||||
|
resultDeclaration = simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind, overideKey);
|
||||||
}
|
}
|
||||||
setCompletionValues(scope, kind, KeywordSetKey.DECLARATION );
|
setCompletionValues(scope, kind, KeywordSetKey.DECLARATION );
|
||||||
endDeclaration( resultDeclaration );
|
endDeclaration( resultDeclaration );
|
||||||
|
|
Loading…
Add table
Reference in a new issue