mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Victor Mozgin.
Here is the patch that should take care of parsing templated constructor/destructor/operator declarations.
This commit is contained in:
parent
239af2b4b6
commit
de2f7c52bc
5 changed files with 115 additions and 103 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2003-06-07 Victor Mozgin
|
||||||
|
Fixes for templated constructor/destructor/operator declarations.
|
||||||
|
This fixed PR 36766, 36767, 36769 (STL parsing problems).
|
||||||
|
|
||||||
2003-06-06 Victor Mozgin
|
2003-06-06 Victor Mozgin
|
||||||
Fixed Bug 38065 - Scanner skipped backslashes inside the code
|
Fixed Bug 38065 - Scanner skipped backslashes inside the code
|
||||||
|
|
||||||
|
|
|
@ -933,26 +933,40 @@ c, quickParse);
|
||||||
*/
|
*/
|
||||||
private boolean lookAheadForConstructor( Flags flags ) throws EndOfFile
|
private boolean lookAheadForConstructor( Flags flags ) throws EndOfFile
|
||||||
{
|
{
|
||||||
return (
|
if (flags.isForParameterDeclaration()) return false;
|
||||||
!flags.isForParameterDeclaration()
|
if (LT(2) == Token.tLPAREN && flags.isForConstructor()) return true;
|
||||||
) &&
|
|
||||||
(
|
int posTokenAfterTemplateParameters = 2;
|
||||||
(
|
|
||||||
(
|
if (LT(posTokenAfterTemplateParameters) == Token.tLT) {
|
||||||
LT(2) == Token.tCOLONCOLON &&
|
// a case for template constructor, like CFoobar<A,B>::CFoobar
|
||||||
(
|
|
||||||
LA(3).getImage().equals( LA(1).getImage() ) ||
|
posTokenAfterTemplateParameters++;
|
||||||
LT(3) == Token.tCOMPL
|
|
||||||
)
|
// until we get all the names sorted out
|
||||||
) ||
|
int depth = 1;
|
||||||
(
|
|
||||||
LT(2) == Token.tLPAREN &&
|
while (depth > 0) {
|
||||||
flags.isForConstructor()
|
switch (LT(posTokenAfterTemplateParameters++)) {
|
||||||
)
|
case Token.tGT :
|
||||||
)
|
--depth;
|
||||||
)
|
break;
|
||||||
;
|
case Token.tLT :
|
||||||
}
|
++depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
(LT(posTokenAfterTemplateParameters) == Token.tCOLONCOLON)
|
||||||
|
&&
|
||||||
|
(
|
||||||
|
LA(posTokenAfterTemplateParameters+1).getImage().equals( LA(1).getImage() ) ||
|
||||||
|
LT(posTokenAfterTemplateParameters+1) == Token.tCOMPL
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param flags input flags that are used to make our decision
|
* @param flags input flags that are used to make our decision
|
||||||
|
@ -1146,6 +1160,37 @@ c, quickParse);
|
||||||
} catch( Exception e ) {}
|
} catch( Exception e ) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consumes template parameters.
|
||||||
|
*
|
||||||
|
* @param previousLast Previous "last" token (returned if nothing was consumed)
|
||||||
|
* @return Last consumed token, or <code>previousLast</code> if nothing was consumed
|
||||||
|
* @throws Backtrack request a backtrack
|
||||||
|
*/
|
||||||
|
private Token consumeTemplateParameters(Token previousLast) throws Backtrack {
|
||||||
|
Token last = previousLast;
|
||||||
|
|
||||||
|
if (LT(1) == Token.tLT) {
|
||||||
|
last = consume(Token.tLT);
|
||||||
|
|
||||||
|
// until we get all the names sorted out
|
||||||
|
int depth = 1;
|
||||||
|
|
||||||
|
while (depth > 0) {
|
||||||
|
last = consume();
|
||||||
|
switch (last.getType()) {
|
||||||
|
case Token.tGT :
|
||||||
|
--depth;
|
||||||
|
break;
|
||||||
|
case Token.tLT :
|
||||||
|
++depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an identifier.
|
* Parse an identifier.
|
||||||
|
@ -1198,23 +1243,7 @@ c, quickParse);
|
||||||
*/
|
*/
|
||||||
protected Token templateId() throws Backtrack {
|
protected Token templateId() throws Backtrack {
|
||||||
Token first = consume( Token.tIDENTIFIER );
|
Token first = consume( Token.tIDENTIFIER );
|
||||||
consume( Token.tLT );
|
Token last = consumeTemplateParameters(first);
|
||||||
|
|
||||||
// until we get all the names sorted out
|
|
||||||
int depth = 1;
|
|
||||||
Token last = null;
|
|
||||||
|
|
||||||
while (depth > 0) {
|
|
||||||
last = consume();
|
|
||||||
switch ( last.getType()) {
|
|
||||||
case Token.tGT:
|
|
||||||
--depth;
|
|
||||||
break;
|
|
||||||
case Token.tLT:
|
|
||||||
++depth;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.nameBegin( first );
|
callback.nameBegin( first );
|
||||||
callback.nameEnd( last );
|
callback.nameEnd( last );
|
||||||
|
@ -1249,25 +1278,7 @@ c, quickParse);
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case Token.tIDENTIFIER:
|
case Token.tIDENTIFIER:
|
||||||
last = consume();
|
last = consume();
|
||||||
if( LT(1) == Token.tLT )
|
last = consumeTemplateParameters(last);
|
||||||
{
|
|
||||||
consume( Token.tLT );
|
|
||||||
|
|
||||||
// until we get all the names sorted out
|
|
||||||
int depth = 1;
|
|
||||||
|
|
||||||
while (depth > 0) {
|
|
||||||
last = consume();
|
|
||||||
switch ( last.getType()) {
|
|
||||||
case Token.tGT:
|
|
||||||
--depth;
|
|
||||||
break;
|
|
||||||
case Token.tLT:
|
|
||||||
++depth;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
backup( mark );
|
backup( mark );
|
||||||
|
@ -1289,26 +1300,7 @@ c, quickParse);
|
||||||
throw backtrack;
|
throw backtrack;
|
||||||
case Token.tIDENTIFIER:
|
case Token.tIDENTIFIER:
|
||||||
last = consume();
|
last = consume();
|
||||||
if( LT(1) == Token.tLT )
|
last = consumeTemplateParameters(last);
|
||||||
{
|
|
||||||
consume( Token.tLT );
|
|
||||||
|
|
||||||
// until we get all the names sorted out
|
|
||||||
int depth = 1;
|
|
||||||
|
|
||||||
while (depth > 0) {
|
|
||||||
last = consume();
|
|
||||||
switch ( last.getType()) {
|
|
||||||
case Token.tGT:
|
|
||||||
--depth;
|
|
||||||
break;
|
|
||||||
case Token.tLT:
|
|
||||||
++depth;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1515,13 +1507,16 @@ c, quickParse);
|
||||||
{
|
{
|
||||||
Token start = consume();
|
Token start = consume();
|
||||||
Token end = null;
|
Token end = null;
|
||||||
|
if (start.type == Token.tIDENTIFIER) end = consumeTemplateParameters(end);
|
||||||
while( LT(1) == Token.tCOLONCOLON || LT(1) == Token.tIDENTIFIER )
|
while( LT(1) == Token.tCOLONCOLON || LT(1) == Token.tIDENTIFIER )
|
||||||
{
|
{
|
||||||
end = consume();
|
end = consume();
|
||||||
|
if (end.type == Token.tIDENTIFIER) end = consumeTemplateParameters(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( LT(1) == Token.t_operator )
|
if( LT(1) == Token.t_operator )
|
||||||
{
|
{
|
||||||
|
consume();
|
||||||
if( LA(1).isOperator() || LT(1) == Token.tLPAREN || LT(1) == Token.tLBRACKET )
|
if( LA(1).isOperator() || LT(1) == Token.tLPAREN || LT(1) == Token.tLBRACKET )
|
||||||
{
|
{
|
||||||
if( (LT(1) == Token.t_new || LT(1) == Token.t_delete ) &&
|
if( (LT(1) == Token.t_new || LT(1) == Token.t_delete ) &&
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2003-06-07 Victor Mozgin
|
||||||
|
Moved testBug36766A(), testBug36766B() & testBug36766C() from STLFailedTests.java to DOMTests.java.
|
||||||
|
Renamed them to testBug36766and36769x(), as they cover both PRs.
|
||||||
|
Added testBug36766and36769D() - test for templated destructor.
|
||||||
|
|
||||||
2003-06-05 John Camelon
|
2003-06-05 John Camelon
|
||||||
Moved testBug23478A() & testBug23478B() from failed tests to TranslationUnitTests.java.
|
Moved testBug23478A() & testBug23478B() from failed tests to TranslationUnitTests.java.
|
||||||
Removed TranslationUnitFailedTests.java as it was empty.
|
Removed TranslationUnitFailedTests.java as it was empty.
|
||||||
|
|
|
@ -23,33 +23,6 @@ public class STLFailedTests extends BaseDOMTest {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug36766A() throws Exception {
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("template <class _CharT, class _Alloc>\n");
|
|
||||||
code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n");
|
|
||||||
code.write("const allocator_type& __a): _Base(__a)\n");
|
|
||||||
code.write("{}\n");
|
|
||||||
failTest(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug36766B() throws Exception {
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("template<class _CharT>\n");
|
|
||||||
code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n");
|
|
||||||
code.write("(const _CharT* __leaf, size_t __n)\n");
|
|
||||||
code.write("{}\n");
|
|
||||||
failTest(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug36766C() throws Exception {
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("template <class _CharT, class _Alloc>\n");
|
|
||||||
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n");
|
|
||||||
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n");
|
|
||||||
code.write("{}\n");
|
|
||||||
failTest(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug36805() throws Exception{
|
public void testBug36805() throws Exception{
|
||||||
Writer code = new StringWriter();
|
Writer code = new StringWriter();
|
||||||
code.write("__STL_BEGIN_NAMESPACE\n");
|
code.write("__STL_BEGIN_NAMESPACE\n");
|
||||||
|
|
|
@ -1783,5 +1783,40 @@ public class DOMTests extends BaseDOMTest {
|
||||||
parse("static const A a( 1, 0 );");
|
parse("static const A a( 1, 0 );");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug36766and36769A() throws Exception {
|
||||||
|
Writer code = new StringWriter();
|
||||||
|
code.write("template <class _CharT, class _Alloc>\n");
|
||||||
|
code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n");
|
||||||
|
code.write("const allocator_type& __a): _Base(__a)\n");
|
||||||
|
code.write("{}\n");
|
||||||
|
parse(code.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug36766and36769B() throws Exception {
|
||||||
|
Writer code = new StringWriter();
|
||||||
|
code.write("template<class _CharT>\n");
|
||||||
|
code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n");
|
||||||
|
code.write("(const _CharT* __leaf, size_t __n)\n");
|
||||||
|
code.write("{}\n");
|
||||||
|
parse(code.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug36766and36769C() throws Exception {
|
||||||
|
Writer code = new StringWriter();
|
||||||
|
code.write("template <class _CharT, class _Alloc>\n");
|
||||||
|
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n");
|
||||||
|
code.write(
|
||||||
|
"_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n");
|
||||||
|
code.write("{}\n");
|
||||||
|
parse(code.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug36766and36769D() throws Exception {
|
||||||
|
Writer code = new StringWriter();
|
||||||
|
code.write("template <class _CharT, class _Alloc>\n");
|
||||||
|
code.write("rope<_CharT, _Alloc>::~rope()\n");
|
||||||
|
code.write("{}\n");
|
||||||
|
parse(code.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue