Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Parser patch - Expression callbacks in DOM for initDeclarator's

CDT Core Patch

2003-03-19	John Camelon
	Updated Parser method visibility to solidify external interface.  
	Solved and removed TODO's from Scanner implementation.
	Updated Parser and callbacks to handle basic expressions.  

CDT UI Tests Patch

2003-03-19 John Camelon
	Updated DOMTests for assignmentExpressions off of declarators. 
	Updated ExprEvalTest for Parser signature changes relating to
adjustments to Expression callbacks.

Index: dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java,v
retrieving revision 1.5
diff -u -r1.5 DOMBuilder.java
--- dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java	19 Mar 2003 16:12:00 -0000	1.5
+++ dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java	20 Mar 2003 00:23:20 -0000
@@ -114,13 +114,17 @@
 	/**
 	 * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionOperator(org.eclipse.cdt.internal.core.newparser.Token)
 	 */
-	public void expressionOperator(Token operator) throws Exception {
+	public void expressionOperator(Object expression, Token operator) throws Exception {
+		Expression e = (Expression)expression;
+		e.add( operator ); 
 	}
 
 	/**
 	 * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionTerminal(org.eclipse.cdt.internal.core.newparser.Token)
 	 */
-	public void expressionTerminal(Token terminal) throws Exception {
+	public void expressionTerminal(Object expression, Token terminal) throws Exception {
+		Expression e = (Expression)expression;
+		e.add( terminal );
 	}
 
 	/**
@@ -268,7 +272,10 @@
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionBegin(java.lang.Object)
 	 */
 	public Object expressionBegin(Object container) {
-		return null;
+		IExpressionOwner owner = (IExpressionOwner)container;
+		Expression expression = new Expression();
+		owner.setExpression(expression); 
+		return expression;
 	}
 	/**
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionEnd(java.lang.Object)
@@ -327,6 +334,12 @@
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
 	 */
 	public void simpleDeclSpecifierName(Object declaration) {
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionAbort(java.lang.Object)
+	 */
+	public void expressionAbort(Object expression) {
 	}
 
 }
Index: dom/org/eclipse/cdt/internal/core/dom/Declarator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Declarator.java,v
retrieving revision 1.3
diff -u -r1.3 Declarator.java
--- dom/org/eclipse/cdt/internal/core/dom/Declarator.java	12 Mar 2003 15:35:41 -0000	1.3
+++ dom/org/eclipse/cdt/internal/core/dom/Declarator.java	20 Mar 2003 00:23:20 -0000
@@ -4,7 +4,7 @@
 import org.eclipse.cdt.internal.core.parser.util.Name;
 
 
-public class Declarator {
+public class Declarator implements IExpressionOwner {
 	
 	public Declarator(DeclSpecifier.Container declaration) {
 		this.declaration = declaration;
@@ -59,6 +59,22 @@
 	 */
 	public ParameterDeclarationClause getParms() {
 		return parms;
+	}
+
+	private Expression expression = null; 
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression()
+	 */
+	public Expression getExpression() {
+		return expression;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression)
+	 */
+	public void setExpression(Expression exp) {
+		expression = exp;
 	}
 
 }
Index: dom/org/eclipse/cdt/internal/core/dom/Expression.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/Expression.java
diff -N dom/org/eclipse/cdt/internal/core/dom/Expression.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/Expression.java	20 Mar 2003 00:23:20 -0000
@@ -0,0 +1,39 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software 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:	John Camelon 
+ * Rational Software - Initial API and implementation
+***********************************************************************/
+
+package org.eclipse.cdt.internal.core.dom;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.internal.core.parser.Token;
+
+/**
+ * @author jcamelon
+ *
+ * To change this generated comment go to 
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class Expression {
+
+	private List tokens = new ArrayList(); 
+	
+	public void add( Token t )
+	{
+		tokens.add( t ); 
+	}
+
+	public List tokens()
+	{
+		return tokens;	
+	}
+
+}
Index: dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java
diff -N dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java	20 Mar 2003 00:23:20 -0000
@@ -0,0 +1,18 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software 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: 
+ * Rational Software - Initial API and implementation
+ ***********************************************************************/
+
+package org.eclipse.cdt.internal.core.dom;
+
+public interface IExpressionOwner {
+
+	public Expression getExpression(); 
+	public void setExpression( Expression exp );
+}
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.5
diff -u -r1.5 ChangeLog
--- parser/ChangeLog	19 Mar 2003 16:12:00 -0000	1.5
+++ parser/ChangeLog	20 Mar 2003 00:23:20 -0000
@@ -1,3 +1,8 @@
+2003-03-19	John Camelon
+	Updated Parser method visibility to solidify external interface.  
+	Solved and removed TODO's from Scanner implementation.
+	Updated Parser and callbacks to handle basic expressions.  
+
 2003-03-18 John Camelon
 	Updated IParserCallback (and implementations) to add a typeName to DeclSpecifier. 
 	Updated IParserCallback and NewModelBuilder to distinguish between Function declarations and definitions. 
Index: parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java,v
retrieving revision 1.7
diff -u -r1.7 NewModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java	19 Mar 2003 16:12:00 -0000	1.7
+++ parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java	20 Mar 2003 00:23:21 -0000
@@ -242,13 +242,13 @@
 	/**
 	 * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionOperator(org.eclipse.cdt.internal.core.newparser.Token)
 	 */
-	public void expressionOperator(Token operator) throws Exception {
+	public void expressionOperator(Object expression, Token operator) throws Exception {
 	}
 
 	/**
 	 * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionTerminal(org.eclipse.cdt.internal.core.newparser.Token)
 	 */
-	public void expressionTerminal(Token terminal) throws Exception {
+	public void expressionTerminal(Object expression, Token terminal) throws Exception {
 	}
 
 	/**
@@ -356,6 +356,14 @@
 	public void simpleDeclSpecifierName(Object declaration) {
 		DeclSpecifier declSpecifier = (DeclSpecifier)declaration;  
 		declSpecifier.setName( currName ); 
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionAbort(java.lang.Object)
+	 */
+	public void expressionAbort(Object expression) {
+		// TODO Auto-generated method stub
+		
 	}
 
 }
Index: parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java,v
retrieving revision 1.6
diff -u -r1.6 ExpressionEvaluator.java
--- parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java	19 Mar 2003 16:11:59 -0000	1.6
+++ parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java	20 Mar 2003 00:23:21 -0000
@@ -30,7 +30,7 @@
 	/**
 	 * @see org.eclipse.cdt.core.newparser.IParserCallback#expressionOperator(Token)
 	 */
-	public void expressionOperator(Token operator) throws Exception {
+	public void expressionOperator(Object expression, Token operator) throws Exception {
 		
 		int second = popInt(); 
 		int first; 
@@ -95,7 +95,7 @@
 	/**
 	 * @see org.eclipse.cdt.core.newparser.IParserCallback#expressionTerminal(Token)
 	 */
-	public void expressionTerminal(Token terminal) throws Exception {
+	public void expressionTerminal(Object expression, Token terminal) throws Exception {
 		switch (terminal.getType()) {
 			case Token.tINTEGER:
 				stack.push(new Integer(terminal.getImage()));
@@ -304,6 +304,14 @@
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
 	 */
 	public void simpleDeclSpecifierName(Object declaration) {
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionAbort(java.lang.Object)
+	 */
+	public void expressionAbort(Object expression) {
+		// TODO Auto-generated method stub
+		
 	}
 
 }
Index: parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java,v
retrieving revision 1.5
diff -u -r1.5 IParserCallback.java
--- parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java	19 Mar 2003 16:11:59 -0000	1.5
+++ parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java	20 Mar 2003 00:23:21 -0000
@@ -54,8 +54,9 @@
 	public void  	baseSpecifierEnd( Object baseSpecifier );
 	
 	public Object 	expressionBegin( Object container ); 
-	public void 	expressionOperator(Token operator) throws Exception;
-	public void 	expressionTerminal(Token terminal) throws Exception;
+	public void 	expressionOperator(Object expression, Token operator) throws Exception;
+	public void 	expressionTerminal(Object expression, Token terminal) throws Exception;
+	public void     expressionAbort( Object expression ); 
 	public void 	expressionEnd(Object expression );
 	
 	public Object	elaboratedTypeSpecifierBegin( Object container, Token classKey ); 
Index: parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java,v
retrieving revision 1.5
diff -u -r1.5 NullParserCallback.java
--- parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java	19 Mar 2003 16:11:59 -0000	1.5
+++ parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java	20 Mar 2003 00:23:21 -0000
@@ -105,13 +105,13 @@
 	/**
 	 * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionOperator(Token)
 	 */
-	public void expressionOperator(Token operator) throws Exception {
+	public void expressionOperator(Object expression, Token operator) throws Exception {
 	}
 
 	/**
 	 * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionTerminal(Token)
 	 */
-	public void expressionTerminal(Token terminal) throws Exception {
+	public void expressionTerminal(Object expression, Token terminal) throws Exception {
 	}
 
 	/**
@@ -220,6 +220,14 @@
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
 	 */
 	public void simpleDeclSpecifierName(Object declaration) {
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionAbort(java.lang.Object)
+	 */
+	public void expressionAbort(Object expression) {
+		// TODO Auto-generated method stub
+		
 	}
 
 }
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.11
diff -u -r1.11 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java	19 Mar 2003 16:11:59 -0000	1.11
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java	20 Mar 2003 00:23:22 -0000
@@ -74,7 +74,7 @@
 	 * : (declaration)*
 	 * 
 	 */
-	public void translationUnit() throws Exception {
+	protected void translationUnit() throws Exception {
 		Object translationUnit = callback.translationUnitBegin();
 		Token lastBacktrack = null;
 		Token lastToken;
@@ -130,7 +130,7 @@
 	 *   - explicitInstantiation and explicitSpecialization into
 	 *       templateDeclaration
 	 */
-	public void declaration( Object container ) throws Exception {
+	protected void declaration( Object container ) throws Exception {
 		switch (LT(1)) {
 			case Token.t_asm:
 				// asmDefinition( );
@@ -176,7 +176,7 @@
 	 * To do:
 	 * - work in ctorInitializer and functionTryBlock
 	 */
-	public void simpleDeclaration( Object container ) throws Exception {
+	protected void simpleDeclaration( Object container ) throws Exception {
 		Object simpleDecl = callback.simpleDeclarationBegin( container);
 		declSpecifierSeq(simpleDecl, false);
 
@@ -239,7 +239,7 @@
 	}
 	
 	
-	public void parameterDeclaration( Object containerObject ) throws Exception
+	protected void parameterDeclaration( Object containerObject ) throws Exception
 	{
 		Object parameterDecl = callback.parameterDeclarationBegin( containerObject );
 		declSpecifierSeq( parameterDecl, true );
@@ -273,7 +273,7 @@
 	 * - folded elaboratedTypeSpecifier into classSpecifier and enumSpecifier
 	 * - find template names in name
 	 */
-	public void declSpecifierSeq( Object decl, boolean parm ) throws Exception {
+	protected void declSpecifierSeq( Object decl, boolean parm ) throws Exception {
 		boolean encounteredTypename = false;
 		boolean encounteredRawType = false;
 		declSpecifiers:		
@@ -366,7 +366,7 @@
 	 * - Handle template ids
 	 * - Handle unqualifiedId
 	 */
-	public boolean name() throws Exception {
+	protected boolean name() throws Exception {
 		Token first = LA(1);
 		Token last = null;
 		
@@ -408,7 +408,7 @@
 	 * cvQualifier
 	 * : "const" | "volatile"
 	 */
-	public Object cvQualifier() throws Exception {
+	protected Object cvQualifier() throws Exception {
 		switch (LT(1)) {
 			case Token.t_const:
 			case Token.t_volatile:
@@ -426,7 +426,7 @@
 	 * To Do:
 	 * - handle initializers
 	 */
-	public void initDeclarator( Object owner ) throws Exception {
+	protected void initDeclarator( Object owner ) throws Exception {
 		Object declarator = declarator( owner );
 		
 		// handle = initializerClause
@@ -434,13 +434,17 @@
 			consume(); 
 			
 			// assignmentExpression || { initializerList , } || { }
+			Object expression = null; 
 			try
 			{
-				assignmentExpression();  
+				expression = callback.expressionBegin( declarator ); 
+				assignmentExpression( expression );
+				callback.expressionEnd( expression );   
 			}
 			catch( Backtrack b )
 			{
-				// doNothing
+				if( expression != null )
+					callback.expressionAbort( expression ); 
 			}
 			
 			if (LT(1) == Token.tLBRACE) {
@@ -463,7 +467,18 @@
 		{
 			consume();  // EAT IT!
 			
-			constantExpression();
+			Object expression = null; 
+			try
+			{
+				expression = callback.expressionBegin( declarator ); 
+				constantExpression( expression );
+				callback.expressionEnd( expression );   
+			}
+			catch( Backtrack b )
+			{
+				if( expression != null )
+					callback.expressionAbort( expression ); 
+			}
 			
 			if( LT(1) == Token.tRPAREN )
 				consume();
@@ -487,7 +502,7 @@
 	 * declaratorId
 	 * : name
 	 */
-	public Object declarator( Object container ) throws Exception {
+	protected Object declarator( Object container ) throws Exception {
 		
 		do
 		{
@@ -569,7 +584,7 @@
 	 * | "&"
 	 * | name "*" (cvQualifier)*
 	 */
-	public Object ptrOperator() throws Exception {
+	protected Object ptrOperator() throws Exception {
 		int t = LT(1);
 		
 		if (t == Token.tAMPER) {					
@@ -604,7 +619,7 @@
 	 * enumSpecifier
 	 * 		"enum" (name)? "{" (enumerator-list) "}" 
 	 */
-	public void enumSpecifier( Object owner ) throws Exception
+	protected void enumSpecifier( Object owner ) throws Exception
 	{
 		if( LT(1) != Token.t_enum )
 			throw backtrack; 
@@ -640,7 +655,7 @@
 	 * classSpecifier
 	 * : classKey name (baseClause)? "{" (memberSpecification)* "}"
 	 */
-	public void classSpecifier( Object owner ) throws Exception {
+	protected void classSpecifier( Object owner ) throws Exception {
 		Token classKey = null;
 		
 		Token mark = mark();
@@ -717,7 +732,7 @@
 		callback.classSpecifierEnd(classSpec);
 	}
 
-	public void baseSpecifier( Object classSpecOwner ) throws Exception {
+	protected void baseSpecifier( Object classSpecOwner ) throws Exception {
 
 		Object baseSpecifier = callback.baseSpecifierBegin( classSpecOwner ); 		
 		
@@ -751,16 +766,19 @@
 		callback.baseSpecifierEnd( baseSpecifier ); 
 	}
 	
-	public void functionBody() throws Exception {
+	protected void functionBody() throws Exception {
 		compoundStatement();
 	}
 	
 	// Statements
-	public void statement() throws Exception {
+	protected void statement() throws Exception {
+		Object expression = null; 
 		switch (LT(1)) {
 			case Token.t_case:
 				consume();
-				constantExpression();
+				expression = callback.expressionBegin( null ); //TODO regarding this null
+				constantExpression(expression);
+				callback.expressionEnd( expression );
 				consume(Token.tCOLON);
 				statement();
 				return;
@@ -813,7 +831,11 @@
 					condition();
 				consume(Token.tSEMI);
 				if (LT(1) != Token.tRPAREN)
-					expression();
+				{
+					expression = callback.expressionBegin( null ); //TODO get rid of NULL  
+					expression(expression);
+					callback.expressionEnd( expression );
+				}
 				consume(Token.tRPAREN);
 				statement();
 				return;
@@ -828,7 +850,11 @@
 			case Token.t_return:
 				consume();
 				if (LT(1) != Token.tSEMI)
-					expression();
+				{
+					expression = callback.expressionBegin( null ); //TODO get rid of NULL  
+					expression(expression);
+					callback.expressionEnd( expression );
+				}
 				consume(Token.tSEMI);
 				return;
 			case Token.t_goto:
@@ -864,7 +890,9 @@
 				// Note: the function style cast ambiguity is handled in expression
 				// Since it only happens when we are in a statement
 				try {
-					expression();
+					expression = callback.expressionBegin( null ); //TODO get rid of NULL  
+					expression(expression);
+					callback.expressionEnd( expression );
 					consume(Token.tSEMI);
 					return;
 				} catch (Backtrack b) {
@@ -875,15 +903,15 @@
 		}
 	}
 	
-	public void condition() throws Exception {
+	protected void condition() throws Exception {
 		// TO DO
 	}
 	
-	public void forInitStatement() throws Exception {
+	protected void forInitStatement() throws Exception {
 		// TO DO
 	}
 	
-	public void compoundStatement() throws Exception {
+	protected void compoundStatement() throws Exception {
 		consume(Token.tLBRACE);
 		while (LT(1) != Token.tRBRACE)
 			statement();
@@ -891,28 +919,28 @@
 	}
 	
 	// Expressions
-	public void constantExpression() throws Exception {
-		conditionalExpression();
+	protected void constantExpression( Object expression ) throws Exception {
+		conditionalExpression( expression );
 	}
 	
-	public void expression() throws Exception {
-		assignmentExpression();
+	public void expression( Object expression ) throws Exception {
+		assignmentExpression( expression );
 		
 		while (LT(1) == Token.tCOMMA) {
 			Token t = consume();
-			assignmentExpression();
-			callback.expressionOperator(t);
+			assignmentExpression( expression );
+			callback.expressionOperator(expression, t);
 		}
 	}
 	
-	public void assignmentExpression() throws Exception {
+	protected void assignmentExpression( Object expression ) throws Exception {
 		if (LT(1) == Token.t_throw) {
-			throwExpression();
+			throwExpression(expression);
 			return;
 		}
 		
 		// if the condition not taken, try assignment operators
-		if (!conditionalExpression()) {
+		if (!conditionalExpression(expression)) {
 			switch (LT(1)) {
 				case Token.tASSIGN:
 				case Token.tSTARASSIGN:
@@ -926,95 +954,95 @@
 				case Token.tXORASSIGN:
 				case Token.tBITORASSIGN:
 					Token t = consume();
-					conditionalExpression();
-					callback.expressionOperator(t);
+					conditionalExpression(expression);
+					callback.expressionOperator(expression, t);
 					break;
 			}
 		}
 	}
 	
-	public void throwExpression() throws Exception {
+	protected void throwExpression( Object expression ) throws Exception {
 		consume(Token.t_throw);
 		
 		try {
-			expression();
+			expression(expression);
 		} catch (Backtrack b) {
 		}
 	}
 	
-	public boolean conditionalExpression() throws Exception {
-		logicalOrExpression();
+	protected boolean conditionalExpression( Object expression ) throws Exception {
+		logicalOrExpression( expression );
 		
 		if (LT(1) == Token.tQUESTION) {
 			consume();
-			expression();
+			expression(expression);
 			consume(Token.tCOLON);
-			assignmentExpression();
+			assignmentExpression(expression);
 			return true;
 		} else
 			return false;
 	}
 	
-	public void logicalOrExpression() throws Exception {
-		logicalAndExpression();
+	protected void logicalOrExpression( Object expression ) throws Exception {
+		logicalAndExpression( expression );
 		
 		while (LT(1) == Token.tOR) {
 			Token t = consume();
-			logicalAndExpression();
-			callback.expressionOperator(t);
+			logicalAndExpression( expression );
+			callback.expressionOperator(expression, t);
 		}
 	}
 	
-	public void logicalAndExpression() throws Exception {
-		inclusiveOrExpression();
+	protected void logicalAndExpression( Object expression ) throws Exception {
+		inclusiveOrExpression( expression );
 		
 		while (LT(1) == Token.tAND) {
 			Token t = consume();
-			inclusiveOrExpression();
-			callback.expressionOperator(t);
+			inclusiveOrExpression(expression );
+			callback.expressionOperator(expression, t);
 		}
 	}
 	
-	public void inclusiveOrExpression() throws Exception {
-		exclusiveOrExpression();
+	protected void inclusiveOrExpression( Object expression ) throws Exception {
+		exclusiveOrExpression(expression);
 		
 		while (LT(1) == Token.tBITOR) {
 			Token t = consume();
-			exclusiveOrExpression();
-			callback.expressionOperator(t);
+			exclusiveOrExpression(expression);
+			callback.expressionOperator(expression, t);
 		}
 	}
 	
-	public void exclusiveOrExpression() throws Exception {
-		andExpression();
+	protected void exclusiveOrExpression( Object expression ) throws Exception {
+		andExpression( expression );
 		
 		while (LT(1) == Token.tXOR) {
 			Token t = consume();
-			andExpression();
-			callback.expressionOperator(t);
+			andExpression(expression);
+			callback.expressionOperator(expression, t);
 		}
 	}
 	
-	public void andExpression() throws Exception {
-		equalityExpression();
+	protected void andExpression( Object expression ) throws Exception {
+		equalityExpression(expression);
 		
 		while (LT(1) == Token.tAMPER) {
 			Token t = consume();
-			equalityExpression();
-			callback.expressionOperator(t);
+			equalityExpression(expression);
+			callback.expressionOperator(expression, t);
 		}
 	}
 	
-	public void equalityExpression() throws Exception {
-		relationalExpression();
+	protected void equalityExpression(Object expression) throws Exception {
+		relationalExpression(expression);
 		
 		for (;;) {
 			switch (LT(1)) {
 				case Token.tEQUAL:
 				case Token.tNOTEQUAL:
 					Token t = consume();
-					relationalExpression();
-					callback.expressionOperator(t);
+					relationalExpression(expression);
+					callback.expressionOperator(expression, t);
 					break;
 				default:
 					return;
@@ -1022,8 +1050,8 @@
 		}
 	}
 	
-	public void relationalExpression() throws Exception {
-		shiftExpression();
+	protected void relationalExpression(Object expression) throws Exception {
+		shiftExpression(expression);
 		
 		for (;;) {
 			switch (LT(1)) {
@@ -1035,8 +1063,8 @@
 				case Token.tLTEQUAL:
 				case Token.tGTEQUAL:
 					Token t = consume();
-					shiftExpression();
-					callback.expressionOperator(t);
+					shiftExpression(expression);
+					callback.expressionOperator(expression, t);
 					break;
 				default:
 					return;
@@ -1044,16 +1072,16 @@
 		}
 	}
 	
-	public void shiftExpression() throws Exception {
-		additiveExpression();
+	protected void shiftExpression( Object expression ) throws Exception {
+		additiveExpression(expression);
 		
 		for (;;) {
 			switch (LT(1)) {
 				case Token.tSHIFTL:
 				case Token.tSHIFTR:
 					Token t = consume();
-					additiveExpression();
-					callback.expressionOperator(t);
+					additiveExpression(expression);
+					callback.expressionOperator(expression, t);
 					break;
 				default:
 					return;
@@ -1061,16 +1089,16 @@
 		}
 	}
 	
-	public void additiveExpression() throws Exception {
-		multiplicativeExpression();
+	protected void additiveExpression( Object expression ) throws Exception {
+		multiplicativeExpression(expression);
 		
 		for (;;) {
 			switch (LT(1)) {
 				case Token.tPLUS:
 				case Token.tMINUS:
 					Token t = consume();
-					multiplicativeExpression();
-					callback.expressionOperator(t);
+					multiplicativeExpression(expression);
+					callback.expressionOperator(expression, t);
 					break;
 				default:
 					return;
@@ -1078,8 +1106,8 @@
 		}
 	}
 	
-	public void multiplicativeExpression() throws Exception {
-		pmExpression();
+	protected void multiplicativeExpression( Object expression ) throws Exception {
+		pmExpression( expression );
 		
 		for (;;) {
 			switch (LT(1)) {
@@ -1087,8 +1115,8 @@
 				case Token.tDIV:
 				case Token.tMOD:
 					Token t = consume();
-					pmExpression();
-					callback.expressionOperator(t);
+					pmExpression(expression );
+					callback.expressionOperator(expression , t);
 					break;
 				default:
 					return;
@@ -1096,16 +1124,16 @@
 		}
 	}
 	
-	public void pmExpression() throws Exception {
-		castExpression();
+	protected void pmExpression( Object expression ) throws Exception {
+		castExpression( expression );
 		
 		for (;;) {
 			switch (LT(1)) {
 				case Token.tDOTSTAR:
 				case Token.tARROWSTAR:
 					Token t = consume();
-					castExpression();
-					callback.expressionOperator(t);
+					castExpression( expression );
+					callback.expressionOperator(expression, t);
 					break;
 				default:
 					return;
@@ -1118,7 +1146,7 @@
 	 * : unaryExpression
 	 * | "(" typeId ")" castExpression
 	 */
-	public void castExpression() throws Exception {
+	protected void castExpression( Object expression ) throws Exception {
 		// TO DO: we need proper symbol checkint to ensure type name
 		if (false && LT(1) == Token.tLPAREN) {
 			Token mark = mark();
@@ -1128,17 +1156,17 @@
 			try {
 				typeId();
 				consume(Token.tRPAREN);
-				castExpression();
+				castExpression( expression );
 				return;
 			} catch (Backtrack b) {
 				backup(mark);
 			}
 		}
 
-		unaryExpression();
+		unaryExpression(expression);
 	}
 	
-	public void typeId() throws Exception {
+	protected void typeId() throws Exception {
 		try {
 			name();
 			return;
@@ -1146,7 +1174,7 @@
 		}
 	}
 	
-	public void deleteExpression() throws Exception {
+	protected void deleteExpression( Object expression ) throws Exception {
 		if (LT(1) == Token.tCOLONCOLON) {
 			// global scope
 			consume();
@@ -1160,10 +1188,10 @@
 			consume(Token.tRBRACKET);
 		}
 		
-		castExpression();
+		castExpression( expression );
 	}
 	
-	public void newExpression() throws Exception {
+	protected void newExpression( Object expression ) throws Exception {
 		if (LT(1) == Token.tCOLONCOLON) {
 			// global scope
 			consume();
@@ -1171,10 +1199,10 @@
 		
 		consume (Token.t_new);
 		
-		// TO DO: finish this horrible mess...
+		//TODO: finish this horrible mess...
 	}
 	
-	public void unaryExpression() throws Exception {
+	protected void unaryExpression( Object expression ) throws Exception {
 		switch (LT(1)) {
 			case Token.tSTAR:
 			case Token.tAMPER:
@@ -1185,8 +1213,8 @@
 			case Token.tINCR:
 			case Token.tDECR:
 				Token t = consume();
-				castExpression();
-				callback.expressionOperator(t);
+				castExpression(expression);
+				callback.expressionOperator(expression, t);
 				return;
 			case Token.t_sizeof:
 				if (LT(1) == Token.tLPAREN) {
@@ -1194,34 +1222,34 @@
 					typeId();
 					consume(Token.tRPAREN);
 				} else {
-					unaryExpression();
+					unaryExpression( expression );
 				}
 				return;
 			case Token.t_new:
-				newExpression();
+				newExpression( expression );
 				return;
 			case Token.t_delete:
-				deleteExpression();
+				deleteExpression( expression );
 				return;
 			case Token.tCOLONCOLON:
 				switch (LT(2)) {
 					case Token.t_new:
-						newExpression();
+						newExpression(expression);
 						return;
 					case Token.t_delete:
-						deleteExpression();
+						deleteExpression(expression);
 						return;
 					default:
-						postfixExpression();
+						postfixExpression(expression);
 						return;			
 				}
 			default:
-				postfixExpression();
+				postfixExpression(expression);
 				return;
 		}
 	}
 
-	public void postfixExpression() throws Exception {
+	protected void postfixExpression( Object expression) throws Exception {
 		switch (LT(1)) {
 			case Token.t_typename:
 				consume();
@@ -1236,7 +1264,7 @@
 				typeId();
 				consume(Token.tGT);
 				consume(Token.tLPAREN);
-				expression();
+				expression(expression);
 				consume(Token.tRPAREN);
 				break;
 			case Token.t_typeid:
@@ -1245,13 +1273,13 @@
 				try {
 					typeId();
 				} catch (Backtrack b) {
-					expression();
+					expression(expression);
 				}
 				consume(Token.tRPAREN);
 				break;
 			default:
 				// TO DO: try simpleTypeSpecifier "(" expressionList ")"
-				primaryExpression();
+				primaryExpression(expression);
 		}
 		
 		for (;;) {
@@ -1259,14 +1287,14 @@
 				case Token.tLBRACKET:
 					// array access
 					consume();
-					expression();
+					expression(expression);
 					consume(Token.tRBRACKET);
 					break;
 				case Token.tLPAREN:
 					// function call
 					consume();
 					// Note: since expressionList and expression are the same...
-					expression();
+					expression(expression);
 					consume(Token.tRPAREN);
 					break;
 				case Token.tINCR:
@@ -1287,25 +1315,25 @@
 		}
 	}
 	
-	public void primaryExpression() throws Exception {
+	protected void primaryExpression( Object expression ) throws Exception {
 		int type = LT(1);
 		switch (type) {
 			// TO DO: we need more literals...
 			case Token.tINTEGER:
-				callback.expressionTerminal(consume());
+				callback.expressionTerminal(expression, consume());
 				return;
 			case Token.tSTRING:
-				callback.expressionTerminal(consume());
+				callback.expressionTerminal(expression, consume());
 				return;
 			case Token.tIDENTIFIER:
-				callback.expressionTerminal(consume());
+				callback.expressionTerminal(expression, consume());
 				return;
 			case Token.t_this:
 				consume();
 				return;
 			case Token.tLPAREN:
 				consume();
-				expression();
+				expression(expression);
 				consume(Token.tRPAREN);
 				return;
 			default:
@@ -1315,7 +1343,7 @@
 		}
 	}
 	
-	public void varName() throws Exception {
+	protected void varName() throws Exception {
 		if (LT(1) == Token.tCOLONCOLON)
 			consume();
 		
@@ -1430,7 +1458,7 @@
 	}
 
 	// Utility routines that require a knowledge of the grammar
-	public static String generateName(Token startToken) throws Exception {
+	protected static String generateName(Token startToken) throws Exception {
 		Token currToken = startToken.getNext();
 		
 		if (currToken == null || currToken.getType() != Token.tCOLONCOLON)
Index: parser/org/eclipse/cdt/internal/core/parser/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java,v
retrieving revision 1.6
diff -u -r1.6 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/Scanner.java	17 Mar 2003 19:48:46 -0000	1.6
+++ parser/org/eclipse/cdt/internal/core/parser/Scanner.java	20 Mar 2003 00:23:23 -0000
@@ -347,12 +347,14 @@
 	// we can just leave it internal
 	private boolean throwExceptionPPError = true;
 	private boolean throwExceptionOnRedefinition = false;
-	private boolean throwExceptionOnBadPPDirective = true;
+	private boolean throwExceptionOnBadUndefinition = false; 
+	private boolean throwExceptionOnBadPreprocessorSyntax = true;
 	private boolean throwExceptionOnInclusionNotFound = true;
 	private boolean throwExceptionOnBadMacroExpansion = true;
 	private boolean throwExceptionOnUnboundedString = true;
 	private boolean throwExceptionOnEOFWithinMultilineComment = true;
 	private boolean throwExceptionOnEOFWithoutBalancedEndifs = true;
+	private boolean throwExceptionOnBadCharacterRead = true; 
 
 	private boolean quickScan = false;
 	public void setQuickScan(boolean qs) {
@@ -630,7 +632,7 @@
 
 				Object directive = ppDirectives.get(token);
 				if (directive == null) {
-					if (throwExceptionOnBadPPDirective)
+					if (throwExceptionOnBadPreprocessorSyntax)
 						throw new ScannerException(
 							BAD_PP + currentContext.getOffset());
 
@@ -669,9 +671,10 @@
 							skipOverWhitespace();
 							// definition 
 							String toBeUndefined = getNextIdentifier();
-							// TODO -- Should we throw an exception if we
-							// do not have this in our table?
-							definitions.remove(toBeUndefined);
+							
+							if( ( definitions.remove(toBeUndefined) == null ) && throwExceptionOnBadUndefinition ) 
+								throw new ScannerException( "Attempt to #undef symbol " + toBeUndefined + " when it was never defined");
+							
 							skipOverTextUntilNewline();
 							c = getChar();
 							continue;
@@ -702,8 +705,9 @@
 							}
 							continue;
 						case PreprocessorDirectives.ENDIF :
-							// TODO - make sure there is nothing after endif
-
+							String restOfLine = getRestOfPreprocessorLine().trim();
+							if( ! restOfLine.equals( "" ) && throwExceptionOnBadPreprocessorSyntax )
+								throw new ScannerException( BAD_PP + currentContext.getOffset() );
 							passOnToClient = branches.poundendif(); 
 							c = getChar();
 							continue;
@@ -736,7 +740,7 @@
 							String elsifExpression = getRestOfPreprocessorLine();
 
 							if (elsifExpression.equals(""))
-								if (throwExceptionOnBadPPDirective)
+								if (throwExceptionOnBadPreprocessorSyntax)
 									throw new ScannerException("Malformed #elsif clause");
 
 							boolean elsifResult =
@@ -774,7 +778,7 @@
 							String remainderOfLine =
 								getRestOfPreprocessorLine().trim();
 							if (!remainderOfLine.equals("")) {
-								if (throwExceptionOnBadPPDirective)
+								if (throwExceptionOnBadPreprocessorSyntax)
 									throw new ScannerException(
 										BAD_PP + currentContext.getOffset());
 							}
@@ -782,7 +786,7 @@
 							c = getChar();
 							continue;
 						default :
-							if (throwExceptionOnBadPPDirective)
+							if (throwExceptionOnBadPreprocessorSyntax)
 								throw new ScannerException(
 									BAD_PP + currentContext.getOffset());
 
@@ -1102,11 +1106,12 @@
 									currentContext);
 						}
 					default :
+						// Bad character
+						if( throwExceptionOnBadCharacterRead )
+							throw new ScannerException( "Invalid character read @ offset " + currentContext.getOffset() + " of file " + currentContext.getFilename() );
 						break;
 				}
 
-				// Bad character
-				// TODO - does this need it's own exception
 				throw Parser.endOfFile;
 			}
 		}
@@ -1259,7 +1264,7 @@
 						EXPRESSION,
 						definitions);
 				Parser parser = new Parser(trial, evaluator);
-				parser.expression();
+				parser.expression(null);  //TODO should this be null?
 				
 				expressionEvalResult = evaluator.getResult();
 	
@@ -1470,13 +1475,13 @@
 			} else {
 				// this is not a comment 
 				// it is a bad statement
-				if (throwExceptionOnBadPPDirective)
+				if (throwExceptionOnBadPreprocessorSyntax)
 					throw new ScannerException(
 						BAD_PP + currentContext.getOffset());
 			}
 		} else {
 			System.out.println("Unexpected character " + ((char) c));
-			if (throwExceptionOnBadPPDirective)
+			if (throwExceptionOnBadPreprocessorSyntax)
 				throw new ScannerException(BAD_PP + currentContext.getOffset());
 		}
 
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/ChangeLog,v
retrieving revision 1.6
diff -u -r1.6 ChangeLog
--- ChangeLog	19 Mar 2003 16:11:50 -0000	1.6
+++ ChangeLog	20 Mar 2003 00:22:58 -0000
@@ -1,3 +1,7 @@
+2003-03-19 John Camelon
+	Updated DOMTests for assignmentExpressions off of declarators. 
+	Updated ExprEvalTest for Parser signature changes relating to adjustments to Expression callbacks. 
+
 2003-03-18 John Camelon
 	Updated DOMTests to validate simple case of a function declaration with multiple parameters.  
 	* parser/org/eclipse/cdt/core/parser/tests/DOMTests.java
Index: parser/org/eclipse/cdt/core/parser/tests/DOMTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java,v
retrieving revision 1.5
diff -u -r1.5 DOMTests.java
--- parser/org/eclipse/cdt/core/parser/tests/DOMTests.java	19 Mar 2003 16:11:49 -0000	1.5
+++ parser/org/eclipse/cdt/core/parser/tests/DOMTests.java	20 Mar 2003 00:22:58 -0000
@@ -11,12 +11,14 @@
 import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
 import org.eclipse.cdt.internal.core.dom.DOMBuilder;
 import org.eclipse.cdt.internal.core.dom.Declarator;
+import org.eclipse.cdt.internal.core.dom.Expression;
 import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
 import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
 import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
 import org.eclipse.cdt.internal.core.dom.TranslationUnit;
 import org.eclipse.cdt.internal.core.parser.Parser;
 import org.eclipse.cdt.internal.core.parser.ParserException;
+import org.eclipse.cdt.internal.core.parser.Token;
 import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
 import org.eclipse.cdt.internal.core.parser.util.Name;
 
@@ -39,12 +41,12 @@
 	}
 	
 	/**
-	 * Test code: int x;
+	 * Test code: int x = 5;
 	 * Purpose: to test the simple decaration in it's simplest form.
 	 */
 	public void testIntGlobal() throws Exception {
 		// Parse and get the translation Unit
-		TranslationUnit translationUnit = parse("int x;");
+		TranslationUnit translationUnit = parse("int x = 5;");
 		
 		// Get the simple declaration
 		List declarations = translationUnit.getDeclarations();
@@ -60,6 +62,13 @@
 		Declarator declarator = (Declarator)declarators.get(0);
 		Name name = declarator.getName();
 		assertEquals("x", name.toString());
+		
+		Expression exp = declarator.getExpression(); 
+		assertNotNull( exp );
+		assertEquals( 1, exp.tokens().size() ); 
+		Token t = (Token)exp.tokens().get(0); 
+		assertEquals( t.getImage(), "5" );
+		assertEquals( t.getType(), Token.tINTEGER);
 	}
 	
 	/**
@@ -243,14 +252,14 @@
 	}
 	
 	/**
-	 * Test code: bool myFunction( int parm1, double parm2 );
+	 * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 );
 	 * @throws Exception
 	 */
 	public void testFunctionDeclarationWithParameters() throws Exception
 	{
 		// Parse and get the translaton unit
 		Writer code = new StringWriter();
-		code.write("bool myFunction( int parm1, double parm2 );");
+		code.write("bool myFunction( int parm1 = 3 * 4, double parm2 );");
 		TranslationUnit translationUnit = parse(code.toString());
 
 		// Get the declaration
@@ -271,7 +280,17 @@
 		List parm1Decls = parm1.getDeclarators(); 
 		assertEquals( 1, parm1Decls.size() ); 
 		Declarator parm1Declarator = (Declarator) parm1Decls.get(0); 
-		assertEquals( "parm1", parm1Declarator.getName().toString() );  
+		assertEquals( "parm1", parm1Declarator.getName().toString() );
+		Expression initialValueParm1 = parm1Declarator.getExpression();
+		assertEquals( initialValueParm1.tokens().size(), 3 );
+		Token t1 = (Token)initialValueParm1.tokens().get( 0 );
+		Token t2 = (Token)initialValueParm1.tokens().get( 1 ); 
+		Token t3 = (Token)initialValueParm1.tokens().get( 2 );
+		assertEquals( t1.getType(), Token.tINTEGER );
+		assertEquals( t1.getImage(), "3" ); 
+		assertEquals( t3.getType(), Token.tSTAR ); 
+		assertEquals( t2.getType(), Token.tINTEGER );
+		assertEquals( t2.getImage(), "4" );   
 
 		ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 );
 		assertEquals( DeclSpecifier.t_double, parm2.getDeclSpecifier().getType() );
Index: parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java,v
retrieving revision 1.3
diff -u -r1.3 ExprEvalTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java	17 Mar 2003 19:48:49 -0000	1.3
+++ parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java	20 Mar 2003 00:22:59 -0000
@@ -20,7 +20,7 @@
 	public void runTest(String code, int expectedValue) throws Exception {
 		ExpressionEvaluator evaluator = new ExpressionEvaluator();
 		Parser parser = new Parser(code, evaluator);
-		parser.expression();
+		parser.expression(null);
 		assertEquals(expectedValue, ((Integer)evaluator.getResult()).intValue());
 	}
 	

Back to the top