Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 348644

Summary: IntegerLiteral.getType() and DecimalLiteral.getType() may be incorrect
Product: z_Archived Reporter: Matt Heitz <mheitz>
Component: EDTAssignee: Matt Heitz <mheitz>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: pharmon
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Matt Heitz CLA 2011-06-07 16:54:13 EDT
IntegerLiteral.getType() always returns "int".  Paul, what are the rules from RBD?  I believe we use the smallest type possible: smallint/int/bigint/decimal.  Is that right?

DecimalLiteralImpl.getType() on a negative number will give the wrong answer.  We need to subtract one from the length so as not to count the negative sign as a digit.
Comment 1 Matt Heitz CLA 2011-06-07 16:55:21 EDT
If we use my suggestion from BugĀ 348642 , IntegerLiteral could be fixed this way:

	public Type getType() {
		if ( fitsInSmallint() )
			return IRUtils.getEGLPrimitiveType(Type_Smallint);
		else if ( fitsInInt() )
			return IRUtils.getEGLPrimitiveType(Type_Int);
		else if ( fitsInBigint() )
			return IRUtils.getEGLPrimitiveType(Type_Bigint);

		int length = getValue().length();
		if ( isNegated() )
		{
			length--;
		}
		return IRUtils.getEGLPrimitiveType(Type_Decimal, length, 0);
	}

DecimalLiteral's fix is:
	public Type getType() {
		String value = getValue();
		int length = value.length() - 1;
		if ( isNegated() )
		{
			length--;
		}
		int decimals = value.substring( value.indexOf( '.' ) + 1 ).length();		
		return IRUtils.getEGLPrimitiveType( Type_Decimal, length, decimals );
	}
Comment 2 Paul Harmon CLA 2011-06-14 14:08:17 EDT
i have put in fixes for IntgerLiteralImpl and DecimalLiteralImpl
Comment 3 Matt Heitz CLA 2011-06-14 20:25:54 EDT
Looks good.

And just for the historical record, integers that are too big to be a bigint have type num, not decimal as I put in the description.