As with array constructors, we can encounter a decl-type-spec for a
structure-constructor while the decl-type-spec for the
type-declaration-stmt is still active. So here too we need to save and
restore the state.
In this case, it is done in DeclarationVisitor, so add
SetDeclTypeSpecState() to get and set the state.
Example where this occurs:
```
type(t(2)) :: x = t(2)()
```
Original-commit: flang-compiler/f18@aa5ca8d7b2
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
When we encounter a ProcedureDesignator, if it is an external procedure
(i.e. there is no visible declaration) it must be implicitly created in
the global scope, not the current scope.
If there is already a symbol there (i.e. a module) it is an error, even
if that symbol is not visible due to an IMPORT statement.
Original-commit: flang-compiler/f18@835e234ded
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
We can encounter a decl-type-spec for an array constructor while the
decl-type-spec for type-declaration-stmt is still active:
```
integer, allocatable :: a(:) = [integer :: 1, 2, 3]
```
To handle this, save the state of the current decl-type-spec while
processing the second one, then restore when done.
Original-commit: flang-compiler/f18@d125a0f612
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
We need to save the names of specific procedures that appear in a
ProcedureStmt or GenericStmt to resolve at the end of the specification
section. They may be forward references to interface bodies.
We were saving them in the GenericDetails but that was not the right
place: we need to save the parser::Name so that we can eventually
resolve it to a Symbol, but the symbol table should not contains
references to Name because they go away with the parse tree.
The fix is to save the mapping in a new multimap, specificProcs_ in
InterfaceVisitor. We can reference parser::Names there and resolve them
during ResolveSpecificsInGenerics(). We no longer need to clutter
GenericDetails with data structures for unresolved names.
Also handle the case where a specific procedure is use-associated from
another module.
Original-commit: flang-compiler/f18@c7f7b1e72d
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
Character decl-type-specs with no kind specified had no kind written to
the .mod file. That was different from the other intrinsic types which
always have an explicit type. This change make character like the other
intrinsic types.
Original-commit: flang-compiler/f18@5b4f047a13
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
IntrinsicTypeSpec was used for all intrinsics except for character.
Change it to be a common base class for NumericTypeSpec,
LogicalTypeSpec, and CharacterTypeSpec.
Change DeclTypeSpec to categorize the intrinsics as Numeric, Logical,
and Character. Add some utility methods: AsIntrinsic() and IsNumeric().
In scope.h, give the functions that create DeclTypeSpecs better names.
In semantics.h, replace MakeIntrinsicTypeSpec() with MakeNumericType()
and MakeLogicalType() as it does not apply to character types.
Original-commit: flang-compiler/f18@8ad92d069c
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
Recognize the various ways of specifying character lengths.
Define CharacterTypeSpec with length and kind and store them in the
current scope, as is done with DerivedTypeSpec (which can also have
length parameters).
Note: IntrinsicTypeSpec is no longer used for characters, so it
should have a different name. Similarly, in DeclTypeSpec::Category,
Intrinsic does not include Character.
Original-commit: flang-compiler/f18@5f84785193
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
Now DeclTypeSpecs are stored in the scope so that they remain available
as long as the scope exists. DeclTypeSpecs for intrinsic types are
stored in the global scope; those for derived types are in the current
scope. They can contains type parameter values so they can't be reused.
Add `Semantics::MakeIntrinsicTypeSpec` to simplify creating
DeclTypeSpecs for intrinsic types.
Replace `std::optional<DeclTypeSpec>` with `DeclTypeSpec *` as they do
not need to be copied around.
Also fix a small bug with writing `class(t(...))` to the module file --
the type parameters were missing.
Original-commit: flang-compiler/f18@e4744418fc
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
Type parameters were sorted by the order of the type-param-def-stmts.
But we need to preserve the order of the type-param-name-list.
The is the order of positional parameters in a derived-type-spec.
So add `paramNames` to `DerivedTypeDetails` to preserve the original
order. Using this allows us to write module files with both the
type-param-name-list and type-param-def-stmts in the original order.
Also fix a bug where a duplicate type-param-def caused a spurious
extra error. If `MakeTypeSymbol()` reports an error we should not
call `SetType()` because it will just report another error.
Original-commit: flang-compiler/f18@3ca55b6333
Reviewed-on: https://github.com/flang-compiler/f18/pull/239
This fixes a problem with converting the ubound call in the example
below back to Fortran (in this case, for writing to the .mod file).
One of the ActualArguments encountered in ProcedureRef::AsFortran is
a `std::nullopt`, so we need to handle that case.
```
module m
real :: x(10)
real :: y(ubound(x, dim=1))
end module
```
Original-commit: flang-compiler/f18@c5ace6b824
Reviewed-on: https://github.com/flang-compiler/f18/pull/240