1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

fix bug 60422 - Template offsets are not correct in Structural Parse mode

Fix bug 60480 - Template parameter <int> is not parsed correctly in Structural parse mode
fix offset information for template parameters
This commit is contained in:
Andrew Niefer 2004-04-29 19:39:21 +00:00
parent f12fae4a2a
commit dc66afff94
10 changed files with 194 additions and 53 deletions

View file

@ -212,7 +212,7 @@ public interface IASTFactory
public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset, int startingLine ) throws ASTSemanticException; public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset, int startingLine ) throws ASTSemanticException;
public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, IASTTypeId defaultValue, IASTParameterDeclaration parameter, List parms, IASTCodeScope parameterScope ) throws ASTSemanticException; public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, IASTTypeId defaultValue, IASTParameterDeclaration parameter, List parms, IASTCodeScope parameterScope, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine ) throws ASTSemanticException;
public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset, int startingLine); public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset, int startingLine);

View file

@ -428,6 +428,7 @@ public abstract class Parser extends ExpressionParser implements IParser
protected IASTDeclaration templateDeclaration(IASTScope scope) protected IASTDeclaration templateDeclaration(IASTScope scope)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
IToken mark = mark();
IToken firstToken = null; IToken firstToken = null;
boolean exported = false; boolean exported = false;
if (LT(1) == IToken.t_export) if (LT(1) == IToken.t_export)
@ -452,6 +453,7 @@ public abstract class Parser extends ExpressionParser implements IParser
catch (Exception e) catch (Exception e)
{ {
logException( "templateDeclaration:createTemplateInstantiation", e ); //$NON-NLS-1$ logException( "templateDeclaration:createTemplateInstantiation", e ); //$NON-NLS-1$
backup( mark );
throw backtrack; throw backtrack;
} }
templateInstantiation.enterScope( requestor ); templateInstantiation.enterScope( requestor );
@ -480,6 +482,7 @@ public abstract class Parser extends ExpressionParser implements IParser
catch (Exception e) catch (Exception e)
{ {
logException( "templateDeclaration:createTemplateSpecialization", e ); //$NON-NLS-1$ logException( "templateDeclaration:createTemplateSpecialization", e ); //$NON-NLS-1$
backup( mark );
throw backtrack; throw backtrack;
} }
templateSpecialization.enterScope(requestor); templateSpecialization.enterScope(requestor);
@ -524,6 +527,7 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
catch (BacktrackException bt) catch (BacktrackException bt)
{ {
backup( mark );
throw bt; throw bt;
} }
} }
@ -569,11 +573,10 @@ public abstract class Parser extends ExpressionParser implements IParser
return returnValue; return returnValue;
if (LT(1) == IToken.t_class || LT(1) == IToken.t_typename) if (LT(1) == IToken.t_class || LT(1) == IToken.t_typename)
{ {
IASTTemplateParameter.ParamKind kind = IASTTemplateParameter.ParamKind kind = (consume().getType() == IToken.t_class)
(consume().getType() == IToken.t_class) ? IASTTemplateParameter.ParamKind.CLASS
? IASTTemplateParameter.ParamKind.CLASS : IASTTemplateParameter.ParamKind.TYPENAME;
: IASTTemplateParameter.ParamKind.TYPENAME; IToken startingToken = lastToken;
IToken id = null; IToken id = null;
IASTTypeId typeId = null; IASTTypeId typeId = null;
try try
@ -603,7 +606,12 @@ public abstract class Parser extends ExpressionParser implements IParser
typeId, typeId,
null, null,
null, null,
( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null )); ( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null,
startingToken.getOffset(), startingToken.getLineNumber(),
(id != null) ? id.getOffset() : 0,
(id != null) ? id.getEndOffset() : 0,
(id != null) ? id.getLineNumber() : 0,
lastToken.getEndOffset(), lastToken.getLineNumber() ));
} }
catch (Exception e) catch (Exception e)
{ {
@ -615,6 +623,7 @@ public abstract class Parser extends ExpressionParser implements IParser
else if (LT(1) == IToken.t_template) else if (LT(1) == IToken.t_template)
{ {
consume(IToken.t_template); consume(IToken.t_template);
IToken startingToken = lastToken;
consume(IToken.tLT); consume(IToken.tLT);
List subResult = templateParameterList(parameterScope); List subResult = templateParameterList(parameterScope);
@ -643,7 +652,12 @@ public abstract class Parser extends ExpressionParser implements IParser
optionalTypeId, optionalTypeId,
null, null,
subResult, subResult,
( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null )); ( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null,
startingToken.getOffset(), startingToken.getLineNumber(),
(optionalId != null) ? optionalId.getOffset() : 0,
(optionalId != null) ? optionalId.getEndOffset() : 0,
(optionalId != null) ? optionalId.getLineNumber() : 0,
lastToken.getEndOffset(), lastToken.getLineNumber() ));
} }
catch (Exception e) catch (Exception e)
{ {
@ -660,10 +674,8 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
ParameterCollection c = new ParameterCollection(); ParameterCollection c = new ParameterCollection();
parameterDeclaration(c, parameterScope); parameterDeclaration(c, parameterScope);
DeclarationWrapper wrapper = DeclarationWrapper wrapper = (DeclarationWrapper)c.getParameters().get(0);
(DeclarationWrapper)c.getParameters().get(0); Declarator declarator = (Declarator)wrapper.getDeclarators().next();
Declarator declarator =
(Declarator)wrapper.getDeclarators().next();
try try
{ {
returnValue.add( returnValue.add(
@ -677,11 +689,17 @@ public abstract class Parser extends ExpressionParser implements IParser
wrapper.getTypeSpecifier(), wrapper.getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
null, null, declarator.getName() == null null, null,
? "" //$NON-NLS-1$ declarator.getName() == null ? "" : declarator.getName(), //$NON-NLS-1$
: declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), wrapper.getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), wrapper.getEndLine()), declarator.getInitializerClause(),
wrapper.getStartingOffset(), wrapper.getStartingLine(),
declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(),
wrapper.getEndOffset(), wrapper.getEndLine()),
null, null,
( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null )); ( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null,
wrapper.getStartingOffset(), wrapper.getStartingLine(),
declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(),
wrapper.getEndOffset(), wrapper.getEndLine() ));
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
@ -21,6 +22,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension;
import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory; import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory;
import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol;
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
@ -63,7 +65,7 @@ public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDec
factory.pushTemplate( template ); factory.pushTemplate( template );
templateParameters = parameters; templateParameters = ( parameters != null ) ? parameters : new LinkedList();
ownerScope = scope; ownerScope = scope;
} }
@ -85,8 +87,14 @@ public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDec
public IASTDeclaration getOwnedDeclaration() public IASTDeclaration getOwnedDeclaration()
{ {
if( owned != null && owned.getASTExtension() != null ){ if( owned != null && owned.getASTExtension() != null ){
ASTNode node = owned.getASTExtension().getPrimaryDeclaration(); ISymbolASTExtension extension = owned.getASTExtension();
return ( node instanceof IASTDeclaration ) ? (IASTDeclaration)node : null; Iterator i = extension.getAllDefinitions();
ASTSymbol s = null;
while( i.hasNext() ){
s = (ASTSymbol) i.next();
}
return s;
} }
IContainerSymbol ownedSymbol = getTemplateSymbol().getTemplatedSymbol(); IContainerSymbol ownedSymbol = getTemplateSymbol().getTemplatedSymbol();

View file

@ -40,12 +40,17 @@ public class ASTTemplateParameter extends ASTSymbol implements IASTTemplateParam
* @param parameter2 * @param parameter2
* @param parms2 * @param parms2
*/ */
public ASTTemplateParameter(ISymbol sym, IASTTypeId defVal, IASTParameterDeclaration param, List parms ) { public ASTTemplateParameter(ISymbol sym, IASTTypeId defVal, IASTParameterDeclaration param, List parms, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine ) {
super( sym ); super( sym );
symbol = sym; symbol = sym;
defaultValue = defVal; defaultValue = defVal;
parameter = (ASTParameterDeclaration) param; parameter = (ASTParameterDeclaration) param;
this.parms = parms; this.parms = parms;
setStartingOffsetAndLineNumber(startingOffset, startingLine);
setEndingOffsetAndLineNumber(endingOffset, endingLine);
setNameOffset(nameOffset);
setNameEndOffsetAndLineNumber( nameEndOffset, nameLine );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind() * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind()

View file

@ -909,12 +909,16 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
return null; return null;
} }
Iterator i = symbol.getASTExtension().getAllDefinitions();
ASTSymbol declaration = i.hasNext() ? (ASTSymbol) i.next() : null;
ASTSymbol definition = i.hasNext() ? (ASTSymbol) i.next() : null;
// assert (symbol != null ) : "createReference cannot be called on null symbol "; // assert (symbol != null ) : "createReference cannot be called on null symbol ";
if( symbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) || if( symbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) ||
symbol.getASTExtension().getPrimaryDeclaration() instanceof IASTTypedefDeclaration ) symbol.getASTExtension().getPrimaryDeclaration() instanceof IASTTypedefDeclaration )
return new ASTTypedefReference( offset, referenceElementName, (IASTTypedefDeclaration)symbol.getASTExtension().getPrimaryDeclaration()); return new ASTTypedefReference( offset, referenceElementName, (IASTTypedefDeclaration)declaration);
else if( symbol.getType() == TypeInfo.t_namespace ) else if( symbol.getType() == TypeInfo.t_namespace )
return new ASTNamespaceReference( offset, referenceElementName, (IASTNamespaceDefinition)symbol.getASTExtension().getPrimaryDeclaration()); return new ASTNamespaceReference( offset, referenceElementName, (IASTNamespaceDefinition)declaration);
else if( symbol.getType() == TypeInfo.t_class || else if( symbol.getType() == TypeInfo.t_class ||
symbol.getType() == TypeInfo.t_struct || symbol.getType() == TypeInfo.t_struct ||
symbol.getType() == TypeInfo.t_union ) symbol.getType() == TypeInfo.t_union )
@ -922,10 +926,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
else if( symbol.getType() == TypeInfo.t_enumeration ) else if( symbol.getType() == TypeInfo.t_enumeration )
return new ASTEnumerationReference( offset, referenceElementName, (IASTEnumerationSpecifier)symbol.getASTExtension().getPrimaryDeclaration() ); return new ASTEnumerationReference( offset, referenceElementName, (IASTEnumerationSpecifier)symbol.getASTExtension().getPrimaryDeclaration() );
else if( symbol.getType() == TypeInfo.t_enumerator ) else if( symbol.getType() == TypeInfo.t_enumerator )
return new ASTEnumeratorReference( offset, referenceElementName, (IASTEnumerator)symbol.getASTExtension().getPrimaryDeclaration() ); return new ASTEnumeratorReference( offset, referenceElementName, (IASTEnumerator)declaration );
else if(( symbol.getType() == TypeInfo.t_function ) || (symbol.getType() == TypeInfo.t_constructor)) else if(( symbol.getType() == TypeInfo.t_function ) || (symbol.getType() == TypeInfo.t_constructor))
{ {
ASTNode referenced = symbol.getASTExtension().getPrimaryDeclaration(); ASTNode referenced = (definition != null) ? definition : declaration;
if( referenced instanceof IASTMethod ) if( referenced instanceof IASTMethod )
return new ASTMethodReference( offset, referenceElementName, (IASTMethod)referenced ); return new ASTMethodReference( offset, referenceElementName, (IASTMethod)referenced );
else else
@ -947,7 +951,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
symbol.getContainingSymbol().getType() == TypeInfo.t_struct || symbol.getContainingSymbol().getType() == TypeInfo.t_struct ||
symbol.getContainingSymbol().getType() == TypeInfo.t_union ) symbol.getContainingSymbol().getType() == TypeInfo.t_union )
{ {
return new ASTFieldReference( offset, referenceElementName, (IASTField)symbol.getASTExtension().getPrimaryDeclaration()); return new ASTFieldReference( offset, referenceElementName, (IASTField)(definition != null ? definition : declaration ));
} }
else if( ( symbol.getContainingSymbol().getType() == TypeInfo.t_function || else if( ( symbol.getContainingSymbol().getType() == TypeInfo.t_function ||
symbol.getContainingSymbol().getType() == TypeInfo.t_constructor ) && symbol.getContainingSymbol().getType() == TypeInfo.t_constructor ) &&
@ -955,11 +959,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
((IParameterizedSymbol)symbol.getContainingSymbol()).getParameterList() != null && ((IParameterizedSymbol)symbol.getContainingSymbol()).getParameterList() != null &&
((IParameterizedSymbol)symbol.getContainingSymbol()).getParameterList().contains( symbol ) ) ((IParameterizedSymbol)symbol.getContainingSymbol()).getParameterList().contains( symbol ) )
{ {
return new ASTParameterReference( offset, referenceElementName, (IASTParameterDeclaration)symbol.getASTExtension().getPrimaryDeclaration() ); return new ASTParameterReference( offset, referenceElementName, (IASTParameterDeclaration)declaration );
} }
else else
{ {
ASTNode s = symbol.getASTExtension().getPrimaryDeclaration(); ASTNode s = (definition != null) ? definition : declaration;
if(s instanceof IASTVariable) if(s instanceof IASTVariable)
return new ASTVariableReference( offset, referenceElementName, (IASTVariable)s); return new ASTVariableReference( offset, referenceElementName, (IASTVariable)s);
else if (s instanceof IASTParameterDeclaration) else if (s instanceof IASTParameterDeclaration)
@ -2807,7 +2811,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IASTTypeId defaultValue, IASTTypeId defaultValue,
IASTParameterDeclaration parameter, IASTParameterDeclaration parameter,
List parms, List parms,
IASTCodeScope parameterScope ) throws ASTSemanticException IASTCodeScope parameterScope,
int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine ) throws ASTSemanticException
{ {
ISymbol symbol = null; ISymbol symbol = null;
if( kind == ParamKind.TEMPLATE_LIST ){ if( kind == ParamKind.TEMPLATE_LIST ){
@ -2830,7 +2835,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( kind == ParamKind.CLASS || kind == ParamKind.TYPENAME ){ if( kind == ParamKind.CLASS || kind == ParamKind.TYPENAME ){
symbol.getTypeInfo().setTemplateParameterType( TypeInfo.t_typeName ); symbol.getTypeInfo().setTemplateParameterType( TypeInfo.t_typeName );
} else /*ParamKind.PARAMETER*/ { } else /*ParamKind.PARAMETER*/ {
pst.newSymbol( identifier, TypeInfo.t_templateParameter );
symbol.setName( parameter.getName() ); symbol.setName( parameter.getName() );
symbol.setTypeInfo( ((ASTSimpleTypeSpecifier)parameter.getTypeSpecifier()).getSymbol().getTypeInfo() ); symbol.setTypeInfo( ((ASTSimpleTypeSpecifier)parameter.getTypeSpecifier()).getSymbol().getTypeInfo() );
symbol.getTypeInfo().setTemplateParameterType( symbol.getType() ); symbol.getTypeInfo().setTemplateParameterType( symbol.getType() );
@ -2852,7 +2856,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} catch (ASTNotImplementedException e1) { } catch (ASTNotImplementedException e1) {
} }
} }
ASTTemplateParameter ast = new ASTTemplateParameter( symbol, defaultValue, parameter, parms );
ASTTemplateParameter ast = new ASTTemplateParameter( symbol, defaultValue, parameter, parms, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, endingLine );
attachSymbolExtension( symbol, ast, false ); attachSymbolExtension( symbol, ast, false );
@ -2865,7 +2870,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IASTScope scope, IASTScope scope,
int startingOffset, int startingLine) int startingOffset, int startingLine)
{ {
return new ASTTemplateInstantiation( scope ); ASTTemplateInstantiation inst = new ASTTemplateInstantiation( scope );
inst.setStartingOffsetAndLineNumber( startingOffset, startingLine );
return inst;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTScope, int) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTScope, int)
@ -2877,7 +2884,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ITemplateSymbol template = pst.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); ITemplateSymbol template = pst.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
ASTTemplateSpecialization ast = new ASTTemplateSpecialization( template, scope ); ASTTemplateSpecialization ast = new ASTTemplateSpecialization( template, scope );
ast.setStartingOffsetAndLineNumber( startingOffset, startingLine );
attachSymbolExtension( template, ast, false ); attachSymbolExtension( template, ast, false );
return ast; return ast;

