1
0
Fork 0
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:
John Camelon 2003-06-09 18:21:28 +00:00
parent 239af2b4b6
commit de2f7c52bc
5 changed files with 115 additions and 103 deletions

View file

@ -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
Fixed Bug 38065 - Scanner skipped backslashes inside the code

View file

@ -933,23 +933,37 @@ c, quickParse);
*/
private boolean lookAheadForConstructor( Flags flags ) throws EndOfFile
{
return (
!flags.isForParameterDeclaration()
) &&
if (flags.isForParameterDeclaration()) return false;
if (LT(2) == Token.tLPAREN && flags.isForConstructor()) return true;
int posTokenAfterTemplateParameters = 2;
if (LT(posTokenAfterTemplateParameters) == Token.tLT) {
// a case for template constructor, like CFoobar<A,B>::CFoobar
posTokenAfterTemplateParameters++;
// until we get all the names sorted out
int depth = 1;
while (depth > 0) {
switch (LT(posTokenAfterTemplateParameters++)) {
case Token.tGT :
--depth;
break;
case Token.tLT :
++depth;
break;
}
}
}
return
(LT(posTokenAfterTemplateParameters) == Token.tCOLONCOLON)
&&
(
(
(
LT(2) == Token.tCOLONCOLON &&
(
LA(3).getImage().equals( LA(1).getImage() ) ||
LT(3) == Token.tCOMPL
)
) ||
(
LT(2) == Token.tLPAREN &&
flags.isForConstructor()
)
)
LA(posTokenAfterTemplateParameters+1).getImage().equals( LA(1).getImage() ) ||
LT(posTokenAfterTemplateParameters+1) == Token.tCOMPL
)
;
}
@ -1146,6 +1160,37 @@ c, quickParse);
} 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.
@ -1198,23 +1243,7 @@ c, quickParse);
*/
protected Token templateId() throws Backtrack {
Token first = consume( Token.tIDENTIFIER );
consume( Token.tLT );
// 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;
}
}
Token last = consumeTemplateParameters(first);
callback.nameBegin( first );
callback.nameEnd( last );
@ -1249,25 +1278,7 @@ c, quickParse);
switch (LT(1)) {
case Token.tIDENTIFIER:
last = consume();
if( LT(1) == Token.tLT )
{
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;
}
}
}
last = consumeTemplateParameters(last);
break;
default:
backup( mark );
@ -1289,26 +1300,7 @@ c, quickParse);
throw backtrack;
case Token.tIDENTIFIER:
last = consume();
if( LT(1) == Token.tLT )
{
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;
}
}
}
last = consumeTemplateParameters(last);
}
}
@ -1515,13 +1507,16 @@ c, quickParse);
{
Token start = consume();
Token end = null;
if (start.type == Token.tIDENTIFIER) end = consumeTemplateParameters(end);
while( LT(1) == Token.tCOLONCOLON || LT(1) == Token.tIDENTIFIER )
{
end = consume();
if (end.type == Token.tIDENTIFIER) end = consumeTemplateParameters(end);
}
if( LT(1) == Token.t_operator )
{
consume();
if( LA(1).isOperator() || LT(1) == Token.tLPAREN || LT(1) == Token.tLBRACKET )
{
if( (LT(1) == Token.t_new || LT(1) == Token.t_delete ) &&

View file

@ -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
Moved testBug23478A() & testBug23478B() from failed tests to TranslationUnitTests.java.
Removed TranslationUnitFailedTests.java as it was empty.

View file

@ -23,33 +23,6 @@ public class STLFailedTests extends BaseDOMTest {
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{
Writer code = new StringWriter();
code.write("__STL_BEGIN_NAMESPACE\n");

View file

@ -1783,5 +1783,40 @@ public class DOMTests extends BaseDOMTest {
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());
}
}