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

org.eclipse.cdt.core

Added some trace statements to CompleteParseASTFactory.  
	Cleaned up usage of Enum.getValue() wrt encapsulation of enumerator value.  
	Refactored CompleteParseASTFactory for correctness and abstraction. 
	Added preliminary IProblem support to CompleteParseASTFactory.  
	Added (commented out unfortunately) assertions into CompleteParseASTFactory. 
	Updated IASTUsingDeclaration to return an Iterator for declarations mapped rather than just a single declaration.  

org.eclipse.cdt.core.tests
	Updated tests to deal with IASTUsingDeclaration interface changes.  

org.eclipse.cdt.ui
	Cleaned up usage of Enum.getValue() wrt encapsulation of enumerator value.
This commit is contained in:
John Camelon 2004-03-03 15:59:56 +00:00
parent ba12f674af
commit fc37d2f92c
35 changed files with 1469 additions and 1202 deletions

View file

@ -1,3 +1,6 @@
2004-03-03 John Camelon
Updated tests to deal with IASTUsingDeclaration interface changes.
2004-03-02 Sean Evoy
Added tests to verify that the tool command canbe set through the
IConfiguration interface in the testConfigurations() method, and

View file

@ -196,11 +196,11 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertEquals( directive.getNamespaceDefinition(), namespaceB );
assertEquals( directive.getNamespaceName(), "A::B" );
IASTUsingDeclaration declaration = (IASTUsingDeclaration)declarations.next();
assertEquals( declaration.getUsingType(), variableX );
assertEquals( declaration.getUsingTypes().next(), variableX );
declaration = (IASTUsingDeclaration)declarations.next();
assertEquals( declaration.getUsingType(), classC );
assertEquals( declaration.getUsingTypes().next(), classC );
declaration = (IASTUsingDeclaration)declarations.next();
assertEquals( declaration.getUsingType(), fieldY );
assertEquals( declaration.getUsingTypes().next(), fieldY );
assertEquals( callback.getReferences().size(), 12 );
}

View file

@ -25,7 +25,7 @@ public class Enum
/**
* @return
*/
public int getEnumValue()
protected int getEnumValue()
{
return enumValue;
}

View file

@ -0,0 +1,20 @@
/*******************************************************************************
* 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;
/**
* @author jcamelon
*/
public interface IFilenameProvider {
public char [] getCurrentFilename();
}

View file

@ -13,8 +13,11 @@ package org.eclipse.cdt.core.parser;
import java.util.Map;
/**
* Description of a C/C++ problem, as detected by the translation or some of the underlying
* technology reusing it.
* @author jcamelon
*
* Description of a C/C++ parse/compilation problem, as detected by the parser or some of the underlying
* clients of the parser.
*
* A problem provides access to:
* <ul>
* <li> its location (originating source file name, source position, line number), </li>
@ -26,6 +29,8 @@ import java.util.Map;
public interface IProblem
{
/**
* Returns the problem id
*
@ -205,6 +210,21 @@ public interface IProblem
*/
public static final String A_SCANNER_BADCHAR = null;
/**
* A_SYMBOL_NAME - symbol name
*/
public static final String A_SYMBOL_NAME = "symbol name";
/**
* A_NAMESPACE_NAME = namespace name
*/
public static final String A_NAMESPACE_NAME = "namespace name";
/**
* A_TYPE_NAME - type name
*/
public static final String A_TYPE_NAME = "type name";
/**
* Below are listed all available problem IDs. Note that this list could be augmented in the future,
* as new features are added to the C/C++ core implementation.
@ -320,14 +340,14 @@ public interface IProblem
public final static int PREPROCESSOR_MACRO_USAGE_ERROR = PREPROCESSOR_RELATED | 0x009;
/**
* Invalid Macro Pasting encountered by Preprocessor.
* Invalid Macro Pasting encountered by Preprocessor.
* Required attributes: A_PREPROC_MACRO_NAME
* @see #A_PREPROC_MACRO_NAME
*/
public final static int PREPROCESSOR_MACRO_PASTING_ERROR = PREPROCESSOR_RELATED | 0x00A;
/**
* Circular inclusion encountered by Preprocessor.
* Circular inclusion encountered by Preprocessor.
* Required attributes: A_PREPROC_INCLUDE_FILENAME
* @see #A_PREPROC_INCLUDE_FILENAME
*/
@ -340,10 +360,72 @@ public interface IProblem
/*
* Parser Semantic Problems
*/
/**
* Attempt to add a unique symbol, yet the value was already defined.
* Require attributes: A_SYMBOL_NAME
* @see #A_SYMBOL_NAME
*/
public final static int SEMANTIC_UNIQUE_NAME_PREDEFINED = SEMANTICS_RELATED | 0x001;
/**
* Attempt to use a symbol that was not found.
* Require attributes: A_SYMBOL_NAME
* @see #A_SYMBOL_NAME
*/
public final static int SEMANTIC_NAME_NOT_FOUND = SEMANTICS_RELATED | 0x002;
/**
* ID reserved for referencing an internal error inside the CCorePlugin implementation which
* may be surfaced as a problem associated with the translation unit which caused it to occur.
* Name not provided in context that it was required.
* Require attributes: none
*/
public final static int UNCLASSIFIED_ERROR = 0;
public final static int SEMANTIC_NAME_NOT_PROVIDED = SEMANTICS_RELATED | 0x003;
/**
* Invalid overload of a particular name.
* Required attributes: A_SYMBOL_NAME
* @see #A_SYMBOL_NAME
*/
public static final int SEMANTIC_INVALID_OVERLOAD = SEMANTICS_RELATED | 0x004;
/**
* Invalid using directive.
* Required attributes: A_NAMESPACE_NAME
* @see #A_NAMESPACE_NAME
*/
public static final int SEMANTIC_INVALID_USING = SEMANTICS_RELATED | 0x005;
/**
* Ambiguous lookup for given name.
* Required attributes: A_SYMBOL_NAME
* @see #A_SYMBOL_NAME
*/
public static final int SEMANTIC_AMBIGUOUS_LOOKUP = SEMANTICS_RELATED | 0x006;
/**
* Invalid type provided
* Required attribugtes: A_TYPE_NAME
* @see #A_TYPE_NAME
*/
public static final int SEMANTIC_INVALID_TYPE = SEMANTICS_RELATED | 0x007;
public static final int SEMANTIC_CIRCULAR_INHERITANCE = SEMANTICS_RELATED | 0x008;
public static final int SEMANTIC_INVALID_TEMPLATE = SEMANTICS_RELATED | 0x009;
public static final int SEMANTIC_BAD_VISIBILITY = SEMANTICS_RELATED | 0x00A;
public static final int SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION = SEMANTICS_RELATED | 0x00B;
public static final int SEMANTIC_INVALID_TEMPLATE_ARGUMENT = SEMANTICS_RELATED | 0x00C;
public static final int SEMANTIC_INVALID_TEMPLATE_PARAMETER = SEMANTICS_RELATED | 0x00D;
public static final int SEMANTIC_REDECLARED_TEMPLATE_PARAMETER = SEMANTICS_RELATED | 0x00E;
public static final int SEMANTIC_INVALID_CONVERSION_TYPE = SEMANTICS_RELATED | 0x00F;
public static final int SEMANTIC_MALFORMED_EXPRESSION = SEMANTICS_RELATED | 0x010;
public static final int SEMANTIC_ILLFORMED_FRIEND = SEMANTICS_RELATED | 0x011;
}

View file

