[Patch,gfortran] ENUMERATIONS and ENUMERATORS

Gaurav Gautam, Noida gauravga@noida.hcltech.com
Mon Aug 1 13:11:00 GMT 2005


Hi,


This patch implements a New Feature of FORTRAN 2003: Enumerations and enumerators

Description of the feature
---------------------------
An enumeration is a set of enumerators. An enumerator is a named integer constant. An enumeration 

definition specifies the enumeration and its set of enumerators of the corresponding integer kind.


Example of an enumeration definition
------------------------------------
ENUM, BIND(C)
ENUMERATOR :: RED = 4, BLUE = 9
ENUMERATOR YELLOW
END ENUM

This declares an enumerator with constants 4, 9, 10.
If a value is not specified for an enumerator, it is taken as one greater than the previous
enumerator or zero if it is the first.

For more details of the feature, FORTRAN language reference manual can be referred.


Implementation Stratagy 
-----------------------
1) Designing a parser that parses the grammer for enumerations and enumerators


Parser has been modified to parse the following Grammer
-------------------------------------------------------

enum-def          is          enumerator-def-stmt
                                    [ enumerator-def-stmt ] ...
                              end-enum-stmt

enum-def-stmt     is          ENUM, BIND(C)

enumerator-def-stmt     is    ENUMERATOR [ :: ] enumerator-list

enumerator        is          named-constant [ = scalar-int-initialization-expr ]

end-enum-stmt     is          END ENUM




2) Storing the parse tree and modifications in symbol table

According to the fortran standard:

"The following declaration might be equivalent to the above enumeration definition.
INTEGER(SELECTED_INT_KIND(2)), PARAMETER :: RED = 4, BLUE = 9, YELLOW = 10 "

The enumerators that have been parsed have actually been stored as integers with parameter attribute 

and with the kind type given by (SELECTED_INT_KIND())

Thus the enumeration shown in the example after parsing, will appear to the rest of frontend as the 

following statement has been parsed:

INTEGER(SELECTED_INT_KIND(arg)), PARAMETER :: RED = 4, BLUE = 9, YELLOW = 10 "

where the argument "arg" of SELECTED_INT_KIND() is decided by the following equation.

 -10 ^ arg         < maximum of the values of all enumerators <    10^ arg     -----equation

the maximum values of enumerator here is 10
so 
arg by above equation comes out to be 2.



3) Error handling

Appropriate Error handling has been done to check the parsing errors and the semantic errors.

4) I have REGTESTED it on SuSe linux -- X86_AMD64.



Please note: I have the copy right assignment with me.


Thanks to FX for solving my queries.

Best Regards
Gaurav Gautam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: changelog_code_20050801
Type: application/octet-stream
Size: 2111 bytes
Desc: changelog_code_20050801
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050801/8298dd1d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: changelog_test_20050801
Type: application/octet-stream
Size: 685 bytes
Desc: changelog_test_20050801
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050801/8298dd1d/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: enum_20050801.diff
Type: application/octet-stream
Size: 21760 bytes
Desc: enum_20050801.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050801/8298dd1d/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testsuite_20050801.diff
Type: application/octet-stream
Size: 10181 bytes
Desc: testsuite_20050801.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050801/8298dd1d/attachment-0003.obj>


More information about the Fortran mailing list