diff -r ce997a27c516 -r c752b113237b stage3/narrow_candidate_datatypes.cc --- a/stage3/narrow_candidate_datatypes.cc Sun Feb 15 16:08:56 2015 +0000 +++ b/stage3/narrow_candidate_datatypes.cc Mon Mar 09 19:22:00 2015 +0000 @@ -416,6 +416,48 @@ +/*************************/ +/* B.1 - Common elements */ +/*************************/ +/*******************************************/ +/* B 1.1 - Letters, digits and identifiers */ +/*******************************************/ +/* Before the existance of this derived_datatype_identifier_c class, all identifiers were stored in the generic identifier_c class. + * Since not all identifiers are used to identify a datatype, the fill/narrow algorithms could not do fill/narrow on all identifiers, and relied + * on the parent class to do the fill/narrow when apropriate (i.e. when the identifier was known to reference a datatype + * for example, in a variable declaration --> var1: some_user_defined_type;) + * + * However, at least one location where an identifier may reference a datatype has not yet been covered: + * array1: ARRAY [1..2] OF INT; + * array2: ARRAY [1..2] OF array1; (* array1 here is stored as a derived_datatype_identifier_c) + * + * Instead of doing it like the old way, I have opted to do a generic fill/narrow for all derived_datatype_identifier_c + * This means that we can now delete the code of all parents of derived_datatype_identifier_c that are still doing the fill/narrow + * explicitly (assuming we do also implement the visitor for poutype_identifier_c). However, I will leave this code cleanup for some later oportunity. + */ +void *narrow_candidate_datatypes_c::visit(derived_datatype_identifier_c *symbol) { + // If this symbol was used (for example) in an ARRAY [1..2] OF (i.e. a datatype in an array) + // then the symbol->datatype of this derived_datatype_identifier_c has not yet been set by the previous visit() method! + // We therefore set the datatype ourselves! + if ((NULL == symbol->datatype) && (symbol->candidate_datatypes.size() == 1)) + symbol->datatype = symbol->candidate_datatypes[0]; + return NULL; +} + + +/* The datatype of a poutype_identifier_c is currently always being set by the parent object, so we leave this code commented out for now. */ +/* +void *narrow_candidate_datatypes_c::visit( poutype_identifier_c *symbol) { + // If this symbol was used (for example) in an ARRAY [1..2] OF (i.e. a datatype in an array) + // then the symbol->datatype of this derived_datatype_identifier_c has not yet been set by the previous visit() method! + // We therefore set the datatype ourselves! + if ((NULL == symbol->datatype) && (symbol->candidate_datatypes.size() == 1)) + symbol->datatype = symbol->candidate_datatypes[0]; + return NULL; +} +*/ + + /**********************/ /* B 1.3 - Data types */