View file

@ -737,7 +737,8 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
String identifier, String identifier,
IASTTypeId defaultValue, IASTTypeId defaultValue,
IASTParameterDeclaration parameter, IASTParameterDeclaration parameter,
List parms, IASTCodeScope parameterScope) { List parms, IASTCodeScope parameterScope,
int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View file

@ -16,15 +16,18 @@ import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
/** /**
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTTemplateParameter implements IASTTemplateParameter public class ASTTemplateParameter implements IASTTemplateParameter, IASTOffsetableNamedElement
{ {
private final NamedOffsets offsets = new NamedOffsets();
private final List templateParms; private final List templateParms;
private final IASTParameterDeclaration parameter; private final IASTParameterDeclaration parameter;
private final ParamKind kind; private final ParamKind kind;
@ -36,14 +39,19 @@ public class ASTTemplateParameter implements IASTTemplateParameter
* @param defaultValue * @param defaultValue
* @param parameter * @param parameter
*/ */
public ASTTemplateParameter(ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List templateParms) public ASTTemplateParameter(ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List templateParms, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine )
{ {
this.kind = kind; this.kind = kind;
this.identifier = identifier; this.identifier = identifier;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
this.parameter = parameter; this.parameter = parameter;
this.templateParms = templateParms; this.templateParms = templateParms;
setStartingOffsetAndLineNumber( startingOffset, startingLine );
setEndingOffsetAndLineNumber( endingOffset, endingLine );
setNameOffset( nameOffset );
setNameEndOffsetAndLineNumber(nameEndOffset, nameLine);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind() * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind()
*/ */
@ -102,5 +110,89 @@ public class ASTTemplateParameter implements IASTTemplateParameter
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
*/
public String getName() {
return identifier;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset()
*/
public int getNameOffset() {
return offsets.getNameOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
*/
public void setNameOffset(int o) {
offsets.setNameOffset( o );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset()
*/
public int getNameEndOffset() {
return offsets.getNameEndOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int)
*/
public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) {
offsets.setNameEndOffsetAndLineNumber( offset, lineNumber );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber()
*/
public int getNameLineNumber() {
return offsets.getNameLineNumber();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int)
*/
public void setStartingOffsetAndLineNumber(int offset, int lineNumber) {
offsets.setStartingOffsetAndLineNumber( offset, lineNumber );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int)
*/
public void setEndingOffsetAndLineNumber(int offset, int lineNumber) {
offsets.setEndingOffsetAndLineNumber(offset, lineNumber);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset()
*/
public int getStartingOffset() {
return offsets.getStartingOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset()
*/
public int getEndingOffset() {
return offsets.getEndingOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine()
*/
public int getStartingLine() {
return offsets.getStartingLine();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine()
*/
public int getEndingLine() {
return offsets.getEndingLine();
}
} }

View file

@ -248,9 +248,9 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateParameter(org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParameterKind, org.eclipse.cdt.core.parser.IToken, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateParameter(org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParameterKind, org.eclipse.cdt.core.parser.IToken, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration)
*/ */
public IASTTemplateParameter createTemplateParameter(IASTTemplateParameter.ParamKind kind, String identifier, IASTTypeId defaultValue, IASTParameterDeclaration parameter, List parms, IASTCodeScope parameterScope) public IASTTemplateParameter createTemplateParameter(IASTTemplateParameter.ParamKind kind, String identifier, IASTTypeId defaultValue, IASTParameterDeclaration parameter, List parms, IASTCodeScope parameterScope, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine)
{ {
return new ASTTemplateParameter( kind, identifier, defaultValue != null ? defaultValue.getTypeOrClassName() : "", parameter, parms ); //$NON-NLS-1$ return new ASTTemplateParameter( kind, identifier, defaultValue != null ? defaultValue.getTypeOrClassName() : "", parameter, parms, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, endingLine ); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -58,36 +58,46 @@ public class ParserSymbolTable {
} }
public IContainerSymbol newContainerSymbol( String name ){ public IContainerSymbol newContainerSymbol( String name ){
if( name == null ) name = EMPTY_NAME;
return new ContainerSymbol( this, name ); return new ContainerSymbol( this, name );
} }
public IContainerSymbol newContainerSymbol( String name, TypeInfo.eType type ){ public IContainerSymbol newContainerSymbol( String name, TypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new ContainerSymbol( this, name, type ); return new ContainerSymbol( this, name, type );
} }
public ISymbol newSymbol( String name ){ public ISymbol newSymbol( String name ){
if( name == null ) name = EMPTY_NAME;
return new BasicSymbol( this, name ); return new BasicSymbol( this, name );
} }
public ISymbol newSymbol( String name, TypeInfo.eType type ){ public ISymbol newSymbol( String name, TypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new BasicSymbol( this, name, type ); return new BasicSymbol( this, name, type );
} }
public IDerivableContainerSymbol newDerivableContainerSymbol( String name ){ public IDerivableContainerSymbol newDerivableContainerSymbol( String name ){
if( name == null ) name = EMPTY_NAME;
return new DerivableContainerSymbol( this, name ); return new DerivableContainerSymbol( this, name );
} }
public IDerivableContainerSymbol newDerivableContainerSymbol( String name, TypeInfo.eType type ){ public IDerivableContainerSymbol newDerivableContainerSymbol( String name, TypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new DerivableContainerSymbol( this, name, type ); return new DerivableContainerSymbol( this, name, type );
} }
public IParameterizedSymbol newParameterizedSymbol( String name ){ public IParameterizedSymbol newParameterizedSymbol( String name ){
if( name == null ) name = EMPTY_NAME;
return new ParameterizedSymbol( this, name ); return new ParameterizedSymbol( this, name );
} }
public IParameterizedSymbol newParameterizedSymbol( String name, TypeInfo.eType type ){ public IParameterizedSymbol newParameterizedSymbol( String name, TypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new ParameterizedSymbol( this, name, type ); return new ParameterizedSymbol( this, name, type );
} }
public ITemplateSymbol newTemplateSymbol( String name ){ public ITemplateSymbol newTemplateSymbol( String name ){
if( name == null ) name = EMPTY_NAME;
return new TemplateSymbol( this, name ); return new TemplateSymbol( this, name );
} }
public ISpecializedSymbol newSpecializedSymbol( String name ){ public ISpecializedSymbol newSpecializedSymbol( String name ){
if( name == null ) name = EMPTY_NAME;
return new SpecializedSymbol( this, name ); return new SpecializedSymbol( this, name );
} }

View file

@ -202,33 +202,33 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( !param.isType( TypeInfo.t_templateParameter ) ) if( !param.isType( TypeInfo.t_templateParameter ) )
return false; return false;
if( param.getName().equals( getName() ) ){ if( !getName().equals( ParserSymbolTable.EMPTY_NAME ) && param.getName().equals( getName() ) ){
return false; return false;
} }
if( param.getTypeInfo().getTemplateParameterType() != TypeInfo.t_typeName && if( param.getTypeInfo().getTemplateParameterType() != TypeInfo.t_typeName &&
param.getTypeInfo().getTemplateParameterType() != TypeInfo.t_template ) param.getTypeInfo().getTemplateParameterType() != TypeInfo.t_template )
{ {
if( param.isType( TypeInfo.t_bool, TypeInfo.t_int ) || TypeInfo info = param.getTypeInfo();
param.isType( TypeInfo.t_enumerator ) ) //a non-type template parameter shall have one of the following:
{
return true;
}
//a non-tpye template parameter shall have one of the following:
//integral or enumeration type //integral or enumeration type
//pointer to object or pointer to function //pointer to object or pointer to function
//reference to object or reference to function //reference to object or reference to function
//pointer to member //pointer to member
//14.1-7
//A non-type template-parameter shall not be declared to have floating point, class or void type //A non-type template-parameter shall not be declared to have floating point, class or void type
if( param.isType( TypeInfo.t_float ) || if( info.getPtrOperators().size() == 0 )
param.isType( TypeInfo.t_double )|| if( info.getTemplateParameterType() == TypeInfo.t_float ||
param.isType( TypeInfo.t_class ) || info.getTemplateParameterType() == TypeInfo.t_double ||
param.isType( TypeInfo.t_void ) ) info.getTemplateParameterType() == TypeInfo.t_class ||
{ info.getTemplateParameterType() == TypeInfo.t_struct ||
return false; info.getTemplateParameterType() == TypeInfo.t_union ||
} info.getTemplateParameterType() == TypeInfo.t_enumeration ||
info.getTemplateParameterType() == TypeInfo.t_void )
{
return false;
}
} }
return true; return true;
} }