@ -8,7 +8,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFactory;
* @author jcamelon
*
*/
public interface IScanner {
public interface IScanner extends IFilenameProvider {
public static final String __CPLUSPLUS = "__cplusplus"; //$NON-NLS-1$
public static final String __STDC_VERSION__ = "__STDC_VERSION__"; //$NON-NLS-1$

View file

@ -42,4 +42,7 @@ public interface ITokenDuple {
public int findLastTokenType( int type );
public IASTNode lookup( IASTFactory factory, IASTScope scope );
public int getStartOffset();
public int getEndOffset();
public int getLineNumber();
}

View file

@ -39,14 +39,14 @@ public class ParserFactory {
private static IParserExtensionFactory extensionFactory = new ParserExtensionFactory( ExtensionDialect.GCC );
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
public static IASTFactory createASTFactory( IFilenameProvider provider, ParserMode mode, ParserLanguage language )
{
if( mode == ParserMode.QUICK_PARSE )
return new QuickParseASTFactory( extensionFactory.createASTExtensionFactory( ParserMode.QUICK_PARSE ) );
else if( mode == ParserMode.EXPRESSION_PARSE )
return new ExpressionParseASTFactory( extensionFactory.createASTExtensionFactory( ParserMode.EXPRESSION_PARSE ) );
else
return new CompleteParseASTFactory( language, mode, extensionFactory.createASTExtensionFactory( ParserMode.COMPLETE_PARSE ) );
return new CompleteParseASTFactory( provider, language, mode, extensionFactory.createASTExtensionFactory( ParserMode.COMPLETE_PARSE ) );
}
public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, ParserLanguage language, IParserLogService log ) throws ParserFactoryError

View file

@ -26,5 +26,17 @@ public class ASTAccessVisibility extends Enum {
{
super( constant );
}
public boolean isLessThan( ASTAccessVisibility other )
{
return getEnumValue() < other.getEnumValue();
}
public boolean isGreaterThan( ASTAccessVisibility other )
{
return getEnumValue() > other.getEnumValue();
}
}

View file

@ -20,12 +20,6 @@ public class ASTSemanticException extends Exception
{
private final IProblem theProblem;
public ASTSemanticException()
{
theProblem = null;
}
/**
*
*/
@ -37,6 +31,14 @@ public class ASTSemanticException extends Exception
/**
* @param e
*/
public ASTSemanticException(ASTSemanticException e) {
theProblem = e.getProblem();
}
/**
* @return
*/
public IProblem getProblem()

View file

@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.core.parser.ast;
import java.util.Hashtable;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.Enum;
@ -118,6 +119,119 @@ public interface IASTExpression extends ISourceElementCallbackDelegate
{
super(enumValue);
}
private static final Hashtable names;
static
{
names = new Hashtable();
names.put( PRIMARY_EMPTY, "PRIMARY_EMPTY" );
names.put( PRIMARY_INTEGER_LITERAL , "PRIMARY_INTEGER_LITERAL" );
names.put( PRIMARY_CHAR_LITERAL , "PRIMARY_CHAR_LITERAL" );
names.put( PRIMARY_FLOAT_LITERAL , "PRIMARY_FLOAT_LITERAL" );
names.put( PRIMARY_STRING_LITERAL , "PRIMARY_STRING_LITERAL" );
names.put( PRIMARY_BOOLEAN_LITERAL , "PRIMARY_BOOLEAN_LITERAL" );
names.put( PRIMARY_THIS , "PRIMARY_THIS");
names.put( PRIMARY_BRACKETED_EXPRESSION , "PRIMARY_BRACKETED_EXPRESSION");
names.put( ID_EXPRESSION , "ID_EXPRESSION");
names.put( POSTFIX_SUBSCRIPT , "POSTFIX_SUBSCRIPT");
names.put( POSTFIX_FUNCTIONCALL , "POSTFIX_FUNCTIONCALL");
names.put( POSTFIX_SIMPLETYPE_INT , "POSTFIX_SIMPLETYPE_INT");
names.put( POSTFIX_SIMPLETYPE_SHORT , "POSTFIX_SIMPLETYPE_SHORT");
names.put( POSTFIX_SIMPLETYPE_DOUBLE , "POSTFIX_SIMPLETYPE_DOUBLE");
names.put( POSTFIX_SIMPLETYPE_FLOAT , "POSTFIX_SIMPLETYPE_FLOAT");
names.put( POSTFIX_SIMPLETYPE_CHAR , "POSTFIX_SIMPLETYPE_CHAR");
names.put( POSTFIX_SIMPLETYPE_WCHART , "POSTFIX_SIMPLETYPE_WCHART");
names.put( POSTFIX_SIMPLETYPE_SIGNED , "POSTFIX_SIMPLETYPE_SIGNED");
names.put( POSTFIX_SIMPLETYPE_UNSIGNED , "POSTFIX_SIMPLETYPE_UNSIGNED");
names.put( POSTFIX_SIMPLETYPE_BOOL , "POSTFIX_SIMPLETYPE_BOOL");
names.put( POSTFIX_SIMPLETYPE_LONG , "POSTFIX_SIMPLETYPE_LONG");
names.put( POSTFIX_TYPENAME_IDENTIFIER , "POSTFIX_TYPENAME_IDENTIFIER");
names.put( POSTFIX_TYPENAME_TEMPLATEID, "POSTFIX_TYPENAME_TEMPLATEID" );
names.put( POSTFIX_DOT_IDEXPRESSION , "POSTFIX_DOT_IDEXPRESSION");
names.put( POSTFIX_ARROW_IDEXPRESSION , "POSTFIX_ARROW_IDEXPRESSION");
names.put( POSTFIX_DOT_TEMPL_IDEXPRESS , "POSTFIX_DOT_TEMPL_IDEXPRESS");
names.put( POSTFIX_ARROW_TEMPL_IDEXP , "POSTFIX_ARROW_TEMPL_IDEXP");
names.put( POSTFIX_DOT_DESTRUCTOR , "POSTFIX_DOT_DESTRUCTOR");
names.put( POSTFIX_ARROW_DESTRUCTOR , "POSTFIX_ARROW_DESTRUCTOR");
names.put( POSTFIX_INCREMENT , "POSTFIX_INCREMENT");
names.put( POSTFIX_DECREMENT , "POSTFIX_DECREMENT");
names.put( POSTFIX_DYNAMIC_CAST , "POSTFIX_DYNAMIC_CAST");
names.put( POSTFIX_REINTERPRET_CAST , "POSTFIX_REINTERPRET_CAST");
names.put( POSTFIX_STATIC_CAST , "POSTFIX_STATIC_CAST");
names.put( POSTFIX_CONST_CAST , "POSTFIX_CONST_CAST");
names.put( POSTFIX_TYPEID_EXPRESSION , "POSTFIX_TYPEID_EXPRESSION");
names.put( POSTFIX_TYPEID_TYPEID , "POSTFIX_TYPEID_TYPEID");
names.put( UNARY_INCREMENT , "UNARY_INCREMENT");
names.put( UNARY_DECREMENT , "UNARY_DECREMENT");
names.put( UNARY_STAR_CASTEXPRESSION , "UNARY_STAR_CASTEXPRESSION");
names.put( UNARY_AMPSND_CASTEXPRESSION , "UNARY_AMPSND_CASTEXPRESSION");
names.put( UNARY_PLUS_CASTEXPRESSION , "UNARY_PLUS_CASTEXPRESSION");
names.put( UNARY_MINUS_CASTEXPRESSION , "UNARY_MINUS_CASTEXPRESSION");
names.put( UNARY_NOT_CASTEXPRESSION , "UNARY_NOT_CASTEXPRESSION");
names.put( UNARY_TILDE_CASTEXPRESSION , "UNARY_TILDE_CASTEXPRESSION");
names.put( UNARY_SIZEOF_UNARYEXPRESSION , "UNARY_SIZEOF_UNARYEXPRESSION");
names.put( UNARY_SIZEOF_TYPEID , "UNARY_SIZEOF_TYPEID");
names.put( NEW_NEWTYPEID , "NEW_NEWTYPEID");
names.put( NEW_TYPEID , "NEW_TYPEID");
names.put( DELETE_CASTEXPRESSION , "DELETE_CASTEXPRESSION");
names.put( DELETE_VECTORCASTEXPRESSION , "DELETE_VECTORCASTEXPRESSION");
names.put( CASTEXPRESSION , "CASTEXPRESSION");
names.put( PM_DOTSTAR , "PM_DOTSTAR");
names.put( PM_ARROWSTAR , "PM_ARROWSTAR");
names.put( MULTIPLICATIVE_MULTIPLY , "MULTIPLICATIVE_MULTIPLY");
names.put( MULTIPLICATIVE_DIVIDE , "MULTIPLICATIVE_DIVIDE");
names.put( MULTIPLICATIVE_MODULUS , "MULTIPLICATIVE_MODULUS");
names.put( ADDITIVE_PLUS , "ADDITIVE_PLUS");
names.put( ADDITIVE_MINUS , "ADDITIVE_MINUS");
names.put( SHIFT_LEFT , "SHIFT_LEFT");
names.put( SHIFT_RIGHT , "SHIFT_RIGHT");
names.put( RELATIONAL_LESSTHAN , "RELATIONAL_LESSTHAN");
names.put( RELATIONAL_GREATERTHAN , "RELATIONAL_GREATERTHAN");
names.put( RELATIONAL_LESSTHANEQUALTO , "RELATIONAL_LESSTHANEQUALTO");
names.put( RELATIONAL_GREATERTHANEQUALTO, "RELATIONAL_GREATERTHANEQUALTO" );
names.put( EQUALITY_EQUALS , "EQUALITY_EQUALS");
names.put( EQUALITY_NOTEQUALS , "EQUALITY_NOTEQUALS");
names.put( ANDEXPRESSION , "ANDEXPRESSION");
names.put( EXCLUSIVEOREXPRESSION , "EXCLUSIVEOREXPRESSION");
names.put( INCLUSIVEOREXPRESSION , "INCLUSIVEOREXPRESSION");
names.put( LOGICALANDEXPRESSION , "LOGICALANDEXPRESSION");
names.put( LOGICALOREXPRESSION , "LOGICALOREXPRESSION");
names.put( CONDITIONALEXPRESSION , "CONDITIONALEXPRESSION");
names.put( THROWEXPRESSION , "THROWEXPRESSION");
names.put( ASSIGNMENTEXPRESSION_NORMAL , "ASSIGNMENTEXPRESSION_NORMAL");
names.put( ASSIGNMENTEXPRESSION_PLUS , "ASSIGNMENTEXPRESSION_PLUS");
names.put( ASSIGNMENTEXPRESSION_MINUS , "ASSIGNMENTEXPRESSION_MINUS");
names.put( ASSIGNMENTEXPRESSION_MULT , "ASSIGNMENTEXPRESSION_MULT");
names.put( ASSIGNMENTEXPRESSION_DIV , "ASSIGNMENTEXPRESSION_DIV");
names.put( ASSIGNMENTEXPRESSION_MOD , "ASSIGNMENTEXPRESSION_MOD");
names.put( ASSIGNMENTEXPRESSION_LSHIFT , "ASSIGNMENTEXPRESSION_LSHIFT");
names.put( ASSIGNMENTEXPRESSION_RSHIFT , "ASSIGNMENTEXPRESSION_RSHIFT");
names.put( ASSIGNMENTEXPRESSION_AND , "ASSIGNMENTEXPRESSION_AND");
names.put( ASSIGNMENTEXPRESSION_OR , "ASSIGNMENTEXPRESSION_OR");
names.put( ASSIGNMENTEXPRESSION_XOR , "ASSIGNMENTEXPRESSION_XOR");
names.put( EXPRESSIONLIST , "EXPRESSIONLIST");
}
/**
* @return
*/
public String getKindName() {
return (String) names.get(this);
}
public boolean isPostfixMemberReference()
{
if( this == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION ||
this == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION ||
this == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS ||
this == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP ||
this == IASTExpression.Kind.PM_DOTSTAR ||
this == IASTExpression.Kind.PM_ARROWSTAR )
return true;
return false;
}
}

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.core.parser.ast;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
@ -243,4 +244,9 @@ public interface IASTFactory
public IASTNode getCompletionContext(Kind kind, IASTExpression expression);
public IASTNode lookupSymbolInContext( IASTScope scope, ITokenDuple duple ) throws ASTNotImplementedException;
/**
* @param log
*/
public void setLogger(IParserLogService log);
}

View file

@ -10,6 +10,8 @@
***********************************************************************/
package org.eclipse.cdt.core.parser.ast;
import java.util.Iterator;
/**
* @author jcamelon
*
@ -17,7 +19,7 @@ package org.eclipse.cdt.core.parser.ast;
public interface IASTUsingDeclaration extends IASTDeclaration, IASTOffsetableElement {
public boolean isTypename();
public String usingTypeName();
public IASTDeclaration getUsingType() throws ASTNotImplementedException;
public String usingTypeName();
public Iterator getUsingTypes() throws ASTNotImplementedException;
}

View file

@ -69,8 +69,9 @@ public class CompleteParser extends Parser {
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
*/
protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETE_PARSE, language);
astFactory = ParserFactory.createASTFactory( this, ParserMode.COMPLETE_PARSE, language);
scanner.setASTFactory(astFactory);
astFactory.setLogger(log);
}
}

