1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-22 16:35:25 +02:00

Patch for Victor Mozgin.

This patch enables parsing of conversion operators. Fixes PR 38657 and the rest of PR 36769.
This commit is contained in:
John Camelon 2003-06-10 14:41:42 +00:00
parent 1aae7b2fa4
commit d4a1629964
7 changed files with 103 additions and 71 deletions

View file

@ -43,7 +43,8 @@ public class Name {
while (t != nameEnd) {
t = t.getNext();
buffer.append( t.getImage() );
buffer.append( t.getImage() );
if (t.getType() == Token.t_operator) buffer.append( " " );
}
return buffer.toString();

View file

@ -1,3 +1,7 @@
2003-06-09 Victor Mozgin
Fixed for conversion operator declarations.
This fixes PR 36769 (finally) and PR 38657.
2003-06-09 Victor Mozgin
Fixed Bug 36932 - RTS: Parser fails on "new" in ctor initializer
Improved handling of new-expressions: placements, arrays and

View file

@ -927,11 +927,11 @@ c, quickParse);
}
/**
* @param flags input flags that are used to make our decision
* @return whether or not this looks like a constructor (true or false)
* @throws EndOfFile we could encounter EOF while looking ahead
* @param flags input flags that are used to make our decision
* @return whether or not this looks like a constructor (true or false)
* @throws EndOfFile we could encounter EOF while looking ahead
*/
private boolean lookAheadForConstructor( Flags flags ) throws EndOfFile
private boolean lookAheadForConstructorOrConversion( Flags flags ) throws EndOfFile
{
if (flags.isForParameterDeclaration()) return false;
if (LT(2) == Token.tLPAREN && flags.isForConstructor()) return true;
@ -958,14 +958,27 @@ c, quickParse);
}
}
return
(LT(posTokenAfterTemplateParameters) == Token.tCOLONCOLON)
&&
(
LA(posTokenAfterTemplateParameters+1).getImage().equals( LA(1).getImage() ) ||
LT(posTokenAfterTemplateParameters+1) == Token.tCOMPL
)
;
// for constructors
return
(
(
(LT(posTokenAfterTemplateParameters) == Token.tCOLONCOLON)
&&
(
LA(posTokenAfterTemplateParameters+1).getImage().equals( LA(1).getImage() ) ||
LT(posTokenAfterTemplateParameters+1) == Token.tCOMPL
)
)
||
(
// for conversion operators
(LT(posTokenAfterTemplateParameters) == Token.tCOLONCOLON)
&&
(
LT(posTokenAfterTemplateParameters+1) == Token.t_operator
)
)
);
}
/**
@ -1080,7 +1093,7 @@ c, quickParse);
return;
if( parm && flags.haveEncounteredTypename() )
return;
if ( lookAheadForConstructor( flags ) )
if ( lookAheadForConstructorOrConversion( flags ) )
return;
if ( lookAheadForDeclarator( flags ) )
return;
@ -1480,11 +1493,18 @@ c, quickParse);
}
else
{
// temporary
while( LT(1) != Token.tLPAREN )
{
toSend = consume();
}
// must be a conversion function
typeId();
toSend = lastToken;
try {
// this ptrOp doesn't belong to the declarator,
// it's just a part of the name
ptrOperator(null);
toSend = lastToken;
} catch (Backtrack b) {}
// In case we'll need better error recovery
// while( LT(1) != Token.tLPAREN ) { toSend = consume(); }
}
try{
@ -1545,13 +1565,20 @@ c, quickParse);
}
else
{
// temporary
while( LT(1) != Token.tLPAREN )
{
end = consume();
}
}
{
// must be a conversion function
typeId();
end = lastToken;
try {
// this ptrOp doesn't belong to the declarator,
// it's just a part of the name
ptrOperator(null);
end = lastToken;
} catch (Backtrack b) {}
// In case we'll need better error recovery
// while( LT(1) != Token.tLPAREN ) { toSend = consume(); }
}
try{
callback.nameBegin( start );

View file

@ -1,3 +1,8 @@
2003-06-09 Victor Mozgin
Moved testBug36769() from ACEFailedTest.java to DOMTests.java.
Removed ACEFailedTest.java as it is empty now.
Added DOMTests.testBug36769B().
2003-06-09 Victor Mozgin
Moved testBug36932() from DOMFailedTest.java to DOMTests.java.
Added DOMTests.testBug36932B() and DOMTests.testBug36932C().

View file

@ -1,42 +0,0 @@
/*******************************************************************************
* Copyright (c) 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.core.parser.failedTests;
import java.io.StringWriter;
import java.io.Writer;
import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class ACEFailedTest extends BaseDOMTest {
/**
* @param arg
*/
public ACEFailedTest(String arg) {
super(arg);
}
public void testBug36769() throws Exception {
Writer code = new StringWriter();
code.write("template <class A, B> cls<A, C>::operator op &() const {}\n");
code.write("template <class A, B> cls<A, C>::cls() {}\n");
code.write("template <class A, B> cls<A, C>::~cls() {}\n");
failTest( code.toString());
}
}

