Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348644 - IntegerLiteral.getType() and DecimalLiteral.getType() may be incorrect
Summary: IntegerLiteral.getType() and DecimalLiteral.getType() may be incorrect
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Matt Heitz CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-07 16:54 EDT by Matt Heitz CLA
Modified: 2017-02-23 14:15 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.