Add `LazyExpr` class to represent expressions in the symbol table.
Initially they contain a pointer to an expression in the parse tree.
After name resolution is complete and symbols are filled in in the parse
tree, `LazyExpr`s are resolved to `evaluate::Expr<evaluate::SomeType>`.
This is done by `ResolveSymbolExprs()`.
Change `Bound` and `ParamValue` to save their value as a `LazyExpr`.
Change `ObjectEntityDetails` and `TypeParamDetails` to save the initial
value as a `LazyExpr`.
Eliminate `IntExpr` and `IntConst` classes, which were just place-holders.
Add `Clone()` to `ShapeSpec`, `Bound`, `LazyExpr`. Normally they should
be moved but in `ObjectEntityDetails::set_shape()` we need to make copies.
Save type parameter values in `derivedTypeSpec_`. `typeParamValue_` is
not needed.
Write out initial values, type parameter values, and bounds to .mod files.
Evaluate parameter values in expressions.
Make some errors non-fatal so that tests can continue to pass.
Original-commit: flang-compiler/f18@b90cadfc53
Reviewed-on: https://github.com/flang-compiler/f18/pull/223
Tree-same-pre-rewrite: false
When a SeparateModuleSubprogram is encountered, check that there is a
corresponding declaration in the current module/submodule or an ancestor.
When it's the current program unit, special handling is required to
avoid trying to declare it again.
Module subprograms with the `MODULE` prefix are handled similarly.
The `hasModulePrefix` flag is passed in to `BeginSubprogram` to
distinguish this case.
Extract common part of `Post(SubroutineStmt)` and `Post(FunctionStmt)` into
`PostSubprogramStmt`. Add code there to ensure that separate module
procedures do not have `EXTERNAL` set. This requires a fix to `ModFileWriter`
to correctly decide when a subprogram is declared in an interface block.
Extract `WalkSubprogramPart` into a separate function. It walks the
internal or module subprograms collecting their names. It is needed to
handle separate module subprograms.
Original-commit: flang-compiler/f18@339b65f251
Reviewed-on: https://github.com/flang-compiler/f18/pull/218
Tree-same-pre-rewrite: false
Push a new scope for constructs and statements that require one
(DataStmt, DO CONCURRENT, ForallConstruct, ForallStmt -- there are more
to do). Currently we use the Block kind of scope because there is no
difference. Perhaps that kind should be renamed to Construct, though it
does apply to statements as well as constructs.
Add DeclareConstructEntity to create a construct or statement entity.
When the type is not specified it can come from the type of a symbol in
the enclosing scope with the same name. Change DeclareObjectEntity et al.
to return the symbol declared, for the benefit of DeclareConstructEntity.
Use DeclareConstructEntity for DO CONCURRENT index-name, LOCAL, and
LOCAL_INIT variables and the data-i-do-variable in DataImpliedDo
Names in SHARED locality spec need special handling: create a new kinds
of symbol with HostAssocDetails to represent the host-association of the
shared variables within the construct scope. That symbol gets the
LocalityShared flag without affecting the symbol in the outer scope.
HostAssoc symbols may be useful in other contexts, e.g. up-level
references to local variables.
Add parser::DoConstruct::IsDoConcurrent() because DO CONCURRENT loops
introduce a construct scope while other DO loops do not.
Move CanonicalizeDo to before name resolution so that name resolution
doesn't have to deal with labeled DO CONCURRENT loops.
Allow for type of index name to be specified in ConcurrentHeader.
Resolve the derived type name in an AllocateStmt, StructureConstructor
Original-commit: flang-compiler/f18@bc7b989136
Reviewed-on: https://github.com/flang-compiler/f18/pull/214
Change it so that the first time a symbol is referenced, its full
definition is emitted, prefixed by "DEF:", and subsequent references
are prefixed with "REF:".
This doesn't give exactly the same results as before but it is
sufficient for testing and is simpler and easier to maintain.
The expected results need to be tweaked accordingly.
Original-commit: flang-compiler/f18@27b5d082a8
Reviewed-on: https://github.com/flang-compiler/f18/pull/214
Tree-same-pre-rewrite: false
Resolve the index name in a FORALL, DO, or DO CONCURRENT.
Handle pointer-stmt. Add DeclareUnknownEntity() to declare an entity
that is not yet know to be an object or procedure. This is used in the
EntityDecl and PointerDecl cases.
When an array element assignment is mistakenly parsed as a statement
function, ensure the index names are resolved.
Detect erroneous use-association with local name that matches the name
of the containing subprogram.
Cleanup: Eliminate GetVariableName() and CheckImplicitSymbol() in favor
of using the Resolve* functions consistently. Add ResolveName() to do
what CheckImplicitSymbol() used to do.
Disable warnings about unresolved names for some categories of
constructs that are not yet implemented: common blocks, namelist
statements, etc. These will be turned back on when they are implemented.
Original-commit: flang-compiler/f18@9a41bf37fd
Reviewed-on: https://github.com/flang-compiler/f18/pull/210
Check that construct names don't conflict with other construct names or
entities in the same scoping unit.
This requires adding symbols for them. MiscDetails was added for cases
like this where we don't need to save much information about the symbol.
References to construct names are recorded too, so those names are now
expected to be resolved and no longer are exceptions in rewrite-parse-tree.cc
Checking that construct names match is still done in resolve-labels.cc.
Original-commit: flang-compiler/f18@0ad79ff029
Reviewed-on: https://github.com/flang-compiler/f18/pull/210
Tree-same-pre-rewrite: false
The "%RE" or "%IM" is parsed as a structure-component.
If the base has type COMPLEX and the component name is one
of those, allow it without comment.
Note that the `parser::Name` for these components don't get
symbols filled in, so we still get a warning that they are
unresolved. We have to figure out how to deal with names
like this that we won't have symbols for.
Fixesflang-compiler/f18#188.
Original-commit: flang-compiler/f18@1d4a84fe3c
Reviewed-on: https://github.com/flang-compiler/f18/pull/194
Tree-same-pre-rewrite: false
Convert each Entity to ObjectEntity at the end of each scope.
Add `ConvertToObjectEntity()` to achieve this, similar to
`ConvertToProcEntity()`. Move them both up into `ScopeHandler`
because they need to be called from `PopScope()`.
In a proc-decl, only mark the proc as a function if it has a return type.
If no return type is declared, function vs. subroutine is determined by:
- for a module it is a subroutine (at end of specification-part)
- otherwise it is by usage
If an entity that could otherwise be a function is used as the base of a
structure component, that forces it to be an object. Because we have to
change it to an object entity at that point, the `base` in `FindComponent()`
can't be const, and that propagates to all of its callers.
Remove the name argument to `ApplyImplicitRules` as it is unneeded.
Fixesflang-compiler/f18#191.
Original-commit: flang-compiler/f18@9bd8bf7c37
Reviewed-on: https://github.com/flang-compiler/f18/pull/194
Tree-same-pre-rewrite: false
When looking for a component name in a derived type, also look in the
parent type. Before adding a component to a derived type, report an
error if it already has one with that name. Check that components are
accessible when they are accessed.
Add the "parent component" to derived types (i.e. a component with the
same name as the parent type). The symbol is marked with the
`ParentComp` flag so we can avoid writing it to `.mod` files.
Add calls to `add_occurrence()` so that those particular instances of
`parser::Name` get their symbol set.
Change `DeclareObjectEntity` and `DeclareProcEntity` to use `SourceName` as
the name passed in rather than `parser::Name`.
Fix some problems in `unparse-with-symbols.cc` on statements that both
define and reference names.
Fixesflang-compiler/f18#187.
Original-commit: flang-compiler/f18@664b9627f2
Reviewed-on: https://github.com/flang-compiler/f18/pull/192
Tree-same-pre-rewrite: false