GabrielDosReis/ipr

As_type("short float") is no longer possible

Closed this issue · 4 comments

With a recent change of moving Name from Expr to Node, we lost ability to manufacture trivial unique types on demand as described in https://www.stroustrup.com/gdr-bs-macis09.pdf, namely,

As_type(Identifier("int"))
As_type(Identifier("typename"))

This is not a problem for these particular types in questions, since they are pre-manufactured in a lexicon as built-ins, but, at the moment there is no easy way to create a custom types of this kind.

Currently, we manufacture such types in impl.cxx via impl::Builtin<ipr::As_type> which is represented as an As_type with the specified name.

            : anytype(get_identifier("typename"), cxx_linkage(), anytype),
              classtype(get_identifier("class"), cxx_linkage(), anytype),
              uniontype(get_identifier("union"), cxx_linkage(), anytype),
              enumtype(get_identifier("enum"), cxx_linkage(), anytype),
              namespacetype(get_identifier("namespace"), cxx_linkage(), anytype)

Those types are also recorded in a map:

         record_builtin_type(anytype);
         record_builtin_type(classtype);
         record_builtin_type(uniontype);
...
         util::rb_tree::container<node_ref<ipr::As_type>> builtin_map;
...

      void Lexicon::record_builtin_type(const ipr::As_type& t) {
         builtin_map.insert(t, unary_compare());
      }

Which makes me think that at some point the idea was to allow creation those type via get_builtin or something like that and use that map to make sure all those types are unique, but, was not added.

Which makes me think that at some point the idea was to allow creation those type via get_builtin or something like that and use that map to make sure all those types are unique, but, was not added.

Do you imply that the user should be able to create new builtin types that were not hard-coded in the lexicon previously?

Yes. My understanding that it was the intention. A compiler on a particular platform may have a non-standard integer or floating types, for example, and still would like to be able to target IPR

@GorNishanov - you observed

This is not a problem for these particular types in questions, since they are pre-manufactured in a lexicon as built-ins, but, at the moment there is no easy way to create a custom types of this kind.

With the introduction of Symbol, now you have As_type(Symbol(Identifier("our builtin type"))) to manufacture any builtin type