View file

@ -160,8 +160,9 @@ public class CompletionParser extends ContextualParser implements IParser {
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
*/
protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETION_PARSE, language);
astFactory = ParserFactory.createASTFactory( this, ParserMode.COMPLETION_PARSE, language);
scanner.setASTFactory(astFactory);
astFactory.setLogger(log);
}
}

View file

@ -14,6 +14,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
@ -307,7 +308,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
/**
* @param requestor
*/
public List createASTNodes(IASTFactory astFactory) throws ASTSemanticException
public List createASTNodes(IASTFactory astFactory) throws ASTSemanticException, BacktrackException
{
this.astFactory = astFactory;
Iterator i = declarators.iterator();
@ -319,7 +320,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
/**
* @param declarator
*/
private IASTDeclaration createASTNode(Declarator declarator) throws ASTSemanticException
private IASTDeclaration createASTNode(Declarator declarator) throws ASTSemanticException, BacktrackException
{
boolean isWithinClass = (getScope() instanceof IASTClassSpecifier); //TODO fix this for COMPLETE_PARSE
boolean isFunction = declarator.isFunction();
@ -350,7 +351,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
* @param declarator
* @return
*/
private IASTDeclaration createIndirectDeclaration(Declarator declarator) throws ASTSemanticException
private IASTDeclaration createIndirectDeclaration(Declarator declarator) throws BacktrackException, ASTSemanticException
{
if( declarator.getOwnedDeclarator().getOwnedDeclarator() == null )
{
@ -383,9 +384,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
List convertedParms = createParameterList( declarator.getParameters() );
IASTAbstractDeclaration abs = null;
try
{
abs =
abs =
astFactory.createAbstractDeclaration(
constt,
volatil,
@ -394,44 +393,20 @@ public class DeclarationWrapper implements IDeclaratorOwner
declarator.getArrayModifiers(),
convertedParms,
(ASTPointerOperator)i.next());
}
catch (Exception e)
{
throw new ASTSemanticException();
}
String name = ( d.getPointerOperatorNameDuple() != null ) ? d.getPointerOperatorNameDuple().toString() + d.getName() : d.getName();
if( typedef )
try
{
return astFactory.createTypedef(
scope,
name,
abs, getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine() );
}
catch (ASTSemanticException e1)
{
throw e1;
}
catch (Exception e1)
{
throw new ASTSemanticException();
}
return astFactory.createTypedef(scope, name, abs,
getStartingOffset(), getStartingLine(), d
.getNameStartOffset(), d.getNameEndOffset(), d
.getNameLine());
else
try
{
return astFactory.createVariable( scope, name, auto, d.getInitializerClause(), d.getBitFieldExpression(), abs, mutable, extern, register, staticc, getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression() );
}
catch (Exception e2)
{
throw new ASTSemanticException();
}
return astFactory.createVariable( scope, name, auto, d.getInitializerClause(), d.getBitFieldExpression(), abs, mutable, extern, register, staticc, getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression() );
}
else
{
throw new ASTSemanticException();
throw new BacktrackException();
}
}
/**
@ -440,25 +415,14 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/
private IASTTypedefDeclaration createTypedef(Declarator declarator, boolean nested ) throws ASTSemanticException
{
try
{
return astFactory.createTypedef(
scope,
nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(),
astFactory.createAbstractDeclaration(
constt,
volatil,
getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), startingOffset, getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine());
}
catch (ASTSemanticException e)
{
throw e;
}
catch (Exception e)
{
throw new ASTSemanticException();
}
return astFactory.createTypedef(scope, nested ? declarator
.getOwnedDeclarator().getName() : declarator.getName(),
astFactory.createAbstractDeclaration(constt, volatil,
getTypeSpecifier(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), null, null),
startingOffset, getStartingLine(), declarator
.getNameStartOffset(), declarator.getNameEndOffset(),
declarator.getNameLine());
}
/**
* @param declarator
@ -466,41 +430,24 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/
private IASTMethod createMethodASTNode(Declarator declarator, boolean nested) throws ASTSemanticException
{
try
{
return astFactory
.createMethod(
scope,
nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(),
createParameterList(declarator.getParameters()),
astFactory.createAbstractDeclaration(
constt,
volatil,
getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
declarator.getExceptionSpecification(),
inline,
friend,
staticc,
startingOffset,
getStartingLine(),
declarator.getNameStartOffset(),
declarator.getNameEndOffset(),
declarator.getNameLine(),
templateDeclaration,
declarator.isConst(),
declarator.isVolatile(),
virtual, explicit,
declarator.isPureVirtual(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode(), declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody(), declarator.hasFunctionTryBlock(), declarator.isVarArgs());
}
catch (ASTSemanticException e)
{
throw e;
}
catch (Exception e)
{
throw new ASTSemanticException();
}
return astFactory.createMethod(scope, nested ? declarator
.getOwnedDeclarator().getNameDuple() : declarator
.getNameDuple(),
createParameterList(declarator.getParameters()), astFactory
.createAbstractDeclaration(constt, volatil,
getTypeSpecifier(), declarator
.getPointerOperators(), declarator
.getArrayModifiers(), null, null),
declarator.getExceptionSpecification(), inline, friend,
staticc, startingOffset, getStartingLine(), declarator
.getNameStartOffset(), declarator.getNameEndOffset(),
declarator.getNameLine(), templateDeclaration, declarator
.isConst(), declarator.isVolatile(), virtual, explicit,
declarator.isPureVirtual(), ((IASTClassSpecifier) scope)
.getCurrentVisibilityMode(), declarator
.getConstructorMemberInitializers(), declarator
.hasFunctionBody(), declarator.hasFunctionTryBlock(),
declarator.isVarArgs());
}
/**
* @param declarator
@ -508,41 +455,23 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/
private IASTFunction createFunctionASTNode(Declarator declarator, boolean nested) throws ASTSemanticException
{
try
{
return astFactory.createFunction(
scope,
nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(),
createParameterList(declarator.getParameters()),
astFactory.createAbstractDeclaration(
constt,
volatil,
getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
declarator.getExceptionSpecification(),
inline,
friend,
staticc,
startingOffset,
getStartingLine(),
declarator.getNameStartOffset(),
declarator.getNameEndOffset(),
declarator.getNameLine(),
templateDeclaration,
declarator.isConst(),
declarator.isVolatile(),
virtual,
explicit, declarator.isPureVirtual(), declarator.getConstructorMemberInitializers(),
declarator.hasFunctionBody(), declarator.hasFunctionTryBlock(), declarator.isVarArgs() );
}
catch (ASTSemanticException e)
{
throw e;
}
catch (Exception e)
{
throw new ASTSemanticException();
}
return astFactory.createFunction(scope, nested ? declarator
.getOwnedDeclarator().getNameDuple() : declarator
.getNameDuple(),
createParameterList(declarator.getParameters()), astFactory
.createAbstractDeclaration(constt, volatil,
getTypeSpecifier(), declarator
.getPointerOperators(), declarator
.getArrayModifiers(), null, null),
declarator.getExceptionSpecification(), inline, friend,
staticc, startingOffset, getStartingLine(), declarator
.getNameStartOffset(), declarator.getNameEndOffset(),
declarator.getNameLine(), templateDeclaration, declarator
.isConst(), declarator.isVolatile(), virtual, explicit,
declarator.isPureVirtual(), declarator
.getConstructorMemberInitializers(), declarator
.hasFunctionBody(), declarator.hasFunctionTryBlock(),
declarator.isVarArgs());
}
/**
* @param declarator
@ -550,9 +479,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/
private IASTField createFieldASTNode(Declarator declarator, boolean nested) throws ASTSemanticException
{
try
{
return astFactory.createField(
return astFactory.createField(
scope,
nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(),
auto,
@ -570,16 +497,8 @@ public class DeclarationWrapper implements IDeclaratorOwner
startingOffset,
getStartingLine(),
declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode());
}
catch (ASTSemanticException e)
{
throw e;
}
catch (Exception e)
{
throw new ASTSemanticException();
}
}
private List createParameterList(List currentParameters) throws ASTSemanticException
{
List result = new ArrayList();
@ -591,23 +510,17 @@ public class DeclarationWrapper implements IDeclaratorOwner
while (j.hasNext())
{
Declarator declarator = (Declarator)j.next();
try
{
result.add(
astFactory.createParameterDeclaration(
wrapper.isConst(),
wrapper.isVolatile(),
wrapper.getTypeSpecifier(),
declarator.getPointerOperators(),
declarator.getArrayModifiers(),
null, null, declarator.getName() == null
? "" //$NON-NLS-1$
: declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine()));
}
catch (Exception e)
{
throw new ASTSemanticException();
}
result.add(
astFactory.createParameterDeclaration(
wrapper.isConst(),
wrapper.isVolatile(),
wrapper.getTypeSpecifier(),
declarator.getPointerOperators(),
declarator.getArrayModifiers(),
null, null, declarator.getName() == null
? "" //$NON-NLS-1$
: declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine()));
}
}
return result;
@ -618,34 +531,24 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/
private IASTVariable createVariableASTNode(Declarator declarator, boolean nested ) throws ASTSemanticException
{
try
{
return astFactory.createVariable(
scope,
nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(),
isAuto(),
declarator.getInitializerClause(),
declarator.getBitFieldExpression(),
astFactory.createAbstractDeclaration(
constt,
volatil,
getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
mutable,
extern,
register,
staticc,
getStartingOffset(),
getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression());
}
catch (ASTSemanticException e)
{
throw e;
}
catch (Exception e)
{
throw new ASTSemanticException();
}
return astFactory.createVariable(
scope,
nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(),
isAuto(),
declarator.getInitializerClause(),
declarator.getBitFieldExpression(),
astFactory.createAbstractDeclaration(
constt,
volatil,
getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
mutable,
extern,
register,
staticc,
getStartingOffset(),
getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression());
}
/* (non-Javadoc)

View file

@ -71,8 +71,9 @@ public class ExpressionParser implements IExpressionParser {
* @param language
*/
protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
astFactory = ParserFactory.createASTFactory( ParserMode.EXPRESSION_PARSE, language);
astFactory = ParserFactory.createASTFactory( this, ParserMode.EXPRESSION_PARSE, language);
scanner.setASTFactory(astFactory);
astFactory.setLogger(log);
}
/**
@ -2508,4 +2509,8 @@ public class ExpressionParser implements IExpressionParser {
}
}
public char[] getCurrentFilename() {
return scanner.getCurrentFilename();
}
}

View file

@ -12,13 +12,14 @@ package org.eclipse.cdt.internal.core.parser;
import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IFilenameProvider;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTScope;
/**
* @author jcamelon
*/
public interface IExpressionParser {
public interface IExpressionParser extends IFilenameProvider {
/**
* Request a parse from a pre-configured parser to parse an expression.

View file

@ -123,7 +123,6 @@ public abstract class Parser extends ExpressionParser implements IParser
*/
protected void translationUnit()
{
try
{
compilationUnit = astFactory.createCompilationUnit();
@ -1649,7 +1648,8 @@ public abstract class Parser extends ExpressionParser implements IParser
eck = ASTClassKind.ENUM;
break;
default :
break;
backup( t );
throw backtrack;
}
ITokenDuple d = name(sdw.getScope(), CompletionKind.TYPE_REFERENCE);
@ -2991,5 +2991,4 @@ public abstract class Parser extends ExpressionParser implements IParser
*/
protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
}
}

View file

@ -70,8 +70,9 @@ public class QuickParser extends Parser {
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
*/
protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
astFactory = ParserFactory.createASTFactory( ParserMode.QUICK_PARSE, language);
astFactory = ParserFactory.createASTFactory( this, ParserMode.QUICK_PARSE, language);
scanner.setASTFactory(astFactory);
astFactory.setLogger(log);
}
}

View file

@ -38,8 +38,7 @@ public class StructuralParser extends Parser implements IParser {
*/
public StructuralParser(IScanner scanner, ISourceElementRequestor ourCallback, ParserLanguage language, IParserLogService logService) {
super(scanner, ourCallback, language, logService);
astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETE_PARSE, language);
scanner.setASTFactory(astFactory);
setupASTFactory(scanner, language );
}
/* (non-Javadoc)
@ -74,6 +73,13 @@ public class StructuralParser extends Parser implements IParser {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
*/
protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
astFactory = ParserFactory.createASTFactory( this, ParserMode.COMPLETE_PARSE, language);
scanner.setASTFactory(astFactory);
astFactory.setLogger(log);
}
}

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
@ -31,6 +32,8 @@ import org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind;
*/
public class BaseASTFactory {
protected IParserLogService logService;
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createMacro(java.lang.String, int, int, int)
*/
@ -64,5 +67,9 @@ public class BaseASTFactory {
fieldIdentifier == null ? -1 : fieldIdentifier.getOffset() );
}
public void setLogger(IParserLogService log) {
logService = log;
}
}

