1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for John Camelon:

CORE 
        Fixed error in Elaborated Enumeration Types.   
        Fixed Bug36559  - Parsing Templates...  
        Fixed Bug36634  - Enum start line error  

TESTS 
        Updated DOMTests::testBug36600(). 
        Updated LineNumberTest::testDOMLineNos().   
        Added DOMTests::testBug36559().
This commit is contained in:
Doug Schaefer 2003-04-17 18:59:18 +00:00
parent 8fc0923c61
commit ec6fd870a4
7 changed files with 94 additions and 19 deletions

View file

@ -338,7 +338,10 @@ public class DOMBuilder implements IParserCallback
break; break;
case Token.t_union: case Token.t_union:
kind = ClassKey.t_union; kind = ClassKey.t_union;
break; break;
case Token.t_enum:
kind = ClassKey.t_enum;
break;
} }
ElaboratedTypeSpecifier elab = null; ElaboratedTypeSpecifier elab = null;
@ -637,7 +640,7 @@ public class DOMBuilder implements IParserCallback
es.setStartToken(enumKey); es.setStartToken(enumKey);
decl.setTypeSpecifier(es); decl.setTypeSpecifier(es);
((IOffsetable)es).setStartingOffset( enumKey.getOffset() ); ((IOffsetable)es).setStartingOffset( enumKey.getOffset() );
((IOffsetable)es).setStartingOffset( parser.getLineNumberForOffset(enumKey.getOffset()) ); ((IOffsetable)es).setTopLine( parser.getLineNumberForOffset(enumKey.getOffset()) );
return es; return es;
} }

View file

@ -1,3 +1,8 @@
2003-04-17 John Camelon
Fixed error in Elaborated Enumeration Types.
Fixed Bug36559 - Parsing Templates...
Fixed Bug36634 - Enum start line error
2003-04-16 John Camelon 2003-04-16 John Camelon
Fixed Bug36532 - Hang on partial template definition. Fixed Bug36532 - Hang on partial template definition.
Fixed Bug36432 - Trying to open attached source code hangs Eclipse. Fixed Bug36432 - Trying to open attached source code hangs Eclipse.

View file

@ -351,7 +351,7 @@ c, quick);
protected void templateParameterList( Object templateDeclaration ) throws EndOfFile, Backtrack { protected void templateParameterList( Object templateDeclaration ) throws EndOfFile, Backtrack {
// if we have gotten this far then we have a true template-declaration // if we have gotten this far then we have a true template-declaration
// iterate through the template parameter list // iterate through the template parameter listtt
Object templateParameterList = null; Object templateParameterList = null;
@ -376,7 +376,7 @@ c, quick);
if( LT(1) == Token.tASSIGN ) // optional = type-id if( LT(1) == Token.tASSIGN ) // optional = type-id
{ {
consume( Token.tASSIGN ); consume( Token.tASSIGN );
identifier(); // type-id typeId(); // type-id
try{ callback.templateTypeParameterInitialTypeId( currentTemplateParm ); }catch( Exception e ) {} try{ callback.templateTypeParameterInitialTypeId( currentTemplateParm ); }catch( Exception e ) {}
} }
} }
@ -404,7 +404,7 @@ c, quick);
if( LT(1) == Token.tASSIGN ) // optional = type-id if( LT(1) == Token.tASSIGN ) // optional = type-id
{ {
consume( Token.tASSIGN ); consume( Token.tASSIGN );
name(); typeId();
try{ callback.templateTypeParameterInitialTypeId( newTemplateParm );} catch( Exception e ) {} try{ callback.templateTypeParameterInitialTypeId( newTemplateParm );} catch( Exception e ) {}
} }
} }
@ -757,8 +757,7 @@ c, quick);
callback.elaboratedTypeSpecifierName( elab ); callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab ); callback.elaboratedTypeSpecifierEnd( elab );
} catch( Exception e ) {} } catch( Exception e ) {}
encounteredTypename = true; return;
break;
} }
case Token.t_enum: case Token.t_enum:
try try
@ -776,8 +775,8 @@ c, quick);
callback.elaboratedTypeSpecifierName( elab ); callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab ); callback.elaboratedTypeSpecifierEnd( elab );
} catch( Exception e ) {} } catch( Exception e ) {}
return;
} }
break;
default: default:
break declSpecifiers; break declSpecifiers;
} }
@ -1948,7 +1947,8 @@ c, quick);
name(); name();
return; return;
} catch (Backtrack b) { } catch (Backtrack b) {
boolean encountered = false; Token begin = LA(1);
Token end = null;
simpleMods: simpleMods:
for( ; ; ) for( ; ; )
{ {
@ -1957,8 +1957,7 @@ c, quick);
case Token.t_short: case Token.t_short:
case Token.t_unsigned: case Token.t_unsigned:
case Token.t_long: case Token.t_long:
encountered = true; end = consume();
consume();
break; break;
case Token.t_int: case Token.t_int:
case Token.t_char: case Token.t_char:
@ -1967,14 +1966,21 @@ c, quick);
case Token.t_float: case Token.t_float:
case Token.t_wchar_t: case Token.t_wchar_t:
case Token.t_void: case Token.t_void:
encountered = true; end = consume();
consume();
default: default:
break simpleMods; break simpleMods;
} }
} }
if( encountered ) if( end != null )
return; {
try
{
callback.nameBegin( begin );
callback.nameEnd( end );
} catch( Exception e ) {}
}
else
throw backtrack;
} }
} }

View file

@ -1,3 +1,8 @@
2003-04-17 John Camelon
Updated DOMTests::testBug36600().
Updated LineNumberTest::testDOMLineNos().
Added DOMTests::testBug36559().
2003-04-17 Andrew Niefer 2003-04-17 Andrew Niefer
Added AutomatedTest Added AutomatedTest
Added resources.cFiles Added resources.cFiles

