Commit graph

8 commits

Author SHA1 Message Date
Tim Keith
9727b06813 [flang] Support for USE statements.
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
2018-05-03 15:57:56 -07:00
Tim Keith
18cee3e8e6 [flang] Add copyright notices.
For source files (C++, Fortran, CMake) add copyright and license.
For documentation files add just copyright.

Original-commit: flang-compiler/f18@38381aed83
Reviewed-on: https://github.com/flang-compiler/f18/pull/74
2018-05-01 12:50:34 -07:00
Tim Keith
cb37c3625a [flang] Non-fatal error for repeated access spec
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
2018-04-25 10:46:39 -07:00
Tim Keith
94fa0fd890 [flang] Initial support for name resolution in modules.
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
2018-04-24 17:07:15 -07:00
Tim Keith
744427238c [flang] Rewrite function calls to array element references
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
2018-04-23 12:46:56 -07:00
Tim Keith
1c291436f5 [flang] Implement parse tree rewriting.
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
2018-04-18 15:06:35 -07:00
Tim Keith
8ca01883bc [flang] Resolve array specifications of entities.
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
2018-04-12 12:59:42 -07:00
Tim Keith
af2940cfb6 [flang] Continue work on name resolution.
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
2018-04-11 13:13:14 -07:00