View file

@ -1178,7 +1178,7 @@ public class DOMTests extends BaseDOMTest {
PointerOperator po = (PointerOperator)functionDeclarator.getPointerOperators().get(0);
assertEquals( po.getType(), PointerOperator.t_reference );
assertFalse( po.isConst() || po.isVolatile() );
assertEquals( functionDeclarator.getName().toString(), "A::operator=");
assertEquals( functionDeclarator.getName().toString(), "A::operator =");
assertEquals( functionDeclarator.getParms().getDeclarations().size(), 1 );
ParameterDeclaration parameterDeclaration = (ParameterDeclaration)functionDeclarator.getParms().getDeclarations().get(0);
assertEquals( parameterDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_type );
@ -2042,5 +2042,43 @@ public class DOMTests extends BaseDOMTest {
parse("X::X( ) : var( new (P) (A)[B] ) {}");
parse("X::X( ) : var( new (P) (A)[B][C][D] ) {}");
}
}
public void testBug36769A() throws Exception {
Writer code = new StringWriter();
code.write("template <class A, B> cls<A, C>::operator op &() const {}\n");
code.write("template <class A, B> cls<A, C>::cls() {}\n");
code.write("template <class A, B> cls<A, C>::~cls() {}\n");
parse( code.toString());
}
public void testBug36769B() throws Exception {
parse("class X { operator int(); } \n");
parse("class X { operator int*(); } \n");
parse("class X { operator int&(); } \n");
parse("class X { operator A(); } \n");
parse("class X { operator A*(); } \n");
parse("class X { operator A&(); } \n");
parse("X::operator int() { } \n");
parse("X::operator int*() { } \n");
parse("X::operator int&() { } \n");
parse("X::operator A() { } \n");
parse("X::operator A*() { } \n");
parse("X::operator A&() { } \n");
parse("template <class A,B> class X<A,C> { operator int(); } \n");
parse("template <class A,B> class X<A,C> { operator int*(); } \n");
parse("template <class A,B> class X<A,C> { operator int&(); } \n");
parse("template <class A,B> class X<A,C> { operator A(); } \n");
parse("template <class A,B> class X<A,C> { operator A*(); } \n");
parse("template <class A,B> class X<A,C> { operator A&(); } \n");
parse("template <class A,B> X<A,C>::operator int() { } \n");
parse("template <class A,B> X<A,C>::operator int*() { } \n");
parse("template <class A,B> X<A,C>::operator int&() { } \n");
parse("template <class A,B> X<A,C>::operator A() { } \n");
parse("template <class A,B> X<A,C>::operator A*() { } \n");
parse("template <class A,B> X<A,C>::operator A&() { } \n");
}
}

View file

@ -77,7 +77,6 @@ public class AutomatedIntegrationSuite extends TestSuite implements TestListener
suite.addTest(suite.new GenerateReport("testStartFailedTests"));
// Add all failed tests
suite.addTestSuite(ACEFailedTest.class);
suite.addTestSuite(DOMFailedTest.class);
suite.addTestSuite(LokiFailures.class);
suite.addTestSuite(STLFailedTests.class);