View file

@ -27,12 +27,12 @@ public class ASTNamespaceReference
/**
* @param offset
* @param string
* @param referencedElementName
* @param definition
*/
public ASTNamespaceReference(int offset, String string, IASTNamespaceDefinition definition)
public ASTNamespaceReference(int offset, String referencedElementName, IASTNamespaceDefinition definition)
{
super(offset, string);
super(offset, referencedElementName);
reference = definition;
}

View file

@ -0,0 +1,119 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. 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:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory;
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
/**
* @author jcamelon
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ASTProblemFactory extends BaseProblemFactory implements IProblemFactory
{
protected static final Map errorMessages;
static {
errorMessages = new HashMap();
errorMessages.put( new Integer( IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED),"Attempt to introduce unique symbol failed : ");
errorMessages.put( new Integer( IProblem.SEMANTIC_NAME_NOT_FOUND), "Attempt to use symbol failed : ");
errorMessages.put( new Integer( IProblem.SEMANTIC_NAME_NOT_PROVIDED), "Name not provided.");
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory#createMessage(int, java.util.Map, int, char[])
*/
public String createMessage(int id, Map arguments, int lineNumber,
char[] fileName) {
StringBuffer buffer = new StringBuffer();
buffer.append(PROBLEM);
buffer.append(errorMessages.get(new Integer(id)));
switch (id)
{
case IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED:
case IProblem.SEMANTIC_NAME_NOT_FOUND:
buffer.append(arguments.get(IProblem.A_SYMBOL_NAME));
break;
case IProblem.SEMANTIC_NAME_NOT_PROVIDED:
break;
default :
return null;
}
if( fileName != null )
{
buffer.append( IN_FILE );
buffer.append(fileName);
}
if( lineNumber > 0 )
{
buffer.append( ON_LINE );
buffer.append(lineNumber);
}
return buffer.toString();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#createProblem(int, int, int, int, char[], java.util.Map, boolean, boolean)
*/
public IProblem createProblem(int id, int start, int end, int line,
char[] file, Map arguments, boolean warn, boolean error) {
if( checkBitmask( id, IProblem.INTERNAL_RELATED ) )
return createInternalProblem( id, start, end, line, file, arguments, warn, error );
if ( checkBitmask( id, IProblem.SEMANTICS_RELATED ) )
return super.createProblem(
id,
start,
end,
line,
file,
createMessage(id, arguments, line, file),
arguments,
warn,
error);
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int)
*/
public String[] getRequiredAttributesForId(int id) {
String [] result = new String[1];
switch (id)
{
case IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED :
case IProblem.SEMANTIC_NAME_NOT_FOUND:
case IProblem.SEMANTIC_AMBIGUOUS_LOOKUP:
result[0] = IProblem.A_SYMBOL_NAME;
break;
case IProblem.SEMANTIC_INVALID_TYPE:
result[0] = IProblem.A_TYPE_NAME;
break;
case IProblem.SEMANTIC_INVALID_USING:
result[0] = IProblem.A_NAMESPACE_NAME;
break;
case IProblem.SEMANTIC_NAME_NOT_PROVIDED:
result = new String[0];
break;
}
return result;
}
}

View file

