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
Intrinsic types are now just a TypeCategory and a int kind. If no kind
is specified the default is used so that every type has an explicit
kind. This caused changes in the expected results of some of the tests.
Add support for "double precision" and "double complex".
Intrinsic types are now stored as values in DeclTypeSpec so none of the
KindedTypeHelper machinery is needed any more.
Eliminate DerivedTypeDef, DataComponentDef, ProcComponentDef,
TypeBoundProc. The components and bindings of a derived type are now
represented by the corresponding Scope.
Original-commit: flang-compiler/f18@4ad8ffb187
Reviewed-on: https://github.com/flang-compiler/f18/pull/182
Tree-same-pre-rewrite: false
Handle BIND statement and PARAMETER statement. They are different from
other attribute-setting statements so some refactoring of
HandleAttributeStmt is required. And for PARAMETER, SetType needs to
report an error if the implicitly determined type is changed later. This
requires operator== on DeclTypeSpec.
Resolve names in allocate statements, pointer assignment statements,
substring expressions, and type parameter values.
Original-commit: flang-compiler/f18@79ad96b976
Reviewed-on: https://github.com/flang-compiler/f18/pull/177
We were trying to write only symbols that are part of the public API of
a module to the .mod file. The problem with that is that submodules need
access to the private symbols in their ancestor modules and submodules.
For now, just write out all of the symbols, private or otherwise.
We could be more precise by omitting some private symbols for modules
that don't have separate module procedures and so can't have submodules.
Also, the old implementation went into an infinite loop for recursive
derived types.
This makes CollectSymbols simpler, so have it do both the collecting and
sorting. Make it static so that the types don't have to be defined in
mod-file.h.
Original-commit: flang-compiler/f18@33a10d6238
Reviewed-on: https://github.com/flang-compiler/f18/pull/177
Tree-same-pre-rewrite: false
A symbol is created with EntityDetails if we don't know whether it is a
procedure or data object. At the end of the specification part, if we
don't know it's a procedure then it must be an object, so convert it
then. So after name resolution there should be no symbols with
EntityDetails.
Also, a couple of small fixes:
- need to visit sub-nodes of shape specs so that any names get resolved
- don't report an error for an array element mis-parsed as a call
Original-commit: flang-compiler/f18@0effecd225
Reviewed-on: https://github.com/flang-compiler/f18/pull/177
Tree-same-pre-rewrite: false
Also eliminate `derivedTypeData_`. Information about derived types needed
during name resolution is in `derivedTypeInfo_` and the permanent record
is the symbol table.
Original-commit: flang-compiler/f18@789960bd95
Reviewed-on: https://github.com/flang-compiler/f18/pull/175
Tree-same-pre-rewrite: false
Track PRIVATE statement in derived type components and in procedure
bindings. These are recorded in derivedTypeInfo_ (along with the name
appearing in EXTENDS) and used to modify the accessibility attributes of
components and bindings. Also track SEQUENCE statement.
Detect erroneous PRIVATE in derived types that aren't in modules.
Detect incompatible SEQUENCE types.
Save EXTENDS symbol and SEQUENCE in DerivedTypeDetails and write them to
the .mod file.
Original-commit: flang-compiler/f18@f29d620714
Reviewed-on: https://github.com/flang-compiler/f18/pull/175
Tree-same-pre-rewrite: false
Add TypeParamDetails for symbols that represent type parameters.
Create such symbols when a type-param-def-stmt is encountered.
At the end of the derived-type-def, check the parameters named
in the type-param-name-list against those encountered in each
type-param-def-stmt.
Original-commit: flang-compiler/f18@c15247bb30
Reviewed-on: https://github.com/flang-compiler/f18/pull/173
Tree-same-pre-rewrite: false
Add new kinds of symbol details: ProcBindingDetails, FinalProcDetails.
and GenericBindingDetails. The last is not yet implemented.
Write them to the .mod file.
Recognize DEFERRED and NON_OVERRIDABLE attributes. Enforce C783.
Resolve CLASS(t) similarly to resolution of TYPE(t).
Original-commit: flang-compiler/f18@0c0a9ab79e
Reviewed-on: https://github.com/flang-compiler/f18/pull/173
Tree-same-pre-rewrite: false
Resolve names and do implicit typing in ArrayElement and LoopBounds.
Fix problem with creation of UseErrorDetails: when a conflict occurs,
record both the original USE and the new one.
Resolve the type name in TypeAttrSpec::Extends. Move CheckUseError to
DeclarationVisitor so that it can be used in ResolveDerivedType.
Report error on unresolved names. I.e. after name resolution, check each
parser::Name and verify we have a Symbol for it. This is on by default
now but it could be an option.
Original-commit: flang-compiler/f18@1c8cbc6e53
Reviewed-on: https://github.com/flang-compiler/f18/pull/173
Tree-same-pre-rewrite: false
A `BLOCK` statement opens a new scope. It is different from other scopes
in that implicitly typed entities are defined in the enclosing non-block
scope, not immediately in the block. This means that `IMPORT` statements
can cause them to be hidden.
Check that blocks can't have `IMPLICIT` statements in them. It is simpler
for the parser not to deal with the different between a
specification-part and a block-specification-part.
Change `ImplicitRules` to have a parent that is consulted when there isn't
an answer in the current one. For an interface body that does not happen
but for all other nested scopes it does. This parent link eliminates the
need for the `implicitRules_` stack. Make `isImplicitNoneType_` and
`isImplicitNoneExternal_` optional: not set means look in parent.
Fixesflang-compiler/f18#71.
Remove `CurrNonTypeScope()` and put the logic in `Symbol::FindSymbol`.
Original-commit: flang-compiler/f18@a153a2ee33
Reviewed-on: https://github.com/flang-compiler/f18/pull/169
Tree-same-pre-rewrite: false
Host association is done by search for symbols using `Scope::FindSymbol()`
which looks for the the name in the parent scope if the import rules
permit it.
Import statements are implemented using `importKind_` and `importNames_`
in class `Scope`. Most of the constraints are checked when the
`ImportStmt` is encountered. `CheckImports()` is called at the end of
the `SpecificationPart` to verify the names mentioned in the IMPORT
statement. That has to happen then so that we can detect if an imported
name is hidden by a declaration in the current scope.
Original-commit: flang-compiler/f18@0d50c8a8ba
Reviewed-on: https://github.com/flang-compiler/f18/pull/167
Tree-same-pre-rewrite: false
Symbols for submodules have `ModuleDetails` with `isSubmodule` set.
Scopes for submodules have `Module` kind and have a parent scope that
is also `Module` kind.
Scopes for modules now contain a mapping of submodule name to scope
so that we can find them without having to search the scope tree or
re-read their `.mod` file.
The module file for submodule `s` with ancestor module `m` is named `m-s.mod`.
The tree structure of scopes means module file writing is now recursive.
Similarly, reading the module file for a submodule may require reading
the module files of its parent and ancestor. `ResolveNames` now requires
the parent scope to be passed in -- it is not always the global scope.
`test_modfiles.sh` now handles an argument that is a filename glob so
that the test can involve multiple files. This allows `modfile09` to
test reading of `.mod` files for modules and submodules.
Original-commit: flang-compiler/f18@2e4424dbc8
Reviewed-on: https://github.com/flang-compiler/f18/pull/160
Tree-same-pre-rewrite: false
When a use-stmt is encountered for a module that isn't in the global
scope, search for and read the appropriate `.mod` file. To perform the
search, pass the search directories in to ResolveNames.
For modules that were read from `.mod` files, we have to keep the cooked
source from being deleted so that the names so that references to names
stay valid. So we store the cooked source in the Scope of the module as
a `unique_ptr`.
Add `Symbol::Flag::ModFile` to distinguish module symbols that were read
from a `.mod` file rather than from the current compilation. Use it to
prevent writing those back out.
Fix test_errors.sh to run the compiler in the temp subdirectory --
otherwise tests could be affected by `.mod` files left from previous
tests.
Original-commit: flang-compiler/f18@207065999c
Reviewed-on: https://github.com/flang-compiler/f18/pull/145
When a procedure is included by name in a generic (either with a
procedure statement in a generic interface or with a generic statement)
we can't immediately resolve it to a subprogram symbol. That is because
the subprogram may be defined later in the specification part. Instead,
collect the names (and whether they should be module procedures) and
resolve them to symbols at the end of the specification part. Also
detect duplicate names then.
This is needed for module file reading as these forward references can
occur there.
Write generics to module file using generic statements. This allows us to
include the access-spec.
Original-commit: flang-compiler/f18@d11d002084
Reviewed-on: https://github.com/flang-compiler/f18/pull/132
Write symbols for external subprogram interfaces as interface-stmts.
Those go in the decls part of the module file, as opposed to contained
subprograms which go in the contains part. See modfile06.f90.
Write symbols with GenericDetails to module files. The specific
procedures of a generic interface are always written as procedure-stmts.
If they also have specific interfaces those are written in a separate
interface-stmt. See modfile07.f90.
Fix a bug where `real, external :: f` was not written like
`real f; external f`. We have to notice the EXTERNAL attribute on the
type-declaration-stmt and convert the entity to a procedure entity.
See modfile08.f90.
Fix a bug where a use-associated symbol is referenced in a
procedure-designator. We were not resolving that correctly.
Change ModFileWriter::PutEntity to include the kind of Details when
it reports an internal error due to a kind it can't handle.
Make DetailsToString public to support that.
Change test_errors.sh to fail if the f18 command exits due to a signal.
We were missing bugs where the correct errors were written out but then
module file writing crashed (due to failure to handle generics mentioned
above). Non-zero exit status is okay because we are expecting
compilation errors.
Change test_modfile.sh to allow for the expected module file contents to
be indented so the tests are easier to read.
Original-commit: flang-compiler/f18@82a7931e51
Reviewed-on: https://github.com/flang-compiler/f18/pull/132
Tree-same-pre-rewrite: false
Allow for bash anywhere on path.
Allow for utilites to be in /bin as well as /usr/bin.
Don't count on sed understanding '\t'.
The options to mktemp aren't portable. Instead just create a per-test
temp directory in the working directory (i.e. <build-dir>/test/semantics).
Setting the KEEP environment variable causes them all to be kept to help
in investigating failures.
Fixesflang-compiler/f18#128.
Original-commit: flang-compiler/f18@3736ceeca8
Reviewed-on: https://github.com/flang-compiler/f18/pull/129
The source files contain the expected contents of generated .mod files.
`test_modfile.sh` compiles the source file and verifies that the correct
.mod files are generated.
Original-commit: flang-compiler/f18@a23f53c1a7
Reviewed-on: https://github.com/flang-compiler/f18/pull/126
Tree-same-pre-rewrite: false
Module file writing is implemented in mod-file.cc. They need to be
written after all semantic checking. Until then, for testing, write
them out whenever names are resolved.
There is a header comment in the .mod files but it is mostly a
placeholder until we can read them in and do something with it.
Rename `Symbol::details<D>` to `Symbol::get<D>`. This asserts that the
details of the symbol match D and returns that type. But we need a way
to access the details as a variant as well (not just one of its types).
`details()` is the best name for that, especially as we already have
`set_details()`. Renaming the old `details` to `get` also better matches
`has` which is used to check which variant is present.
Original-commit: flang-compiler/f18@8d14be1a16
Reviewed-on: https://github.com/flang-compiler/f18/pull/126
Tree-same-pre-rewrite: false
Recognize `IntentStmt` and use `HandleAttributeStmt()` to implement it
as is done with other attribute statements. Add `Attr::INTENT_INOUT` as
a separate attribute for `INTENT(INOUT)`.
Collect attributes from the prefix and suffix of `FunctionStmt` and
`SubroutineStmt` (including `BIND(C)`) and set them on the subprogram
symbol.
Create a test for this using `test_symbol.sh`. It compiles with
`-funparse-with-symbols` and compares the output with the symbols in
comments in the input.
Change `test_errors.sh` to be similar to `test_symbol.sh`: check usage
and allow `F18` environment variable to override the path to the
compiler.
Original-commit: flang-compiler/f18@384828a22f
Reviewed-on: https://github.com/flang-compiler/f18/pull/120
Tree-same-pre-rewrite: false
This consists of:
- a new kind of symbols to represent them with DerivedTypeDetails
- creating symbols for derived types when they are declared
- creating a new kind of scope for the type to hold component symbols
- resolving entity declarations of objects of derived type
- resolving references to objects of derived type and to components
- handling derived types with same name as generic
Type parameters are not yet implemented.
Refactor DeclTypeSpec to be a value class wrapping an IntrinsicTypeSpec
or a DerivedTypeSpec (or neither in the TypeStar and ClassStar cases).
Store DerivedTypeSpec objects in a new structure the current scope
MakeDerivedTypeSpec so that DeclTypeSpec can just contain a pointer to
them, as it currently does for intrinsic types.
In GenericDetails, add derivedType field to handle case where generic
and derived type have the same name. The generic is in the scope and the
derived type is referenced from the generic, similar to the case where a
generic and specific have the same name. When one of these names is
mis-recognized, we sometimes have to fix up the 'occurrences' lists
of the symbols.
Assign implicit types as soon as an entity is encountered that requires
one. Otherwise implicit derived types won't work. When we see 'x%y' we
have to know the type of x in order to resolve y. Add an Implicit flag
to mark symbols that were implicitly typed
For symbols that introduce a new scope, include a pointer back to that
scope.
Add CurrNonTypeScope() for the times when we want the current scope but
ignoring derived type scopes. For example, that happens when looking for
types or parameters, or creating implicit symbols.
Original-commit: flang-compiler/f18@9bd16da020
Reviewed-on: https://github.com/flang-compiler/f18/pull/109
The Fortran source files in test/semantics all contain expected
errors in comments. The script test_errors.sh compiles a file with
'f18 -fdebug-resolve-names -fparse-only' and compares the actual
errors produced against the expected ones.
The change to resolve15.f90 is necessary because test_errors.sh can't
handle two expected errors for the same source line.
A useful command to run these is 'ctest -R f90 --output-on-failure'.
-R means only run tests with f90 in the name
--output-on-failure prints the output of test_errors.sh when a test
fails, showing the expected and actual messages that differ.
Original-commit: flang-compiler/f18@df18ee7bc9
Reviewed-on: https://github.com/flang-compiler/f18/pull/105
Add ObjectEntityDetails and ProcEntityDetails to distinguish between an
entity from an object-decl and one from a proc-decl. When we don't know,
it stays as EntityDetails until it is resolved. DeclareEntity() in
DeclarationVisitor creates this kind of symbol.
Add flags to Symbol as a convenient place for boolean flags common to
many kinds of symbols. Use it to mark symbols known to be functions or
subroutines so that we can report errors when they are used incorrectly.
Improve handling of EXTERNAL statement.
Handle ProcDecl nodes and add symbols for them.
Partial processing of derived types. Data component declarations are
processed and added to the derived type. Define TypeBoundProc and
TypeBoundGeneric in type.h. Procedure components, type-bound procedures,
etc. are not handled yet and nothing is done with the derived type once
it is created. Eliminate DerivedTypeDefBuilder in favor of just setting
fields in derivedTypeData_.
Add GetDeclTypeSpec to go with BeginDeclTypeSpec and EndDeclTypeSpec, to
avoid directly access the private variable.
Add tests in resolve20.f90 for errors related to procedure declarations.
Add missing copyrights to other tests.
Original-commit: flang-compiler/f18@40e65c1465
Reviewed-on: https://github.com/flang-compiler/f18/pull/97
Tree-same-pre-rewrite: false
When a generic or specific procedure is use-associated, make a copy of
it in the current scope (replacing the symbol that has UseDetails) so
that we can make changes to it. This permits a generic to be defined in
one module and extended with more specific procedures in another.
When a specific procedure has the same name as its generic, it can't be
stored directly in the scope because that is indexed by name and the
generic is already there. So instead we store the specific in the
GenericDetails of the generic symbol.
Enforce the rule that a generic and a procedure can only have the same
name if the procedure is one of the specifics of the generic.
Refactorings done is support of this change:
- Add FindSymbol() and EraseSymbol() as helpers to find or erase a
symbol in the current scope. Make use of FindSymbol() where appropriate.
- Add SayAlreadyDeclared() to report a common error.
Original-commit: flang-compiler/f18@be479b9887
Reviewed-on: https://github.com/flang-compiler/f18/pull/95
Add subprogram symbols for each interface-body and set isInterface on
them. Create a symbol with GenericDetails for each generic interface
block and add interface specifications to the specific procedures of
the generic. InterfaceVisitor takes care of this.
Before processing the specification part of modules and subprograms,
collect the names of module subprograms and internal subprograms and add
them to the symbol table with SubprogramNameDetails. This allows us to
reference them from interface blocks in the specification part.
SubprogramNameDetails is converted to SubprogramDetails when the real
subprogram is visited.
This is achieved by setting subpNamesOnly_ and then walking the
ModuleSubprogramPart or InternalSubprogramPart. Creating the symbol and
scope for a module or subprogram now happens when the Module,
SubroutineSubprogram, or FunctionSubprogram node is encountered so
this can happen in the right order.
Add BeginSubprogram and EndSubprogram to handle the parts in common
between subprograms and interface specifications.
Add GenericSpec to type.h to represent all possible generic specs.
Only generic names are resolved so far.
Add tests for new error messages. Change resolve02.f90 to reflect the
new errors reported.
Original-commit: flang-compiler/f18@03148b49dd
Reviewed-on: https://github.com/flang-compiler/f18/pull/88
Tree-same-pre-rewrite: false
When a USE statement is encountered, find the scope corresponding to the
module. This is now stored in the ModuleDetails of the module symbol.
useModuleScope_ tracks this while processing the USE. Currently only
modules defined in the same file work because we don't have module files.
At the end of a USE that isn't a use-only, add all public names that
were not renamed.
AddUse() handles recording of a USE by creating a local symbol with
UseDetails that tracks the use-symbol in the module and the location of
the USE (for error messages). If an ambiguous USE is detected, the
UseDetails are replaced by UseErrorDetails. This tracks the locations of
all the uses so that they can be referenced in a diagnostic.
Detect attempts to re-declare use-associated symbols as well as changing
their attributes (except for ASYNCHRONOUS and VOLATILE).
Add missing checks for access-stmt in scoping units other than modules.
Add tests for the new errors.
Reorganize the MessageHandler::Say() overloadings to prevent them from
becoming too numerous.
Original-commit: flang-compiler/f18@cc0523134c
Reviewed-on: https://github.com/flang-compiler/f18/pull/79
When an access statement repeats the same attribute, make it a non-fatal
diagnostic. Also, include the previous specification in the message.
resolve11.f90 now illustrates both cases, fatal and non-fatal.
Original-commit: flang-compiler/f18@1f567c740a
Reviewed-on: https://github.com/flang-compiler/f18/pull/70
Tree-same-pre-rewrite: false
Recognize modules and open and close the corresponding scope.
Handle PUBLIC and PRIVATE statements and set the corresponding
attributes on entity declarations in the module.
Refactoring (no functional changes): Make CheckImplicitSymbol() and
GetVariableName() overloadings private and out-of-line.
Add missing option to f18 help.
Original-commit: flang-compiler/f18@d01cacca63
Reviewed-on: https://github.com/flang-compiler/f18/pull/70
Tree-same-pre-rewrite: false
parse-tree.h, parse-tree.cc:
Add FunctionReference::ConvertToArrayElementRef() to convert a function
reference to an array element reference.
Factor out MakeArrayElementRef() to use in ConvertToArrayElementRef()
and also in converting statement functions to array element assignments.
resolve-names.cc:
Recognize references to functions and subroutines and add symbols for them.
Detect declaration conflicts from these and check `IMPLICIT NONE(EXTERNAL)`.
rewrite-parse-tree.cc:
Find function references that need to be converted and rewrite them.
Original-commit: flang-compiler/f18@e5a1e0aaef
Reviewed-on: https://github.com/flang-compiler/f18/pull/65
Add parse-tree-mutator.h like parse-tree-visitor.h except that the Walk
functions take non-const references to parse tree nodes so the Pre and
Post methods of the mutator that are passed around can make changes to
the parse tree.
Change ExecutionPart to be a class that wraps a list so that it can be
identified during parse tree walking.
Add Symbol* field to parser::Name for the result of symbol resolution.
In parse tree dumper, dump symbol when it is there instead of just name.
Add RewriteParseTree to walk the parse tree, fill in resolved symbols in
Name nodes, and make necessary changes to the structure. Currently that
consists of rewriting statement functions as array assignments when
appropriate.
In ResolveNames, call RewriteParseTree if the resolution was successful.
Recognize a statement function that comes after a mis-identified
statement function and report an error. resolve08.f90 tests this case.
Add -fdebug-dump-symbols to dump the scope tree and symbols in each scope.
This is implemented by DumpSymbols in resolve-names.cc. Add an optional
symbol to scopes that correspond to symbols (e.g. subprograms). Remove
debug output from ResolveNamesVisitor as this option can be used instead.
Original-commit: flang-compiler/f18@9cd3372265
Reviewed-on: https://github.com/flang-compiler/f18/pull/60
Tree-same-pre-rewrite: false
Add ArraySpecVisitor to recognize the various forms of array specifications.
They are tracked in arraySpec_ and attrArraySpec_. Both are needed because
a declaration like `integer, dimension(4) :: x(2,2), y` has two different
array-specs.
The method DeclareEntity was extracted out to handle the common part for
EntityDecl, ObjectDecl, and DimensionStmt. AllocatableStmt and TargetStmt
are now handled through their contained ObjectDecl.
The test resolve07 checks the interactions between these kinds of declarations.
Rename ComponentArraySpec to ArraySpec as it doesn't just occur in components.
Fix some 'begin' and 'end' methods to start with upper-case letters.
Original-commit: flang-compiler/f18@3d4d7430b5
Reviewed-on: https://github.com/flang-compiler/f18/pull/53
In Symbol and Scope, use SourceName (== parser::CharBlock) in place of
Name (== std::string) so that names in the symtab have provenance. We
may ultimately have multiple source locations associated with a symbol.
ImplicitRules: Add isImplicitNoneType and isImplicitNoneExternal flags.
MessageHandler: Add methods to emit messages associated with source
locations.
Detect conflicting declarations of symbols (e.g. as subprogram and
variable).
Handle attribute statements like ASYNCHRONOUS statement: make sure the
symbol is present and set the attribute on it. Check that these all have
a type declared by the end of the specification part if IMPLICIT NONE.
Find variables named in Variable and Expr nodes and check they have
types declared if IMPLICIT NONE. Otherwise, make sure they are in the
symtab and apply the implicit type rules at the end of the scope.
Push a scope for MainProgram nodes and add a symbol for the name if it
has one.
Rename Scope::map_type to Scope::mapType
Add tests for errors currently being detected. There is no framework for
running them yet, just source files with the expected errors in
comments.
Original-commit: flang-compiler/f18@39e6fa4169
Reviewed-on: https://github.com/flang-compiler/f18/pull/49
Tree-same-pre-rewrite: false