mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Cloned CompleteParseASTTest to CompleteParse2Tests to be used w/the new parser.
Added CompleteParser2Tests to ParserTestSuite. Removed unnecessary helper classes in parser2 package.
This commit is contained in:
parent
2a7c0f097f
commit
1a5a30c950
15 changed files with 1612 additions and 1238 deletions
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
|||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
|
||||
import org.eclipse.cdt.core.parser.tests.parser2.CompleteParser2Tests;
|
||||
import org.eclipse.cdt.core.parser.tests.parser2.QuickParser2Tests;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
|
||||
|
@ -57,6 +58,7 @@ public class ParserTestSuite extends TestCase {
|
|||
suite.addTestSuite( AST2Tests.class );
|
||||
suite.addTestSuite( GCCTests.class );
|
||||
suite.addTestSuite( QuickParser2Tests.class );
|
||||
suite.addTestSuite( CompleteParser2Tests.class );
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.eclipse.cdt.core.parser.ParserFactory;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.tests.parser2.QuickParser2Tests.ProblemCollector;
|
||||
import org.eclipse.cdt.core.parser.tests.parser2.ProblemCollector;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
import org.eclipse.cdt.internal.core.parser2.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.ANSICParserExtensionConfiguration;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,44 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.parser2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.internal.core.parser2.IProblemRequestor;
|
||||
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class ProblemCollector implements IProblemRequestor {
|
||||
|
||||
List problems = new ArrayList();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser2.IProblemRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
|
||||
*/
|
||||
public boolean acceptProblem(IProblem problem) {
|
||||
problems.add(problem);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean hasNoProblems() {
|
||||
return problems.isEmpty();
|
||||
}
|
||||
|
||||
}
|
|
@ -12,15 +12,11 @@ package org.eclipse.cdt.core.parser.tests.parser2;
|
|||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
|
@ -29,7 +25,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
|||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
import org.eclipse.cdt.internal.core.parser2.IProblemRequestor;
|
||||
import org.eclipse.cdt.internal.core.parser2.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.ANSICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.GCCParserExtensionConfiguration;
|
||||
|
@ -45,34 +40,7 @@ import org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguratio
|
|||
*/
|
||||
public class QuickParser2Tests extends TestCase {
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public static class ProblemCollector implements IProblemRequestor {
|
||||
|
||||
List problems = new ArrayList();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser2.IProblemRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
|
||||
*/
|
||||
public boolean acceptProblem(IProblem problem) {
|
||||
problems.add(problem);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean hasNoProblems() {
|
||||
return problems.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final NullLogService NULL_LOG = new NullLogService();
|
||||
|
||||
private static final NullSourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor();
|
||||
|
||||
/**
|
||||
|
@ -1409,7 +1377,7 @@ public class QuickParser2Tests extends TestCase {
|
|||
parser2 = new GNUCSourceParser(scanner, ParserMode.QUICK_PARSE,
|
||||
collector, NULL_LOG, config);
|
||||
}
|
||||
IASTTranslationUnit tu = parser2.parse();
|
||||
parser2.parse();
|
||||
if (parser2.encounteredError() && expectedToPass)
|
||||
throw new ParserException("FAILURE"); //$NON-NLS-1$
|
||||
if (expectedToPass)
|
||||
|
|
|
@ -846,9 +846,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
IASTUnaryExpression result = createUnaryExpression();
|
||||
((ASTNode)result).setOffset(offset);
|
||||
result.setOperator(operator);
|
||||
result.setOperand(operand);
|
||||
operand.setParent(result);
|
||||
operand.setPropertyInParent(IASTUnaryExpression.OPERAND);
|
||||
if( operand != null )
|
||||
{
|
||||
result.setOperand(operand);
|
||||
operand.setParent(result);
|
||||
operand.setPropertyInParent(IASTUnaryExpression.OPERAND);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,497 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
|
||||
|
||||
public class DeclarationWrapper implements IDeclaratorOwner
|
||||
{
|
||||
private int flag = 0;
|
||||
protected void setBit(boolean b, int mask){
|
||||
if( b ){
|
||||
flag = flag | mask;
|
||||
} else {
|
||||
flag = flag & ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkBit(int mask){
|
||||
return (flag & mask) != 0;
|
||||
}
|
||||
|
||||
private static final int DEFAULT_LIST_SIZE = 4;
|
||||
|
||||
protected static final int IS_IMAGINARY = 0x00000010;
|
||||
protected static final int IS_COMPLEX = 0x00000020;
|
||||
protected static final int IS_RESTRICT = 0x00000040;
|
||||
protected static final int IS_SIGNED = 0x00000080;
|
||||
protected static final int IS_SHORT = 0x00000100;
|
||||
protected static final int IS_UNSIGNED = 0x00000200;
|
||||
protected static final int IS_LONG = 0x00000400;
|
||||
protected static final int IS_TYPENAMED = 0x00000800;
|
||||
protected static final int IS_VOLATILE = 0x00001000;
|
||||
protected static final int IS_VIRTUAL = 0x00002000;
|
||||
protected static final int IS_TYPEDEF = 0x00004000;
|
||||
protected static final int IS_STATIC = 0x00008000;
|
||||
protected static final int IS_REGISTER = 0x00010000;
|
||||
protected static final int IS_EXTERN = 0x00020000;
|
||||
protected static final int IS_EXPLICIT = 0x00040000;
|
||||
protected static final int IS_CONST = 0x00080000;
|
||||
protected static final int IS_AUTO = 0x00100000;
|
||||
protected static final int IS_GLOBAL = 0x00200000;
|
||||
protected static final int IS_MUTABLE = 0x00400000;
|
||||
protected static final int IS_FRIEND = 0x00800000;
|
||||
protected static final int IS_INLINE = 0x01000000;
|
||||
|
||||
|
||||
public int startingOffset = 0;
|
||||
public int startingLine;
|
||||
public int endOffset;
|
||||
|
||||
private ITokenDuple name;
|
||||
private Type simpleType = IASTSimpleTypeSpecifier.Type.UNSPECIFIED;
|
||||
private final Object templateDeclaration;
|
||||
private final Object scope;
|
||||
private Object typeSpecifier;
|
||||
|
||||
private List declarators = Collections.EMPTY_LIST;
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setAuto(boolean b)
|
||||
{
|
||||
setBit( b, IS_AUTO );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param filename TODO
|
||||
*/
|
||||
public DeclarationWrapper(
|
||||
Object scope,
|
||||
int startingOffset,
|
||||
int startingLine, Object templateDeclaration, char[] filename)
|
||||
{
|
||||
this.scope = scope;
|
||||
this.startingOffset = startingOffset;
|
||||
this.startingLine = startingLine;
|
||||
this.templateDeclaration = templateDeclaration;
|
||||
this.fn = filename;
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setTypenamed(boolean b)
|
||||
{
|
||||
setBit( b, IS_TYPENAMED );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setMutable(boolean b)
|
||||
{
|
||||
setBit( b, IS_MUTABLE);
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setFriend(boolean b)
|
||||
{
|
||||
setBit( b, IS_FRIEND );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setInline(boolean b)
|
||||
{
|
||||
setBit( b, IS_INLINE );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setRegister(boolean b)
|
||||
{
|
||||
setBit( b, IS_REGISTER );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setStatic(boolean b)
|
||||
{
|
||||
setBit( b, IS_STATIC );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setTypedef(boolean b)
|
||||
{
|
||||
setBit( b, IS_TYPEDEF );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setVirtual(boolean b)
|
||||
{
|
||||
setBit( b, IS_VIRTUAL );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setVolatile(boolean b)
|
||||
{
|
||||
setBit( b, IS_VOLATILE );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setExtern(boolean b)
|
||||
{
|
||||
setBit( b, IS_EXTERN );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setExplicit(boolean b)
|
||||
{
|
||||
setBit( b, IS_EXPLICIT );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setConst(boolean b)
|
||||
{
|
||||
setBit( b, IS_CONST );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isAuto()
|
||||
{
|
||||
return checkBit( IS_AUTO );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isConst()
|
||||
{
|
||||
return checkBit( IS_CONST );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isExplicit()
|
||||
{
|
||||
return checkBit( IS_EXPLICIT );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isExtern()
|
||||
{
|
||||
return checkBit( IS_EXTERN );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isFriend()
|
||||
{
|
||||
return checkBit( IS_FRIEND );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isInline()
|
||||
{
|
||||
return checkBit( IS_INLINE );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isMutable()
|
||||
{
|
||||
return checkBit( IS_MUTABLE );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isRegister()
|
||||
{
|
||||
return checkBit( IS_REGISTER );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isStatic()
|
||||
{
|
||||
return checkBit( IS_STATIC );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isTypedef()
|
||||
{
|
||||
return checkBit( IS_TYPEDEF );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isTypeNamed()
|
||||
{
|
||||
return checkBit( IS_TYPENAMED );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isVirtual()
|
||||
{
|
||||
return checkBit( IS_VIRTUAL );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isVolatile()
|
||||
{
|
||||
return checkBit( IS_VOLATILE );
|
||||
}
|
||||
|
||||
public void addDeclarator(Declarator d)
|
||||
{
|
||||
if( declarators == Collections.EMPTY_LIST )
|
||||
declarators = new ArrayList(DEFAULT_LIST_SIZE);
|
||||
declarators.add(d);
|
||||
}
|
||||
public Iterator getDeclarators()
|
||||
{
|
||||
return declarators.iterator();
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object getTypeSpecifier()
|
||||
{
|
||||
return typeSpecifier;
|
||||
}
|
||||
/**
|
||||
* @param enumeration
|
||||
*/
|
||||
public void setTypeSpecifier(Object enumeration)
|
||||
{
|
||||
typeSpecifier = enumeration;
|
||||
}
|
||||
public int endLine;
|
||||
|
||||
public final char[] fn;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarationWrapper()
|
||||
*/
|
||||
public DeclarationWrapper getDeclarationWrapper()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isUnsigned()
|
||||
{
|
||||
return checkBit( IS_UNSIGNED );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isSigned()
|
||||
{
|
||||
return checkBit( IS_SIGNED );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isShort()
|
||||
{
|
||||
return checkBit( IS_SHORT );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isLong()
|
||||
{
|
||||
return checkBit( IS_LONG );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setLong(boolean b)
|
||||
{
|
||||
setBit( b, IS_LONG );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setShort(boolean b)
|
||||
{
|
||||
setBit( b, IS_SHORT );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setSigned(boolean b)
|
||||
{
|
||||
setBit( b, IS_SIGNED );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setUnsigned(boolean b)
|
||||
{
|
||||
setBit( b, IS_UNSIGNED );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Type getSimpleType()
|
||||
{
|
||||
return simpleType;
|
||||
}
|
||||
/**
|
||||
* @param type
|
||||
*/
|
||||
public void setSimpleType(Type type)
|
||||
{
|
||||
simpleType = type;
|
||||
}
|
||||
/**
|
||||
* @param duple
|
||||
*/
|
||||
public void setTypeName(ITokenDuple duple)
|
||||
{
|
||||
name = duple;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public final ITokenDuple getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public final Object getOwnerTemplate()
|
||||
{
|
||||
return templateDeclaration;
|
||||
}
|
||||
/**
|
||||
* @param i
|
||||
*/
|
||||
public void setEndingOffsetAndLineNumber(int offset, int lineNumber)
|
||||
{
|
||||
endOffset = offset;
|
||||
endLine = lineNumber;
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setRestrict(boolean b)
|
||||
{
|
||||
setBit( b, IS_RESTRICT );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isRestrict()
|
||||
{
|
||||
return checkBit( IS_RESTRICT );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setImaginary(boolean b)
|
||||
{
|
||||
setBit( b, IS_IMAGINARY );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isComplex()
|
||||
{
|
||||
return checkBit( IS_COMPLEX );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isImaginary()
|
||||
{
|
||||
return checkBit( IS_IMAGINARY );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setComplex(boolean b)
|
||||
{
|
||||
setBit( b, IS_COMPLEX );
|
||||
}
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setGloballyQualified(boolean b) {
|
||||
setBit( b, IS_GLOBAL );
|
||||
}
|
||||
|
||||
public boolean isGloballyQualified(){
|
||||
return checkBit( IS_GLOBAL );
|
||||
}
|
||||
|
||||
private Map extensionParameters = Collections.EMPTY_MAP;
|
||||
/**
|
||||
* @param key
|
||||
* @param typeOfExpression
|
||||
*/
|
||||
public void setExtensionParameter(String key, Object value) {
|
||||
if( extensionParameters == Collections.EMPTY_MAP )
|
||||
extensionParameters = new Hashtable( 4 );
|
||||
extensionParameters.put( key, value );
|
||||
}
|
||||
|
||||
public Map getExtensionParameters()
|
||||
{
|
||||
return extensionParameters;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean consumedRawType() {
|
||||
return( getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED );
|
||||
}
|
||||
}
|
|
@ -1,428 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
|
||||
|
||||
public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator
|
||||
{
|
||||
private static final int DEFAULT_ARRAYLIST_SIZE = 4;
|
||||
private static final char[] EMPTY_STRING = new char[0]; //$NON-NLS-1$
|
||||
|
||||
private final IDeclaratorOwner owner;
|
||||
private ITokenDuple pointerOperatorNameDuple = null;
|
||||
private ITokenDuple namedDuple = null;
|
||||
private Object constructorExpression = null;
|
||||
private Declarator ownedDeclarator = null;
|
||||
private Object initializerClause = null;
|
||||
private Object exceptionSpecification = null;
|
||||
private Object bitFieldExpression = null;
|
||||
|
||||
private int flag = 0;
|
||||
protected void setBit(boolean b, int mask){
|
||||
if( b ){
|
||||
flag = flag | mask;
|
||||
} else {
|
||||
flag = flag & ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkBit(int mask){
|
||||
return (flag & mask) != 0;
|
||||
}
|
||||
|
||||
protected static final int IS_FUNCTION = 0x000020;
|
||||
protected static final int HAS_TRY_BLOCK = 0x000040;
|
||||
protected static final int HAS_FUNCTION_BODY = 0x000080;
|
||||
protected static final int IS_PURE_VIRTUAL = 0x000100;
|
||||
protected static final int IS_VAR_ARGS = 0x000200;
|
||||
protected static final int IS_VOLATILE = 0x000400;
|
||||
protected static final int IS_CONST = 0x000800;
|
||||
|
||||
private List ptrOps = Collections.EMPTY_LIST;
|
||||
private List parameters = Collections.EMPTY_LIST;
|
||||
private List arrayModifiers = Collections.EMPTY_LIST;
|
||||
private List constructorMemberInitializers = Collections.EMPTY_LIST;
|
||||
|
||||
|
||||
|
||||
public Declarator( IDeclaratorOwner owner )
|
||||
{
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public char[] getName()
|
||||
{
|
||||
if( namedDuple == null ) return EMPTY_STRING;
|
||||
return namedDuple.toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getNameEndOffset()
|
||||
{
|
||||
if( namedDuple == null ) return -1;
|
||||
return namedDuple.getEndOffset();
|
||||
}
|
||||
|
||||
public int getNameLine()
|
||||
{
|
||||
if( namedDuple == null ) return -1;
|
||||
return namedDuple.getLineNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getNameStartOffset()
|
||||
{
|
||||
if( namedDuple == null ) return -1;
|
||||
return namedDuple.getStartOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public IDeclaratorOwner getOwner()
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List getPointerOperators()
|
||||
{
|
||||
return ptrOps;
|
||||
}
|
||||
|
||||
public void addPointerOperator( Object ptrOp )
|
||||
{
|
||||
if( ptrOps == Collections.EMPTY_LIST )
|
||||
ptrOps = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
|
||||
|
||||
ptrOps.add( ptrOp );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void addParameter( DeclarationWrapper param )
|
||||
{
|
||||
if( parameters == Collections.EMPTY_LIST )
|
||||
parameters = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
|
||||
|
||||
parameters.add( param );
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object getInitializerClause()
|
||||
{
|
||||
return initializerClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clause
|
||||
*/
|
||||
public void setInitializerClause(Object clause)
|
||||
{
|
||||
initializerClause = clause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Declarator getOwnedDeclarator()
|
||||
{
|
||||
return ownedDeclarator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param declarator
|
||||
*/
|
||||
public void setOwnedDeclarator(Declarator declarator)
|
||||
{
|
||||
ownedDeclarator = declarator;
|
||||
}
|
||||
|
||||
public void setName( ITokenDuple duple )
|
||||
{
|
||||
namedDuple = duple;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object getExceptionSpecification()
|
||||
{
|
||||
return exceptionSpecification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isConst()
|
||||
{
|
||||
return checkBit(IS_CONST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isVolatile()
|
||||
{
|
||||
return checkBit( IS_VOLATILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param specification
|
||||
*/
|
||||
public void setExceptionSpecification(Object specification)
|
||||
{
|
||||
exceptionSpecification = specification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setConst(boolean b)
|
||||
{
|
||||
setBit(b, IS_CONST );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setVolatile(boolean b)
|
||||
{
|
||||
setBit( b, IS_VOLATILE );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setPureVirtual(boolean b)
|
||||
{
|
||||
setBit( b, IS_PURE_VIRTUAL );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isPureVirtual()
|
||||
{
|
||||
return checkBit( IS_PURE_VIRTUAL );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param arrayMod
|
||||
*/
|
||||
public void addArrayModifier(Object arrayMod)
|
||||
{
|
||||
if( arrayModifiers == Collections.EMPTY_LIST )
|
||||
arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
|
||||
arrayModifiers.add( arrayMod );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List getArrayModifiers()
|
||||
{
|
||||
return arrayModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object getBitFieldExpression()
|
||||
{
|
||||
return bitFieldExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param exp
|
||||
*/
|
||||
public void setBitFieldExpression(Object exp)
|
||||
{
|
||||
bitFieldExpression = exp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param astExpression
|
||||
*/
|
||||
public void setConstructorExpression(Object astExpression)
|
||||
{
|
||||
constructorExpression = astExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object getConstructorExpression()
|
||||
{
|
||||
return constructorExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initializer
|
||||
*/
|
||||
public void addConstructorMemberInitializer(Object initializer)
|
||||
{
|
||||
if( constructorMemberInitializers == Collections.EMPTY_LIST )
|
||||
constructorMemberInitializers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
|
||||
constructorMemberInitializers.add( initializer );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List getConstructorMemberInitializers()
|
||||
{
|
||||
return constructorMemberInitializers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isFunction()
|
||||
{
|
||||
return checkBit( IS_FUNCTION );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setIsFunction(boolean b)
|
||||
{
|
||||
setBit( b, IS_FUNCTION );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarators()
|
||||
*/
|
||||
public Iterator getDeclarators()
|
||||
{
|
||||
if( ownedDeclarator == null )
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
|
||||
List l = new ArrayList(1);
|
||||
l.add( ownedDeclarator );
|
||||
return l.iterator();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarationWrapper()
|
||||
*/
|
||||
public DeclarationWrapper getDeclarationWrapper()
|
||||
{
|
||||
Declarator d = this;
|
||||
while( d.getOwner() instanceof Declarator )
|
||||
d = (Declarator)d.getOwner();
|
||||
return (DeclarationWrapper)d.getOwner();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public ITokenDuple getNameDuple()
|
||||
{
|
||||
return namedDuple;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nameDuple
|
||||
*/
|
||||
public void setPointerOperatorName(ITokenDuple nameDuple)
|
||||
{
|
||||
pointerOperatorNameDuple = nameDuple;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public ITokenDuple getPointerOperatorNameDuple()
|
||||
{
|
||||
return pointerOperatorNameDuple;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean hasFunctionBody()
|
||||
{
|
||||
return checkBit( HAS_FUNCTION_BODY );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setHasFunctionBody(boolean b)
|
||||
{
|
||||
setBit( b, HAS_FUNCTION_BODY );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setFunctionTryBlock(boolean b)
|
||||
{
|
||||
setBit( b, HAS_TRY_BLOCK );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean hasFunctionTryBlock()
|
||||
{
|
||||
return checkBit( HAS_TRY_BLOCK );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
public void setIsVarArgs(boolean b) {
|
||||
setBit( b, IS_VAR_ARGS );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the varArgs.
|
||||
*/
|
||||
public boolean isVarArgs() {
|
||||
return checkBit( IS_VAR_ARGS );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getScope()
|
||||
*/
|
||||
public Object getScope() {
|
||||
return getDeclarationWrapper().getScope();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002-2004 IBM Canada 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 Rational Software - Initial API and implementation */
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IDeclarator
|
||||
{
|
||||
public Object getScope();
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract List getPointerOperators();
|
||||
public abstract void addPointerOperator(Object ptrOp);
|
||||
/**
|
||||
* @param arrayMod
|
||||
*/
|
||||
public abstract void addArrayModifier(Object arrayMod);
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract List getArrayModifiers();
|
||||
|
||||
/**
|
||||
* @param nameDuple
|
||||
*/
|
||||
public void setPointerOperatorName(ITokenDuple nameDuple);
|
||||
|
||||
public ITokenDuple getPointerOperatorNameDuple();
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002-2004 IBM Canada 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 Rational Software - Initial API and implementation */
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IDeclaratorOwner {
|
||||
|
||||
public Iterator getDeclarators();
|
||||
public DeclarationWrapper getDeclarationWrapper();
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002-2004 IBM Canada 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 Rational Software - Initial API and implementation */
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IParameterCollection {
|
||||
public List getParameters();
|
||||
public void addParameter( DeclarationWrapper param );
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ParameterCollection implements IParameterCollection
|
||||
{
|
||||
private List list = new ArrayList();
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParameterCollection#getParameters()
|
||||
*/
|
||||
public List getParameters()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParameterCollection#addParameter(org.eclipse.cdt.internal.core.parser.DeclarationWrapper)
|
||||
*/
|
||||
public void addParameter(DeclarationWrapper param)
|
||||
{
|
||||
list.add( param );
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
/**********************************************************************
|
||||
* 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:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class TypeId implements IDeclarator
|
||||
{
|
||||
private static final int DEFAULT_ARRAYLIST_SIZE = 4;
|
||||
private ITokenDuple name;
|
||||
private List arrayModifiers;
|
||||
private List pointerOperators;
|
||||
private Object scope;
|
||||
|
||||
/**
|
||||
* @param scope2
|
||||
*/
|
||||
public void reset(Object scope2) {
|
||||
this.scope = scope2;
|
||||
arrayModifiers = Collections.EMPTY_LIST;
|
||||
pointerOperators = Collections.EMPTY_LIST;
|
||||
name = null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public TypeId()
|
||||
{
|
||||
reset( null );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperators()
|
||||
*/
|
||||
public List getPointerOperators()
|
||||
{
|
||||
return pointerOperators;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#addPointerOperator(org.eclipse.cdt.core.parser.ast.ASTPointerOperator)
|
||||
*/
|
||||
public void addPointerOperator(Object ptrOp)
|
||||
{
|
||||
if( pointerOperators == Collections.EMPTY_LIST )
|
||||
pointerOperators = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
|
||||
pointerOperators.add( ptrOp );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#addArrayModifier(org.eclipse.cdt.core.parser.ast.IASTArrayModifier)
|
||||
*/
|
||||
public void addArrayModifier(Object arrayMod)
|
||||
{
|
||||
if( arrayModifiers == Collections.EMPTY_LIST )
|
||||
arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
|
||||
arrayModifiers.add( arrayMod );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getArrayModifiers()
|
||||
*/
|
||||
public List getArrayModifiers()
|
||||
{
|
||||
return arrayModifiers;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#setPointerOperatorName(org.eclipse.cdt.core.parser.ITokenDuple)
|
||||
*/
|
||||
public void setPointerOperatorName(ITokenDuple nameDuple)
|
||||
{
|
||||
name = nameDuple;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperatorNameDuple()
|
||||
*/
|
||||
public ITokenDuple getPointerOperatorNameDuple()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getScope()
|
||||
*/
|
||||
public Object getScope() {
|
||||
return scope;
|
||||
}
|
||||
}
|
|
@ -82,6 +82,7 @@ import org.eclipse.cdt.core.parser.BacktrackException;
|
|||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
|
@ -2085,33 +2086,74 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return compound;
|
||||
// selection statement
|
||||
case IToken.t_if:
|
||||
startOffset = consume(IToken.t_if).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IASTExpression if_condition = condition();
|
||||
consume(IToken.tRPAREN);
|
||||
IASTStatement then_clause = statement();
|
||||
IASTStatement else_clause = null;
|
||||
if (LT(1) == IToken.t_else) {
|
||||
consume(IToken.t_else);
|
||||
else_clause = statement();
|
||||
}
|
||||
|
||||
IASTIfStatement if_stmt = createIfStatement();
|
||||
if_stmt.setCondition( if_condition );
|
||||
((ASTNode)if_stmt).setOffset( startOffset );
|
||||
if_condition.setParent( if_stmt );
|
||||
if_condition.setPropertyInParent( IASTIfStatement.CONDITION );
|
||||
if_stmt.setThenClause( then_clause );
|
||||
then_clause.setParent( if_stmt );
|
||||
then_clause.setPropertyInParent( IASTIfStatement.THEN );
|
||||
if( else_clause != null )
|
||||
{
|
||||
if_stmt.setElseClause( else_clause );
|
||||
else_clause.setParent( if_stmt );
|
||||
else_clause.setPropertyInParent( IASTIfStatement.ELSE );
|
||||
}
|
||||
cleanupLastToken();
|
||||
return if_stmt;
|
||||
IASTIfStatement if_statement = null;
|
||||
if_loop: while( true ){
|
||||
int so = consume(IToken.t_if).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IToken start = LA(1);
|
||||
boolean passedCondition = true;
|
||||
IASTExpression condition = null;
|
||||
try {
|
||||
condition = condition();
|
||||
consume(IToken.tRPAREN);
|
||||
} catch (BacktrackException b) {
|
||||
//if the problem has no offset info, make a new one that does
|
||||
if( b.getProblem() != null && b.getProblem().getSourceLineNumber() == -1 ){
|
||||
IProblem p = b.getProblem();
|
||||
IProblem p2 = problemFactory.createProblem( p.getID(), start.getOffset(),
|
||||
lastToken != null ? lastToken.getEndOffset() : start.getEndOffset(),
|
||||
start.getLineNumber(), p.getOriginatingFileName(),
|
||||
p.getArguments() != null ? p.getArguments().toCharArray() : null,
|
||||
p.isWarning(), p.isError() );
|
||||
b.initialize( p2 );
|
||||
}
|
||||
failParse(b);
|
||||
failParseWithErrorHandling();
|
||||
passedCondition = false;
|
||||
}
|
||||
|
||||
IASTStatement thenClause = null;
|
||||
if( passedCondition ){
|
||||
thenClause = statement();
|
||||
}
|
||||
|
||||
IASTIfStatement new_if_statement = createIfStatement();
|
||||
((ASTNode)new_if_statement).setOffset( so );
|
||||
new_if_statement.setCondition( condition );
|
||||
condition.setParent( new_if_statement );
|
||||
condition.setPropertyInParent( IASTIfStatement.CONDITION );
|
||||
if( thenClause != null )
|
||||
{
|
||||
new_if_statement.setThenClause( thenClause );
|
||||
thenClause.setParent( new_if_statement );
|
||||
thenClause.setPropertyInParent(IASTIfStatement.THEN );
|
||||
}
|
||||
if (LT(1) == IToken.t_else) {
|
||||
consume(IToken.t_else);
|
||||
if (LT(1) == IToken.t_if) {
|
||||
//an else if, don't recurse, just loop and do another if
|
||||
cleanupLastToken();
|
||||
if( if_statement != null )
|
||||
{
|
||||
if_statement.setElseClause( new_if_statement );
|
||||
new_if_statement.setParent( if_statement );
|
||||
new_if_statement.setPropertyInParent( IASTIfStatement.ELSE );
|
||||
if_statement = new_if_statement;
|
||||
}
|
||||
continue if_loop;
|
||||
}
|
||||
IASTStatement elseStatement = statement();
|
||||
new_if_statement.setElseClause( elseStatement );
|
||||
elseStatement.setParent( new_if_statement );
|
||||
elseStatement.setPropertyInParent( IASTIfStatement.ELSE );
|
||||
if_statement = new_if_statement;
|
||||
}
|
||||
else
|
||||
if_statement = new_if_statement;
|
||||
break if_loop;
|
||||
}
|
||||
cleanupLastToken();
|
||||
return if_statement;
|
||||
case IToken.t_switch:
|
||||
startOffset = consume( IToken.t_switch ).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
|
|
|
@ -708,7 +708,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
protected IASTExpression throwExpression() throws EndOfFileException,
|
||||
BacktrackException {
|
||||
IToken throwToken = consume(IToken.t_throw);
|
||||
IASTExpression throwExpression = expression();
|
||||
IASTExpression throwExpression = null;
|
||||
try
|
||||
{
|
||||
throwExpression = expression();
|
||||
}
|
||||
catch( BacktrackException bte )
|
||||
{
|
||||
}
|
||||
return buildUnaryExpression( ICPPASTUnaryExpression.op_throw, throwExpression, throwToken.getOffset() );
|
||||
}
|
||||
|
||||
|
@ -4431,34 +4438,75 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return compound;
|
||||
// selection statement
|
||||
case IToken.t_if:
|
||||
startOffset = consume(IToken.t_if).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IASTExpression if_condition = condition();
|
||||
consume(IToken.tRPAREN);
|
||||
IASTStatement then_clause = statement();
|
||||
IASTStatement else_clause = null;
|
||||
if (LT(1) == IToken.t_else) {
|
||||
consume(IToken.t_else);
|
||||
else_clause = statement();
|
||||
}
|
||||
|
||||
IASTIfStatement if_stmt = createIfStatement();
|
||||
if_stmt.setCondition( if_condition );
|
||||
((ASTNode)if_stmt).setOffset( startOffset );
|
||||
if_condition.setParent( if_stmt );
|
||||
if_condition.setPropertyInParent( IASTIfStatement.CONDITION );
|
||||
if_stmt.setThenClause( then_clause );
|
||||
then_clause.setParent( if_stmt );
|
||||
then_clause.setPropertyInParent( IASTIfStatement.THEN );
|
||||
if( else_clause != null )
|
||||
{
|
||||
if_stmt.setElseClause( else_clause );
|
||||
else_clause.setParent( if_stmt );
|
||||
else_clause.setPropertyInParent( IASTIfStatement.ELSE );
|
||||
}
|
||||
cleanupLastToken();
|
||||
return if_stmt;
|
||||
case IToken.t_switch:
|
||||
IASTIfStatement if_statement = null;
|
||||
if_loop: while( true ){
|
||||
int so = consume(IToken.t_if).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IToken start = LA(1);
|
||||
boolean passedCondition = true;
|
||||
IASTExpression condition = null;
|
||||
try {
|
||||
condition = condition();
|
||||
consume(IToken.tRPAREN);
|
||||
} catch (BacktrackException b) {
|
||||
//if the problem has no offset info, make a new one that does
|
||||
if( b.getProblem() != null && b.getProblem().getSourceLineNumber() == -1 ){
|
||||
IProblem p = b.getProblem();
|
||||
IProblem p2 = problemFactory.createProblem( p.getID(), start.getOffset(),
|
||||
lastToken != null ? lastToken.getEndOffset() : start.getEndOffset(),
|
||||
start.getLineNumber(), p.getOriginatingFileName(),
|
||||
p.getArguments() != null ? p.getArguments().toCharArray() : null,
|
||||
p.isWarning(), p.isError() );
|
||||
b.initialize( p2 );
|
||||
}
|
||||
failParse(b);
|
||||
failParseWithErrorHandling();
|
||||
passedCondition = false;
|
||||
}
|
||||
|
||||
IASTStatement thenClause = null;
|
||||
if( passedCondition ){
|
||||
thenClause = statement();
|
||||
}
|
||||
|
||||
IASTIfStatement new_if_statement = createIfStatement();
|
||||
((ASTNode)new_if_statement).setOffset( so );
|
||||
new_if_statement.setCondition( condition );
|
||||
condition.setParent( new_if_statement );
|
||||
condition.setPropertyInParent( IASTIfStatement.CONDITION );
|
||||
if( thenClause != null )
|
||||
{
|
||||
new_if_statement.setThenClause( thenClause );
|
||||
thenClause.setParent( new_if_statement );
|
||||
thenClause.setPropertyInParent(IASTIfStatement.THEN );
|
||||
}
|
||||
if (LT(1) == IToken.t_else) {
|
||||
consume(IToken.t_else);
|
||||
if (LT(1) == IToken.t_if) {
|
||||
//an else if, don't recurse, just loop and do another if
|
||||
cleanupLastToken();
|
||||
if( if_statement != null )
|
||||
{
|
||||
if_statement.setElseClause( new_if_statement );
|
||||
new_if_statement.setParent( if_statement );
|
||||
new_if_statement.setPropertyInParent( IASTIfStatement.ELSE );
|
||||
if_statement = new_if_statement;
|
||||
}
|
||||
continue if_loop;
|
||||
}
|
||||
IASTStatement elseStatement = statement();
|
||||
new_if_statement.setElseClause( elseStatement );
|
||||
elseStatement.setParent( new_if_statement );
|
||||
elseStatement.setPropertyInParent( IASTIfStatement.ELSE );
|
||||
if_statement = new_if_statement;
|
||||
}
|
||||
else
|
||||
if_statement = new_if_statement;
|
||||
break if_loop;
|
||||
}
|
||||
cleanupLastToken();
|
||||
return if_statement;
|
||||
case IToken.t_switch:
|
||||
startOffset = consume( IToken.t_switch ).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
IASTExpression switch_condition = condition();
|
||||
|
|
Loading…
Add table
Reference in a new issue