View | Details | Raw Unified | Return to bug 295851
Collapse All | Expand All

(-)parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java (+27 lines)
Lines 33-38 Link Here
33
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
33
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
34
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
34
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
35
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
35
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
36
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
36
import org.eclipse.cdt.core.dom.ast.IASTExpression;
37
import org.eclipse.cdt.core.dom.ast.IASTExpression;
37
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
38
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
38
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
39
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
Lines 6503-6506 Link Here
6503
	        }
6504
	        }
6504
	    }
6505
	    }
6505
	}
6506
	}
6507
	
6508
	
6509
	
6510
	
6511
	//
6512
	// /* check that enumerator values are evaluated correctly for
6513
	//  * conditional expressions */
6514
	//
6515
	//enum
6516
	//{
6517
	//    _ISalnum = 11 < 8 ? 1 : 2,
6518
	//    _ISalnum2 = 11 > 8 ? 1 : 2
6519
	//};
6520
	//
6521
	public void testBug295851() throws Exception {
6522
	    for(ParserLanguage lang : ParserLanguage.values()) {
6523
            IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang);
6524
            IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclSpecifier();
6525
            IEnumerator enumeratorBinding = (IEnumerator)enumSpec.getEnumerators()[0].getName().resolveBinding();
6526
            IValue value = enumeratorBinding.getValue();
6527
            assertEquals( 2, value.numericalValue().longValue());
6528
            IEnumerator enumeratorBinding2 = (IEnumerator)enumSpec.getEnumerators()[1].getName().resolveBinding();
6529
            IValue value2 = enumeratorBinding2.getValue();
6530
            assertEquals( 1, value2.numericalValue().longValue());
6531
	    }
6532
	}
6506
}
6533
}
(-)parser/org/eclipse/cdt/internal/core/dom/parser/Value.java (-12 / +12 lines)
Lines 316-323 Link Here
316
		if (e instanceof IASTConditionalExpression) {
316
		if (e instanceof IASTConditionalExpression) {
317
			IASTConditionalExpression cexpr= (IASTConditionalExpression) e;
317
			IASTConditionalExpression cexpr= (IASTConditionalExpression) e;
318
			Object o= evaluate(cexpr.getLogicalConditionExpression(), unknownSigs, unknowns, maxdepth);
318
			Object o= evaluate(cexpr.getLogicalConditionExpression(), unknownSigs, unknowns, maxdepth);
319
			if (o instanceof Long) {
319
			if (o instanceof Number) {
320
				Long v= (Long) o;
320
				Number v= (Number) o;
321
				if (v.longValue() == 0) {
321
				if (v.longValue() == 0) {
322
					return evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth);
322
					return evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth);
323
				}
323
				}
Lines 330-336 Link Here
330
			final IASTExpression pe = cexpr.getPositiveResultExpression();
330
			final IASTExpression pe = cexpr.getPositiveResultExpression();
331
			Object po= pe == null ? o : evaluate(pe, unknownSigs, unknowns, maxdepth);
331
			Object po= pe == null ? o : evaluate(pe, unknownSigs, unknowns, maxdepth);
332
			Object neg= evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth);
332
			Object neg= evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth);
333
			return CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + SEPARATOR + neg.toString();
333
			return "" + CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + SEPARATOR + neg.toString(); //$NON-NLS-1$
334
		}
334
		}
335
		if (e instanceof IASTIdExpression) {
335
		if (e instanceof IASTIdExpression) {
336
			IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding();
336
			IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding();
Lines 462-469 Link Here
462
			return value;
462
			return value;
463
		}
463
		}
464
		
464
		
465
		if (value instanceof Long) {
465
		if (value instanceof Number) {
466
			long v= (Long) value;
466
			long v= ((Number) value).longValue();
467
			switch(unaryOp) {
467
			switch(unaryOp) {
468
			case IASTUnaryExpression.op_prefixIncr:
468
			case IASTUnaryExpression.op_prefixIncr:
469
			case IASTUnaryExpression.op_postFixIncr:
469
			case IASTUnaryExpression.op_postFixIncr:
Lines 504-512 Link Here
504
	}
504
	}
505
	
505
	
506
	private static Object combineBinary(final int op, final Object o1, final Object o2) throws UnknownValueException {
506
	private static Object combineBinary(final int op, final Object o1, final Object o2) throws UnknownValueException {
507
		if (o1 instanceof Long && o2 instanceof Long) {
507
		if (o1 instanceof Number && o2 instanceof Number) {
508
			long v1= (Long) o1;
508
			long v1= ((Number) o1).longValue();
509
			long v2= (Long) o2;
509
			long v2= ((Number) o2).longValue();
510
			switch(op) {
510
			switch(op) {
511
			case IASTBinaryExpression.op_multiply:
511
			case IASTBinaryExpression.op_multiply:
512
				return v1*v2;
512
				return v1*v2;
Lines 601-608 Link Here
601
			if (reeval.pos != reeval.fExpression.length)
601
			if (reeval.pos != reeval.fExpression.length)
602
				return UNKNOWN;
602
				return UNKNOWN;
603
			
603
			
604
			if (obj instanceof Long)
604
			if (obj instanceof Number)
605
				return create(((Long) obj).longValue());
605
				return create(((Number) obj).longValue());
606
			
606
			
607
			ICPPUnknownBinding[] ua;
607
			ICPPUnknownBinding[] ua;
608
			if (unknown.isEmpty()) {
608
			if (unknown.isEmpty()) {
Lines 645-652 Link Here
645
			Object cond= reevaluate(reeval, maxdepth);
645
			Object cond= reevaluate(reeval, maxdepth);
646
			Object po= reevaluate(reeval, maxdepth);
646
			Object po= reevaluate(reeval, maxdepth);
647
			Object neg= reevaluate(reeval, maxdepth);
647
			Object neg= reevaluate(reeval, maxdepth);
648
			if (cond instanceof Long) {
648
			if (cond instanceof Number) {
649
				Long v= (Long) cond;
649
				Number v= (Number) cond;
650
				if (v.longValue() == 0) {
650
				if (v.longValue() == 0) {
651
					return neg;
651
					return neg;
652
				}
652
				}

Return to bug 295851