@ -10,14 +10,15 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.Offsets;
import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator;
/**
* @author jcamelon
@ -27,18 +28,20 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
{
private final IASTScope ownerScope;
private final boolean isTypeName;
private final IASTDeclaration declaration;
private final List declarations = new ArrayList();
private Offsets offsets = new Offsets();
private final ASTReferenceStore delegate;
private final ASTReferenceStore delegate;
private String name;
/**
*
*/
public ASTUsingDeclaration( IASTScope ownerScope, IASTDeclaration declaration, boolean isTypeName, int startingOffset, int startingLine, int endingOffset, int endingLine, List references )
public ASTUsingDeclaration( IASTScope ownerScope, String name, List declarations, boolean isTypeName, int startingOffset, int startingLine, int endingOffset, int endingLine, List references )
{
this.ownerScope = ownerScope;
this.isTypeName = isTypeName;
this.declaration = declaration;
this.name = name;
this.declarations.addAll( declarations );
setStartingOffsetAndLineNumber(startingOffset, startingLine);
setEndingOffsetAndLineNumber(endingOffset, endingLine);
delegate = new ASTReferenceStore( references );
@ -55,7 +58,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
*/
public String usingTypeName()
{
return ((IASTOffsetableNamedElement)declaration).getName();
return name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
@ -122,9 +125,9 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#getUsingType()
*/
public IASTDeclaration getUsingType()
public Iterator getUsingTypes()
{
return declaration;
return new SymbolIterator( declarations.iterator() );
}
/* (non-Javadoc)

View file

@ -67,11 +67,12 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
/**
* @author jcamelon
*/
public class ExpressionParseASTFactory implements IASTFactory {
public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFactory {
private final IASTExtensionFactory extensionFactory;
@ -914,4 +915,5 @@ public class ExpressionParseASTFactory implements IASTFactory {
return null;
}
}

View file

@ -10,9 +10,10 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.Offsets;
@ -108,7 +109,7 @@ public class ASTUsingDeclaration
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#getUsingType()
*/
public IASTDeclaration getUsingType() throws ASTNotImplementedException
public Iterator getUsingTypes() throws ASTNotImplementedException
{
throw new ASTNotImplementedException();
}

View file

@ -2205,7 +2205,7 @@ public class ParserSymbolTable {
parentAccess = parent.getAccess();
symbolAccess = ((IASTMember)symbol.getASTExtension().getPrimaryDeclaration()).getVisiblity();
return ( parentAccess.getEnumValue() > symbolAccess.getEnumValue() ) ? parentAccess : symbolAccess;
return ( parentAccess.isGreaterThan( symbolAccess ) )? parentAccess : symbolAccess;
}
}
@ -2221,10 +2221,10 @@ public class ParserSymbolTable {
symbolAccess = getVisibility( symbol, (IContainerSymbol) parent.getParent() );
if( symbolAccess != null ){
symbolAccess = ( parentAccess.getEnumValue() > symbolAccess.getEnumValue() ) ? parentAccess : symbolAccess;
symbolAccess = ( parentAccess.isGreaterThan( symbolAccess ) ) ? parentAccess : symbolAccess;
if( checkAllPaths ){
if( resultingAccess != null )
resultingAccess = ( resultingAccess.getEnumValue() > symbolAccess.getEnumValue() ) ? symbolAccess : resultingAccess;
resultingAccess = resultingAccess.isGreaterThan( symbolAccess ) ? symbolAccess : resultingAccess;
else
resultingAccess = symbolAccess;
} else {

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.internal.core.parser.pst;
import org.eclipse.cdt.core.parser.IProblem;
/**
* @author aniefer
*/
@ -44,5 +46,38 @@ public class ParserSymbolTableException extends Exception {
public static final int r_BadTemplateParameter = 9;
public static final int r_RedeclaredTemplateParam = 10;
public int reason = -1;
/**
* @return
*/
public int createProblemID() {
switch( reason )
{
case r_Ambiguous:
return IProblem.SEMANTIC_AMBIGUOUS_LOOKUP;
case r_BadTypeInfo:
return IProblem.SEMANTIC_INVALID_TYPE;
case r_CircularInheritance:
return IProblem.SEMANTIC_CIRCULAR_INHERITANCE;
case r_InvalidOverload:
return IProblem.SEMANTIC_INVALID_OVERLOAD;
case r_BadTemplate:
return IProblem.SEMANTIC_INVALID_TEMPLATE;
case r_InvalidUsing:
return IProblem.SEMANTIC_INVALID_USING;
case r_BadVisibility:
return IProblem.SEMANTIC_BAD_VISIBILITY;
case r_UnableToResolveFunction:
return IProblem.SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION;
case r_BadTemplateArgument:
return IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT;
case r_BadTemplateParameter:
return IProblem.SEMANTIC_INVALID_TEMPLATE_PARAMETER;
case r_RedeclaredTemplateParam:
return IProblem.SEMANTIC_REDECLARED_TEMPLATE_PARAMETER;
default:
// assert false : this;
return -1;
}
}
}

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
@ -26,7 +28,6 @@ import java.util.StringTokenizer;
import java.util.Vector;
import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.Directives;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
@ -66,7 +67,7 @@ import org.eclipse.cdt.internal.core.parser.token.Token;
public class Scanner implements IScanner {
private final static String SCRATCH = "<scratch>"; //$NON-NLS-1$
private final static String SCRATCH = "<scratch>";
protected final IScannerData scannerData;
private boolean initialContextInitialized = false;
@ -94,7 +95,7 @@ public class Scanner implements IScanner {
IProblem problem = scannerData.getProblemFactory().createProblem( problemID, beginningOffset, getCurrentOffset(), scannerData.getContextStack().getCurrentLineNumber(), getCurrentFile().toCharArray(), arguments, warning, error );
// trace log
StringBuffer logMessage = new StringBuffer( "Scanner problem encountered: "); //$NON-NLS-1$
StringBuffer logMessage = new StringBuffer( "Scanner problem encountered: ");
logMessage.append( problem.getMessage() );
scannerData.getLogService().traceLog( logMessage.toString() );
@ -110,7 +111,7 @@ public class Scanner implements IScanner {
if( scannerExtension instanceof GCCScannerExtension )
((GCCScannerExtension)scannerExtension).setScannerData( scannerData );
scannerData.setASTFactory( ParserFactory.createASTFactory( scannerData.getParserMode(), language ) );
scannerData.setASTFactory( ParserFactory.createASTFactory( this, scannerData.getParserMode(), language ) );
try {
//this is a hack to get around a sudden EOF experience
scannerData.getContextStack().push(
@ -174,18 +175,18 @@ public class Scanner implements IScanner {
scannerExtension.setupBuiltInMacros(scannerData.getLanguage());
if( getDefinition(__STDC__) == null )
addDefinition( __STDC__, new ObjectMacroDescriptor( __STDC__, "1") ); //$NON-NLS-1$
addDefinition( __STDC__, new ObjectMacroDescriptor( __STDC__, "1") );
if( scannerData.getLanguage() == ParserLanguage.C )
{
if( getDefinition(__STDC_HOSTED__) == null )
addDefinition( __STDC_HOSTED__, new ObjectMacroDescriptor( __STDC_HOSTED__, "0")); //$NON-NLS-1$
addDefinition( __STDC_HOSTED__, new ObjectMacroDescriptor( __STDC_HOSTED__, "0"));
if( getDefinition( __STDC_VERSION__) == null )
addDefinition( __STDC_VERSION__, new ObjectMacroDescriptor( __STDC_VERSION__, "199001L")); //$NON-NLS-1$
addDefinition( __STDC_VERSION__, new ObjectMacroDescriptor( __STDC_VERSION__, "199001L"));
}
else
if( getDefinition( __CPLUSPLUS ) == null )
addDefinition( __CPLUSPLUS, new ObjectMacroDescriptor( __CPLUSPLUS, "199711L")); //$NON-NLS-1$
addDefinition( __CPLUSPLUS, new ObjectMacroDescriptor( __CPLUSPLUS, "199711L"));
if( getDefinition(__FILE__) == null )
addDefinition( __FILE__,
@ -222,17 +223,17 @@ public class Scanner implements IScanner {
if( Calendar.MONTH == Calendar.OCTOBER) return "Oct";
if( Calendar.MONTH == Calendar.NOVEMBER) return "Nov";
if( Calendar.MONTH == Calendar.DECEMBER) return "Dec";
return ""; //$NON-NLS-1$
return "";
}
public String execute() {
StringBuffer result = new StringBuffer();
result.append( getMonth() );
result.append(" "); //$NON-NLS-1$
result.append(" ");
if( Calendar.DAY_OF_MONTH < 10 )
result.append(" "); //$NON-NLS-1$
result.append(" ");
result.append(Calendar.DAY_OF_MONTH);
result.append(" "); //$NON-NLS-1$
result.append(" ");
result.append( Calendar.YEAR );
return result.toString();
}
@ -308,7 +309,6 @@ public class Scanner implements IScanner {
buffer.append( tokenizer.nextToken() );
}
file = new File( buffer.toString() );
path = buffer.toString();
}
if( file.exists() && file.isDirectory() )
@ -496,7 +496,9 @@ public class Scanner implements IScanner {
protected void handleInclusion(String fileName, boolean useIncludePaths, int beginOffset, int startLine, int nameOffset, int nameLine, int endOffset, int endLine ) throws ScannerException {
CodeReader duple = null;
FileReader inclusionReader = null;
String newPath = null;
totalLoop: for( int i = 0; i < 2; ++i )
{
if( useIncludePaths ) // search include paths for this file
@ -507,33 +509,65 @@ public class Scanner implements IScanner {
while (iter.hasNext()) {
String path = (String)iter.next();
duple = createReaderDuple( path, fileName );
if( duple != null )
break totalLoop;
File pathFile = new File(path);
//TODO assert pathFile.isDirectory();
StringBuffer buffer = new StringBuffer( pathFile.getPath() );
buffer.append( File.separatorChar );
buffer.append( fileName );
newPath = buffer.toString();
//TODO remove ".." and "." segments
File includeFile = new File(newPath);
if (includeFile.exists() && includeFile.isFile()) {
try {
inclusionReader = new FileReader(includeFile);
break totalLoop;
} catch (FileNotFoundException fnf) {
continue;
}
}
}
if (duple == null )
if (inclusionReader == null )
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
}
else // local inclusion
{
duple = createReaderDuple( new File( scannerData.getContextStack().getCurrentContext().getFilename() ).getParentFile().getAbsolutePath(), fileName );
if( duple != null )
break totalLoop;
useIncludePaths = true;
continue totalLoop;
String currentFilename = scannerData.getContextStack().getCurrentContext().getFilename();
File currentIncludeFile = new File( currentFilename );
String parentDirectory = currentIncludeFile.getParentFile().getAbsolutePath();
currentIncludeFile = null;
StringBuffer buffer = new StringBuffer( parentDirectory );
buffer.append( File.separatorChar );
buffer.append( fileName );
newPath = buffer.toString();
//TODO remove ".." and "." segments
File includeFile = new File( newPath );
if (includeFile.exists() && includeFile.isFile()) {
try {
inclusionReader = new FileReader(includeFile);
break totalLoop;
} catch (FileNotFoundException fnf) {
useIncludePaths = true;
continue totalLoop;
}
}
else
{
useIncludePaths = true;
continue totalLoop;
}
}
}
if (duple!= null) {
if (inclusionReader != null) {
IASTInclusion inclusion = null;
try
{
inclusion =
scannerData.getASTFactory().createInclusion(
fileName,
duple.getFilename(),
newPath,
!useIncludePaths,
beginOffset,
startLine,
@ -547,7 +581,7 @@ public class Scanner implements IScanner {
try
{
scannerData.getContextStack().updateContext(duple.getUnderlyingReader(), duple.getFilename(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
scannerData.getContextStack().updateContext(inclusionReader, newPath, ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
}
catch (ContextException e1)
{
@ -559,14 +593,14 @@ public class Scanner implements IScanner {
// constants
private static final int NOCHAR = -1;
private static final String TEXT = "<text>"; //$NON-NLS-1$
private static final String START = "<initial reader>"; //$NON-NLS-1$
private static final String EXPRESSION = "<expression>"; //$NON-NLS-1$
private static final String PASTING = "<pasting>"; //$NON-NLS-1$
private static final String TEXT = "<text>";
private static final String START = "<initial reader>";
private static final String EXPRESSION = "<expression>";
private static final String PASTING = "<pasting>";
private static final String DEFINED = "defined"; //$NON-NLS-1$
private static final String _PRAGMA = "_Pragma"; //$NON-NLS-1$
private static final String POUND_DEFINE = "#define "; //$NON-NLS-1$
private static final String DEFINED = "defined";
private static final String _PRAGMA = "_Pragma";
private static final String POUND_DEFINE = "#define ";
private IScannerContext lastContext = null;
@ -634,39 +668,39 @@ public class Scanner implements IScanner {
c = getChar(insideString);
switch (c) {
case '(':
expandDefinition("??(", "[", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??(", "[", baseOffset);
c = getChar(insideString);
break;
case ')':
expandDefinition("??)", "]", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??)", "]", baseOffset);
c = getChar(insideString);
break;
case '<':
expandDefinition("??<", "{", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??<", "{", baseOffset);
c = getChar(insideString);
break;
case '>':
expandDefinition("??>", "}", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??>", "}", baseOffset);
c = getChar(insideString);
break;
case '=':
expandDefinition("??=", "#", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??=", "#", baseOffset);
c = getChar(insideString);
break;
case '/':
expandDefinition("??/", "\\", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??/", "\\", baseOffset);
c = getChar(insideString);
break;
case '\'':
expandDefinition("??\'", "^", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??\'", "^", baseOffset);
c = getChar(insideString);
break;
case '!':
expandDefinition("??!", "|", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??!", "|", baseOffset);
c = getChar(insideString);
break;
case '-':
expandDefinition("??-", "~", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("??-", "~", baseOffset);
c = getChar(insideString);
break;
default:
@ -709,10 +743,10 @@ public class Scanner implements IScanner {
if (c == '<') {
c = getChar(false);
if (c == '%') {
expandDefinition("<%", "{", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("<%", "{", baseOffset);
c = getChar(false);
} else if (c == ':') {
expandDefinition("<:", "[", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("<:", "[", baseOffset);
c = getChar(false);
} else {
// Not a digraph
@ -722,7 +756,7 @@ public class Scanner implements IScanner {
} else if (c == ':') {
c = getChar(false);
if (c == '>') {
expandDefinition(":>", "]", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition(":>", "]", baseOffset);
c = getChar(false);
} else {
// Not a digraph
@ -732,10 +766,10 @@ public class Scanner implements IScanner {
} else if (c == '%') {
c = getChar(false);
if (c == '>') {
expandDefinition("%>", "}", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("%>", "}", baseOffset);
c = getChar(false);
} else if (c == ':') {
expandDefinition("%:", "#", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
expandDefinition("%:", "#", baseOffset);
c = getChar(false);
} else {
// Not a digraph
@ -1081,17 +1115,17 @@ public class Scanner implements IScanner {
if( ! firstCharZero && floatingPoint && !(c >= '0' && c <= '9') ){
//if pasting, there could actually be a float here instead of just a .
if( buff.toString().equals( "." ) ){ //$NON-NLS-1$
if( buff.toString().equals( "." ) ){
if( c == '*' ){
return newToken( IToken.tDOTSTAR, ".*", scannerData.getContextStack().getCurrentContext() ); //$NON-NLS-1$
return newToken( IToken.tDOTSTAR, ".*", scannerData.getContextStack().getCurrentContext() );
} else if( c == '.' ){
if( getChar() == '.' )
return newToken( IToken.tELLIPSIS, "...", scannerData.getContextStack().getCurrentContext() ); //$NON-NLS-1$
return newToken( IToken.tELLIPSIS, "...", scannerData.getContextStack().getCurrentContext() );
else
handleProblem( IProblem.SCANNER_BAD_FLOATING_POINT, null, beginOffset, false, true );
} else {
ungetChar( c );
return newToken( IToken.tDOT, ".", scannerData.getContextStack().getCurrentContext() ); //$NON-NLS-1$
return newToken( IToken.tDOT, ".", scannerData.getContextStack().getCurrentContext() );
}
}
} else if (c == 'x') {
@ -1212,7 +1246,7 @@ public class Scanner implements IScanner {
int tokenType;
String result = buff.toString();
if( floatingPoint && result.equals(".") ) //$NON-NLS-1$
if( floatingPoint && result.equals(".") )
tokenType = IToken.tDOT;
else
tokenType = floatingPoint ? IToken.tFLOATINGPT : IToken.tINTEGER;
@ -1238,12 +1272,12 @@ public class Scanner implements IScanner {
if( c == '#' )
{
if( skipped )
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "# #", beginningOffset, false, true ); //$NON-NLS-1$
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "# #", beginningOffset, false, true );
else
return newToken( tPOUNDPOUND, "##" ); //$NON-NLS-1$
return newToken( tPOUNDPOUND, "##" );
} else if( tokenizingMacroReplacementList ) {
ungetChar( c );
return newToken( tPOUND, "#" ); //$NON-NLS-1$
return newToken( tPOUND, "#" );
}
while (((c >= 'a') && (c <= 'z'))
@ -1263,7 +1297,7 @@ public class Scanner implements IScanner {
if (directive == null) {
if( scannerExtension.canHandlePreprocessorDirective( token ) )
scannerExtension.handlePreprocessorDirective( token, getRestOfPreprocessorLine() );
StringBuffer buffer = new StringBuffer( "#"); //$NON-NLS-1$
StringBuffer buffer = new StringBuffer( "#");
buffer.append( token );
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, buffer.toString(), beginningOffset, false, true );
} else {
@ -1320,8 +1354,8 @@ public class Scanner implements IScanner {
if( isLimitReached() )
handleCompletionOnExpression( expression );
if (expression.trim().equals("")) //$NON-NLS-1$
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#if", beginningOffset, false, true ); //$NON-NLS-1$
if (expression.trim().equals(""))
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#if", beginningOffset, false, true );
boolean expressionEvalResult = false;
@ -1355,9 +1389,9 @@ public class Scanner implements IScanner {
if( isLimitReached() )
handleInvalidCompletion();
if( ! restOfLine.equals( "" ) ) //$NON-NLS-1$
if( ! restOfLine.equals( "" ) )
{
StringBuffer buffer = new StringBuffer("#endif "); //$NON-NLS-1$
StringBuffer buffer = new StringBuffer("#endif ");
buffer.append( restOfLine );
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, buffer.toString(), beginningOffset, false, true );
}
@ -1415,8 +1449,8 @@ public class Scanner implements IScanner {
handleCompletionOnExpression( elifExpression );
if (elifExpression.equals("")) //$NON-NLS-1$
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#elif", beginningOffset, false, true ); //$NON-NLS-1$
if (elifExpression.equals(""))
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#elif", beginningOffset, false, true );
boolean elsifResult = false;
if( scannerData.getBranchTracker().queryCurrentBranchForElif() )
@ -1467,15 +1501,15 @@ public class Scanner implements IScanner {
case PreprocessorDirectives.BLANK :
String remainderOfLine =
getRestOfPreprocessorLine().trim();
if (!remainderOfLine.equals("")) { //$NON-NLS-1$
StringBuffer buffer = new StringBuffer( "# "); //$NON-NLS-1$
if (!remainderOfLine.equals("")) {
StringBuffer buffer = new StringBuffer( "# ");
buffer.append( remainderOfLine );
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, buffer.toString(), beginningOffset, false, true);
}
c = getChar();
continue;
default :
StringBuffer buffer = new StringBuffer( "# "); //$NON-NLS-1$
StringBuffer buffer = new StringBuffer( "# ");
buffer.append( token );
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, buffer.toString(), beginningOffset, false, true );
}
@ -1490,51 +1524,51 @@ public class Scanner implements IScanner {
case ':' :
return newToken(
IToken.tCOLONCOLON,
"::", //$NON-NLS-1$
"::",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tCOLON,
":", //$NON-NLS-1$
":",
scannerData.getContextStack().getCurrentContext());
}
case ';' :
return newToken(IToken.tSEMI, ";", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tSEMI, ";", scannerData.getContextStack().getCurrentContext());
case ',' :
return newToken(IToken.tCOMMA, ",", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tCOMMA, ",", scannerData.getContextStack().getCurrentContext());
case '?' :
return newToken(IToken.tQUESTION, "?", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tQUESTION, "?", scannerData.getContextStack().getCurrentContext());
case '(' :
return newToken(IToken.tLPAREN, "(", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tLPAREN, "(", scannerData.getContextStack().getCurrentContext());
case ')' :
return newToken(IToken.tRPAREN, ")", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tRPAREN, ")", scannerData.getContextStack().getCurrentContext());
case '[' :
return newToken(IToken.tLBRACKET, "[", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tLBRACKET, "[", scannerData.getContextStack().getCurrentContext());
case ']' :
return newToken(IToken.tRBRACKET, "]", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tRBRACKET, "]", scannerData.getContextStack().getCurrentContext());
case '{' :
return newToken(IToken.tLBRACE, "{", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tLBRACE, "{", scannerData.getContextStack().getCurrentContext());
case '}' :
return newToken(IToken.tRBRACE, "}", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tRBRACE, "}", scannerData.getContextStack().getCurrentContext());
case '+' :
c = getChar();
switch (c) {
case '=' :
return newToken(
IToken.tPLUSASSIGN,
"+=", //$NON-NLS-1$
"+=",
scannerData.getContextStack().getCurrentContext());
case '+' :
return newToken(
IToken.tINCR,
"++", //$NON-NLS-1$
"++",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tPLUS,
"+", //$NON-NLS-1$
"+",
scannerData.getContextStack().getCurrentContext());
}
case '-' :
@ -1543,12 +1577,12 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tMINUSASSIGN,
"-=", //$NON-NLS-1$
"-=",
scannerData.getContextStack().getCurrentContext());
case '-' :
return newToken(
IToken.tDECR,
"--", //$NON-NLS-1$
"--",
scannerData.getContextStack().getCurrentContext());
case '>' :
c = getChar();
@ -1556,20 +1590,20 @@ public class Scanner implements IScanner {
case '*' :
return newToken(
IToken.tARROWSTAR,
"->*", //$NON-NLS-1$
"->*",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tARROW,
"->", //$NON-NLS-1$
"->",
scannerData.getContextStack().getCurrentContext());
}
default :
ungetChar(c);
return newToken(
IToken.tMINUS,
"-", //$NON-NLS-1$
"-",
scannerData.getContextStack().getCurrentContext());
}
case '*' :
@ -1578,13 +1612,13 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tSTARASSIGN,
"*=", //$NON-NLS-1$
"*=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tSTAR,
"*", //$NON-NLS-1$
"*",
scannerData.getContextStack().getCurrentContext());
}
case '%' :
@ -1593,13 +1627,13 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tMODASSIGN,
"%=", //$NON-NLS-1$
"%=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tMOD,
"%", //$NON-NLS-1$
"%",
scannerData.getContextStack().getCurrentContext());
}
case '^' :
@ -1608,13 +1642,13 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tXORASSIGN,
"^=", //$NON-NLS-1$
"^=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tXOR,
"^", //$NON-NLS-1$
"^",
scannerData.getContextStack().getCurrentContext());
}
case '&' :
@ -1623,18 +1657,18 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tAMPERASSIGN,
"&=", //$NON-NLS-1$
"&=",
scannerData.getContextStack().getCurrentContext());
case '&' :
return newToken(
IToken.tAND,
"&&", //$NON-NLS-1$
"&&",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tAMPER,
"&", //$NON-NLS-1$
"&",
scannerData.getContextStack().getCurrentContext());
}
case '|' :
@ -1643,35 +1677,35 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tBITORASSIGN,
"|=", //$NON-NLS-1$
"|=",
scannerData.getContextStack().getCurrentContext());
case '|' :
return newToken(
IToken.tOR,
"||", //$NON-NLS-1$
"||",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tBITOR,
"|", //$NON-NLS-1$
"|",
scannerData.getContextStack().getCurrentContext());
}
case '~' :
return newToken(IToken.tCOMPL, "~", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tCOMPL, "~", scannerData.getContextStack().getCurrentContext());
case '!' :
c = getChar();
switch (c) {
case '=' :
return newToken(
IToken.tNOTEQUAL,
"!=", //$NON-NLS-1$
"!=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tNOT,
"!", //$NON-NLS-1$
"!",
scannerData.getContextStack().getCurrentContext());
}
case '=' :
@ -1680,13 +1714,13 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tEQUAL,
"==", //$NON-NLS-1$
"==",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tASSIGN,
"=", //$NON-NLS-1$
"=",
scannerData.getContextStack().getCurrentContext());
}
case '<' :
@ -1698,25 +1732,25 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tSHIFTLASSIGN,
"<<=", //$NON-NLS-1$
"<<=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tSHIFTL,
"<<", //$NON-NLS-1$
"<<",
scannerData.getContextStack().getCurrentContext());
}
case '=' :
return newToken(
IToken.tLTEQUAL,
"<=", //$NON-NLS-1$
"<=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
if( forInclusion )
temporarilyReplaceDefinitionsMap();
return newToken(IToken.tLT, "<", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tLT, "<", scannerData.getContextStack().getCurrentContext());
}
case '>' :
c = getChar();
@ -1727,25 +1761,25 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tSHIFTRASSIGN,
">>=", //$NON-NLS-1$
">>=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tSHIFTR,
">>", //$NON-NLS-1$
">>",
scannerData.getContextStack().getCurrentContext());
}
case '=' :
return newToken(
IToken.tGTEQUAL,
">=", //$NON-NLS-1$
">=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
if( forInclusion )
restoreDefinitionsMap();
return newToken(IToken.tGT, ">", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tGT, ">", scannerData.getContextStack().getCurrentContext());
}
case '.' :
c = getChar();
@ -1756,7 +1790,7 @@ public class Scanner implements IScanner {
case '.' :
return newToken(
IToken.tELLIPSIS,
"...", //$NON-NLS-1$
"...",
scannerData.getContextStack().getCurrentContext());
default :
break;
@ -1765,13 +1799,13 @@ public class Scanner implements IScanner {
case '*' :
return newToken(
IToken.tDOTSTAR,
".*", //$NON-NLS-1$
".*",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tDOT,
".", //$NON-NLS-1$
".",
scannerData.getContextStack().getCurrentContext());
}
break;
@ -1789,13 +1823,13 @@ public class Scanner implements IScanner {
case '=' :
return newToken(
IToken.tDIVASSIGN,
"/=", //$NON-NLS-1$
"/=",
scannerData.getContextStack().getCurrentContext());
default :
ungetChar(c);
return newToken(
IToken.tDIV,
"/", //$NON-NLS-1$
"/",
scannerData.getContextStack().getCurrentContext());
}
default :
@ -1838,9 +1872,9 @@ public class Scanner implements IScanner {
int completionPoint = expression.length() + 2;
IASTCompletionNode.CompletionKind kind = IASTCompletionNode.CompletionKind.MACRO_REFERENCE;
String prefix = ""; //$NON-NLS-1$
String prefix = "";
if( ! expression.trim().equals("")) //$NON-NLS-1$
if( ! expression.trim().equals(""))
{
IScanner subScanner = ParserFactory.createScanner( new StringReader(expression), SCRATCH, EMPTY_INFO, ParserMode.QUICK_PARSE, scannerData.getLanguage(), new NullSourceElementRequestor(), new NullLogService());
IToken lastToken = null;
@ -1883,7 +1917,7 @@ public class Scanner implements IScanner {
protected void handleInvalidCompletion() throws EndOfFileException
{
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, "", KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()) )); //$NON-NLS-1$
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, "", KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()) ));
}
protected void handleCompletionOnPreprocessorDirective( String prefix ) throws EndOfFileException
@ -1948,7 +1982,7 @@ public class Scanner implements IScanner {
protected String getCurrentFile()
{
return scannerData.getContextStack().getMostRelevantFileContext() != null ? scannerData.getContextStack().getMostRelevantFileContext().getFilename() : ""; //$NON-NLS-1$
return scannerData.getContextStack().getMostRelevantFileContext() != null ? scannerData.getContextStack().getMostRelevantFileContext().getFilename() : "";
}
@ -2009,13 +2043,13 @@ public class Scanner implements IScanner {
return processCharacterLiteral( c, false );
case ',' :
if (tokenImage.length() > 0) throw endOfMacroToken;
return newToken(IToken.tCOMMA, ",", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tCOMMA, ",", scannerData.getContextStack().getCurrentContext());
case '(' :
if (tokenImage.length() > 0) throw endOfMacroToken;
return newToken(IToken.tLPAREN, "(", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tLPAREN, "(", scannerData.getContextStack().getCurrentContext());
case ')' :
if (tokenImage.length() > 0) throw endOfMacroToken;
return newToken(IToken.tRPAREN, ")", scannerData.getContextStack().getCurrentContext()); //$NON-NLS-1$
return newToken(IToken.tRPAREN, ")", scannerData.getContextStack().getCurrentContext());
case '/' :
if (tokenImage.length() > 0) throw endOfMacroToken;
c = getChar();
@ -2231,7 +2265,7 @@ public class Scanner implements IScanner {
if( scannerData.getParserMode() == ParserMode.QUICK_PARSE )
{
if( expression.trim().equals( "0" ) ) //$NON-NLS-1$
if( expression.trim().equals( "0" ) )
return false;
return true;
@ -2275,7 +2309,7 @@ public class Scanner implements IScanner {
protected void skipOverSinglelineComment() throws ScannerException, EndOfFileException {
StringBuffer comment = new StringBuffer("//"); //$NON-NLS-1$
StringBuffer comment = new StringBuffer("//");
int c;
loop:
@ -2298,7 +2332,7 @@ public class Scanner implements IScanner {
protected boolean skipOverMultilineComment() throws ScannerException, EndOfFileException {
int state = 0;
boolean encounteredNewline = false;
StringBuffer comment = new StringBuffer("/*"); //$NON-NLS-1$
StringBuffer comment = new StringBuffer("/*");
// simple state machine to handle multi-line comments
// state 0 == no end of comment in site
// state 1 == encountered *, expecting /
@ -2337,7 +2371,7 @@ public class Scanner implements IScanner {
}
protected void poundInclude( int beginningOffset, int startLine ) throws ScannerException, EndOfFileException {
StringBuffer potentialErrorLine = new StringBuffer( "#include "); //$NON-NLS-1$
StringBuffer potentialErrorLine = new StringBuffer( "#include ");
skipOverWhitespace();
int baseOffset = lastContext.getOffset() - lastContext.undoStackSize();
int nameLine = scannerData.getContextStack().getCurrentLineNumber();
@ -2348,7 +2382,7 @@ public class Scanner implements IScanner {
int startOffset = baseOffset;
int endOffset = baseOffset;
if (! includeLine.equals("")) { //$NON-NLS-1$
if (! includeLine.equals("")) {
Scanner helperScanner = new Scanner(
new StringReader(includeLine),
null,
@ -2429,7 +2463,7 @@ public class Scanner implements IScanner {
i =
scannerData.getASTFactory().createInclusion(
f,
"", //$NON-NLS-1$
"",
!useIncludePath,
beginningOffset,
startLine,
@ -2481,7 +2515,7 @@ public class Scanner implements IScanner {
protected List tokenizeReplacementString( int beginning, String key, String replacementString, List parameterIdentifiers )
{
List macroReplacementTokens = new ArrayList();
if( replacementString.trim().equals( "" ) ) //$NON-NLS-1$
if( replacementString.trim().equals( "" ) )
return macroReplacementTokens;
IScanner helperScanner=null;
try {
@ -2602,7 +2636,7 @@ public class Scanner implements IScanner {
String parameters = buffer.toString();
// replace StringTokenizer later -- not performant
StringTokenizer tokenizer = new StringTokenizer(parameters, ","); //$NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(parameters, ",");
ArrayList parameterIdentifiers =
new ArrayList(tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
@ -2615,7 +2649,7 @@ public class Scanner implements IScanner {
String replacementString = getRestOfPreprocessorLine();
macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$
macroReplacementTokens = ( ! replacementString.equals( "" ) ) ?
tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) :
EMPTY_LIST;
@ -2623,7 +2657,7 @@ public class Scanner implements IScanner {
fullSignature.append( key );
fullSignature.append( '(');
fullSignature.append( parameters );
fullSignature.append( ") "); //$NON-NLS-1$
fullSignature.append( ") ");
fullSignature.append( replacementString );
descriptor = new FunctionMacroDescriptor(
key,
@ -2638,8 +2672,8 @@ public class Scanner implements IScanner {
}
else if ((c == '\n') || (c == '\r'))
{
checkValidMacroRedefinition(key, previousDefinition, "", beginning); //$NON-NLS-1$
addDefinition( key, "" ); //$NON-NLS-1$
checkValidMacroRedefinition(key, previousDefinition, "", beginning);
addDefinition( key, "" );
}
else if ((c == ' ') || (c == '\t') ) {
// this is a simple definition
@ -2657,33 +2691,33 @@ public class Scanner implements IScanner {
if (c == '/') // one line comment
{
skipOverSinglelineComment();
checkValidMacroRedefinition(key, previousDefinition, "", beginning); //$NON-NLS-1$
addDefinition(key, ""); //$NON-NLS-1$
checkValidMacroRedefinition(key, previousDefinition, "", beginning);
addDefinition(key, "");
} else if (c == '*') // multi-line comment
{
if (skipOverMultilineComment()) {
// we have gone over a newline
// therefore, this symbol was defined to an empty string
checkValidMacroRedefinition(key, previousDefinition, "", beginning); //$NON-NLS-1$
addDefinition(key, ""); //$NON-NLS-1$
checkValidMacroRedefinition(key, previousDefinition, "", beginning);
addDefinition(key, "");
} else {
String value = getRestOfPreprocessorLine();
checkValidMacroRedefinition(key, previousDefinition, "", beginning); //$NON-NLS-1$
checkValidMacroRedefinition(key, previousDefinition, "", beginning);
addDefinition(key, value);
}
} else {
// this is not a comment
// it is a bad statement
potentialErrorMessage.append( key );
potentialErrorMessage.append( " /"); //$NON-NLS-1$
potentialErrorMessage.append( " /");
potentialErrorMessage.append( getRestOfPreprocessorLine() );
handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, potentialErrorMessage.toString(), beginning, false, true );
return;
}
} else {
potentialErrorMessage = new StringBuffer();
potentialErrorMessage.append( "#define"); //$NON-NLS-1$
potentialErrorMessage.append( "#define");
potentialErrorMessage.append( key );
potentialErrorMessage.append( (char)c );
potentialErrorMessage.append( getRestOfPreprocessorLine() );
@ -2798,7 +2832,7 @@ public class Scanner implements IScanner {
buffer.append('\"');
break;
case IToken.tLSTRING :
buffer.append( "L\""); //$NON-NLS-1$
buffer.append( "L\"");
buffer.append(t.getImage());
buffer.append('\"');
break;
@ -2958,7 +2992,7 @@ public class Scanner implements IScanner {
buffer.append('\"');
break;
case IToken.tLSTRING:
buffer.append("L\""); //$NON-NLS-1$
buffer.append("L\"");
buffer.append(t.getImage());
buffer.append('\"');
break;
@ -2987,7 +3021,7 @@ public class Scanner implements IScanner {
if( t.getType() != tPOUNDPOUND && ! pastingNext )
if (i < (numberOfTokens-1)) // Do not append to the last one
buffer.append( " " ); //$NON-NLS-1$
buffer.append( " " );
}
String finalString = buffer.toString();
try
@ -3013,7 +3047,7 @@ public class Scanner implements IScanner {
}
else {
StringBuffer logMessage = new StringBuffer( "Unexpected type of MacroDescriptor stored in definitions table: " ); //$NON-NLS-1$
StringBuffer logMessage = new StringBuffer( "Unexpected type of MacroDescriptor stored in definitions table: " );
logMessage.append( expansion.getMacroType() );
scannerData.getLogService().traceLog( logMessage.toString() );
}
@ -3034,8 +3068,8 @@ public class Scanner implements IScanner {
c = getChar();
if (c != ')')
{
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, "defined()", o, false, true ); //$NON-NLS-1$
return "0"; //$NON-NLS-1$
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, "defined()", o, false, true );
return "0";
}
}
else
@ -3045,9 +3079,9 @@ public class Scanner implements IScanner {
}
if (getDefinition(definitionIdentifier) != null)
return "1"; //$NON-NLS-1$
return "1";
return "0"; //$NON-NLS-1$
return "0";
}
public void setThrowExceptionOnBadCharacterRead( boolean throwOnBad ){
@ -3093,55 +3127,11 @@ public class Scanner implements IScanner {
*/
public boolean isOnTopContext() {
return ( scannerData.getContextStack().getCurrentContext() == scannerData.getContextStack().getTopContext() );
}
protected CodeReader createReaderDuple( String path, String fileName )
{
File pathFile = new File(path);
//TODO assert pathFile.isDirectory();
StringBuffer newPathBuffer = new StringBuffer( pathFile.getPath() );
newPathBuffer.append( File.separatorChar );
newPathBuffer.append( fileName );
//remove ".." and "." segments
String finalPath = reconcilePath( newPathBuffer.toString() );
Reader r = scannerData.getClientRequestor().createReader( finalPath );
if( r != null )
return new CodeReader( finalPath, r );
return null;
}
/**
* @param string
* @return
} /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFilename()
*/
private String reconcilePath(String originalPath ) {
if( originalPath == null ) return null;
String [] segments = originalPath.split( "[/\\\\]" ); //$NON-NLS-1$
if( segments.length == 1 ) return originalPath;
Vector results = new Vector();
for( int i = 0; i < segments.length; ++i )
{
String segment = segments[i];
if( segment.equals( ".") ) continue; //$NON-NLS-1$
if( segment.equals("..") ) //$NON-NLS-1$
{
if( results.size() > 0 )
results.removeElementAt( results.size() - 1 );
}
else
results.add( segment );
}
StringBuffer buffer = new StringBuffer();
Iterator i = results.iterator();
while( i.hasNext() )
{
buffer.append( (String)i.next() );
if( i.hasNext() )
buffer.append( File.separatorChar );
}
scannerData.getLogService().traceLog( "Path has been reduced to " + buffer.toString()); //$NON-NLS-1$
return buffer.toString();
public char[] getCurrentFilename() {
return getCurrentFile().toCharArray();
}
}

View file

@ -22,8 +22,9 @@ import org.eclipse.cdt.internal.core.parser.problem.*;
*/
public class ScannerProblemFactory extends BaseProblemFactory implements IProblemFactory
{
protected static Map errorMessages = new HashMap();
protected static final Map errorMessages;
static {
errorMessages = new HashMap();
errorMessages.put(
new Integer(IProblem.PREPROCESSOR_POUND_ERROR),
"#error encountered with text: ");

View file

@ -28,6 +28,7 @@ public class TokenDuple implements ITokenDuple {
public TokenDuple( IToken first, IToken last )
{
// assert ( first != null && last != null ) : this;
firstToken = first;
lastToken = last;
}
@ -190,4 +191,22 @@ public class TokenDuple implements ITokenDuple {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getEndOffset()
*/
public int getEndOffset() {
return getLastToken().getEndOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getLineNumber()
*/
public int getLineNumber() {
return getFirstToken().getLineNumber();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
*/
public int getStartOffset() {
return getFirstToken().getOffset();
}
}

View file

@ -1,3 +1,6 @@
2004-03-03 John Camelon
Cleaned up usage of Enum.getValue() wrt encapsulation of enumerator value.
2004-03-02 Tanya Wolff
Fixed missing key for Working Set name and content on

View file

@ -189,7 +189,6 @@ public abstract class FindAction extends Action {
}
catch (ParseError er){
ParseErrorKind per = er.getErrorKind();
int val = per.getEnumValue();
er.printStackTrace();
}
catch (Exception ex){