View file

@ -75,11 +75,8 @@ public class AutomatedTest extends TestCase {
output = file.getCanonicalPath() + ": Parse failed on line "; output = file.getCanonicalPath() + ": Parse failed on line ";
output += parser.getLastLineNumber() + "\n"; output += parser.getLastLineNumber() + "\n";
} else { } else {
StackTraceElement frames[] = e.getStackTrace();
output = file.getCanonicalPath() + ": " + e.getClass().toString(); output = file.getCanonicalPath() + ": " + e.getClass().toString();
output += " on line " + parser.getLastLineNumber() + "\n"; output += " on line " + parser.getLastLineNumber() + "\n";
output += "\t" + "at " + frames[0].getClassName() + "." + frames[0].getMethodName() + "\n";
output += "\t" + "at " + frames[1].getClassName() + "." + frames[1].getMethodName() + "\n";
} }
if( report != null ){ if( report != null ){
report.write( output.getBytes() ); report.write( output.getBytes() );

View file

@ -1309,7 +1309,25 @@ public class DOMTests extends TestCase {
public void testBug36600() throws Exception public void testBug36600() throws Exception
{ {
TranslationUnit tu = parse( "enum mad_flow (*input_func)(void *, struct mad_stream *);"); TranslationUnit tu = parse( "enum mad_flow (*input_func)(void *, struct mad_stream *);");
assertEquals( tu.getDeclarations().size(), 1 );
SimpleDeclaration simple = (SimpleDeclaration)tu.getDeclarations().get(0);
ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier)simple.getTypeSpecifier();
assertEquals( elab.getClassKey(), ClassKey.t_enum );
assertEquals( elab.getName().toString(), "mad_flow");
assertEquals( simple.getDeclarators().size(), 1 );
Declarator declarator = (Declarator)simple.getDeclarators().get(0);
assertNull( declarator.getName() );
assertNotNull( declarator.getDeclarator() );
tu = parse( "enum mad_layer layer;");
assertEquals( tu.getDeclarations().size(), 1);
SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0);
elab = (ElaboratedTypeSpecifier)declaration.getTypeSpecifier();
assertEquals( elab.getClassKey(), ClassKey.t_enum);
assertEquals( elab.getName().toString(), "mad_layer");
assertEquals( declaration.getDeclarators().size(), 1);
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getName().toString(), "layer" );
} }
public void testBug36247() throws Exception public void testBug36247() throws Exception
@ -1367,5 +1385,43 @@ public class DOMTests extends TestCase {
} }
} }
public void testBug36559() throws Exception
{
Writer code = new StringWriter();
code.write( "namespace myNameSpace {\n" );
code.write( "template<typename T=short> class B {};\n" );
code.write( "template<> class B<int> {};\n" );
code.write( "}\n" );
TranslationUnit tu = parse( code.toString() );
assertEquals( tu.getDeclarations().size(),1);
NamespaceDefinition definition = (NamespaceDefinition)tu.getDeclarations().get(0);
assertEquals( definition.getName().toString(), "myNameSpace");
assertEquals( definition.getDeclarations().size(), 2 );
TemplateDeclaration templateDeclaration = (TemplateDeclaration)definition.getDeclarations().get(0);
assertFalse( templateDeclaration.isExported());
assertEquals( templateDeclaration.getTemplateParms().getDeclarations().size(), 1 );
TemplateParameter parm = (TemplateParameter)templateDeclaration.getTemplateParms().getDeclarations().get(0);
assertEquals( parm.getKind(), TemplateParameter.k_typename );
assertEquals( parm.getName().toString(), "T");
assertEquals( parm.getTypeId().toString(), "short");
assertEquals( templateDeclaration.getDeclarations().size(), 1 );
SimpleDeclaration classB = (SimpleDeclaration)templateDeclaration.getDeclarations().get(0);
assertEquals( classB.getDeclarators().size(), 0 );
assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getName().toString(), "B" );
assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getClassKey(), ClassKey.t_class );
assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getDeclarations().size(), 0 );
ExplicitTemplateDeclaration etd = (ExplicitTemplateDeclaration)definition.getDeclarations().get(1);
assertEquals( etd.getKind(), ExplicitTemplateDeclaration.k_specialization );
assertEquals( etd.getDeclarations().size(), 1 );
classB = (SimpleDeclaration)etd.getDeclarations().get(0);
assertEquals( classB.getDeclarators().size(), 0 );
assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getName().toString(), "B<int>" );
assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getClassKey(), ClassKey.t_class );
assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getDeclarations().size(), 0 );
}
} }

View file

@ -21,6 +21,7 @@ import junit.framework.TestCase;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier; import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
import org.eclipse.cdt.internal.core.dom.DOMBuilder; import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
import org.eclipse.cdt.internal.core.dom.IOffsetable; import org.eclipse.cdt.internal.core.dom.IOffsetable;
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition; import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration; import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
@ -134,7 +135,9 @@ public class LineNumberTest extends TestCase {
validateLineNumbers( (SimpleDeclaration)declarations.get(1), 25, 27); validateLineNumbers( (SimpleDeclaration)declarations.get(1), 25, 27);
validateLineNumbers( (TemplateDeclaration)declarations.get(2), 34, 35); validateLineNumbers( (TemplateDeclaration)declarations.get(2), 34, 35);
validateLineNumbers( (SimpleDeclaration)declarations.get(3), 38, 43); SimpleDeclaration d = (SimpleDeclaration)declarations.get(3);
validateLineNumbers( d, 38, 43);
validateLineNumbers( ((EnumerationSpecifier)d.getTypeSpecifier()), 38, 43);
} }