Commit graph

98 commits

Author SHA1 Message Date
peter klausler b64a39e1ea [flang] Prep for review
Original-commit: flang-compiler/f18@e86eae005e
Reviewed-on: https://github.com/flang-compiler/f18/pull/200
2018-10-04 13:55:51 -07:00
peter klausler 7e87d5a297 [flang] Parse nonlabel DO within label DO better; add -fdebug-semantics; more testing
Original-commit: flang-compiler/f18@2825a45956
Reviewed-on: https://github.com/flang-compiler/f18/pull/200
Tree-same-pre-rewrite: false
2018-10-04 13:54:07 -07:00
peter klausler 93a7f1f85c [flang] work on structure components
Original-commit: flang-compiler/f18@619b6957b4
Reviewed-on: https://github.com/flang-compiler/f18/pull/195
Tree-same-pre-rewrite: false
2018-09-25 15:23:58 -07:00
Tim Keith 7edb7ec69b [flang] Add top-level Semantics class
Refactor to create the Semantics class that is responsible for holding
state during semantics (the scope tree and messages) and managing the
logic of the various phases of semantic processing. Eliminate static
Scope::globalScope.

The messages generated during semantic processing are accumulated in a
Messages data member of Semantics so that individual phases don't need
to emit them to std::cerr. This is now done by the driver so that it has
control over where they go and eliminates other includes of iostream.
To do this, the messages object is passed in to the various semantics
operations.

Move DumpSymbols into semantics.cc: it doesn't belong in resolve-names.cc
and it depends on the global scope, so it's as good a place as any.
The call to RewriteParseTree is also moved to Semantics.

Original-commit: flang-compiler/f18@771d0e1293
Reviewed-on: https://github.com/flang-compiler/f18/pull/186
Tree-same-pre-rewrite: false
2018-09-14 15:04:50 -07:00
Eric Schweitz 43da7a187e [flang] Remove incorrect error message
Original-commit: flang-compiler/f18@9ef54520df
Reviewed-on: https://github.com/flang-compiler/f18/pull/184
Tree-same-pre-rewrite: false
2018-09-13 15:46:17 -07:00
Eric Schweitz b1938138a7 [flang] Add semantics checking for END xxx statements.
Add a negative test for END xxx names.
Reverse the sequence of calls such that resolve-label is before
resolve-name.

Original-commit: flang-compiler/f18@5fe62f108c
Reviewed-on: https://github.com/flang-compiler/f18/pull/184
Tree-same-pre-rewrite: false
2018-09-13 15:46:17 -07:00
peter klausler 6c6234be9e [flang] clean up for review
Original-commit: flang-compiler/f18@d3d81b1e6f
Reviewed-on: https://github.com/flang-compiler/f18/pull/183
Tree-same-pre-rewrite: false
2018-09-12 16:29:20 -07:00
peter klausler 003c8329ba [flang] add left(), right(), and comments
Original-commit: flang-compiler/f18@372fd06508
Reviewed-on: https://github.com/flang-compiler/f18/pull/183
Tree-same-pre-rewrite: false
2018-09-12 16:29:16 -07:00
Tim Keith ae3b96456f [flang] Simplify representation of intrinsic types
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
2018-09-11 17:33:42 -07:00
Eric Schweitz df4575f6b9 [flang] Add label resolution design document, pass, and tests
Original-commit: flang-compiler/f18@e0d0df900c
Reviewed-on: https://github.com/flang-compiler/f18/pull/170
Tree-same-pre-rewrite: false
2018-09-11 14:01:25 -07:00
peter klausler ce231b9559 [flang] Clean up messaging: make Say() member function templates more flexible, hide MessageFormattedText instances
Original-commit: flang-compiler/f18@59d774382f
Reviewed-on: https://github.com/flang-compiler/f18/pull/165
Tree-same-pre-rewrite: false
2018-08-09 10:17:40 -07:00
Tim Keith 96b187efdf [flang] Add support for submodules
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
2018-08-02 16:21:27 -07:00
Tim Keith 070073426a [flang] Add support for -module option
The `-module` option specifies where to write module files. It is also
the first place search for modules files. The current options name and
behavior match PGI compilers.

To support this, reorganize `ModFileWriter` to be more like `ModFileReader`.
The gives the client a way to set the output directory and fetch the
error messages. A bunch of static member functions in `ModFileWriter`
were changed to non-member functions so they didn't need to be exposed
in `mod-files.h`.

Original-commit: flang-compiler/f18@2717846e81
Reviewed-on: https://github.com/flang-compiler/f18/pull/147
2018-07-25 17:07:38 -07:00
Tim Keith f62f8b655d [flang] Implement reading of module files
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
2018-07-25 10:11:38 -07:00
peter klausler aa6c6f97a9 [flang] Begin semantic analysis of expressions.
Original-commit: flang-compiler/f18@34615fdc37
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:52 -07:00
Hongyon Suauthai 9d24bf5f53 [flang] Add predefined macro _OPENMP to 201511 - yyyymm of the OpenMP Spec.
Original-commit: flang-compiler/f18@859912b54e
Reviewed-on: https://github.com/flang-compiler/f18/pull/140
2018-07-23 10:43:44 -07:00
peter klausler 5bd2ac4952 [flang] Pass -Mnobackslash to pgf90 unless f18 -fbackslash is used.
Original-commit: flang-compiler/f18@df5058ff97
Reviewed-on: https://github.com/flang-compiler/f18/pull/133
2018-07-19 15:50:39 -07:00
peter klausler 888786b346 [flang] Really fix backslash escapes.
Original-commit: flang-compiler/f18@a8c702c103
Reviewed-on: https://github.com/flang-compiler/f18/pull/133
Tree-same-pre-rewrite: false
2018-07-19 15:35:55 -07:00
peter klausler 80ece7418a [flang] Define LanguageFeatureControl, use it everywhere.
Original-commit: flang-compiler/f18@9a95107610
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:24 -07:00
peter klausler f701b42920 [flang] Better language feature enablement and warnings.
Original-commit: flang-compiler/f18@359e4d2c60
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:23 -07:00
Tim Keith cde0b5cc87 [flang] Use brace initialization in tools/f18
Also reformat dump.cc.

Original-commit: flang-compiler/f18@1cc4fe2788
Reviewed-on: https://github.com/flang-compiler/f18/pull/127
2018-07-17 07:05:35 -07:00
Tim Keith 0c575ed548 [flang] Implement writing of .mod files.
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
2018-07-16 16:23:18 -07:00
Tim Keith f77f9309fc [flang] Add -funparse-with-symbols to enable new behavior
Original-commit: flang-compiler/f18@7ad44e7e33
Reviewed-on: https://github.com/flang-compiler/f18/pull/112
2018-06-26 15:40:52 -07:00
Tim Keith 89840b5087 [flang] Support unparse with symbol annotations.
When `-fdebug-dump-symbols` is supplied with `-funparse`, include symbol
information in comments in the Fortran output. This will be used for
testing to verify that correct symbols are defined and references in
the right place.

In `UnparseWithSymbols()`, walk the parse tree and collect symbol
definitions and references, organized by statement. When a symbol is
defined across several statement it is associated with the first.
The definition of implicitly defined symbols is associated with the
first reference.

To write out the symbol information, a new optional argument is added to
`Unparse()`: it is a function that is called immediately before each
statement is unparsed. We pass in a function that prints out the symbol
information collected for that statement.

Add `Symbol::GetType()` to make it easier to write the symbol types
and add `Symbol::SetType()` for uniformity.

Original-commit: flang-compiler/f18@2e827de4ad
Reviewed-on: https://github.com/flang-compiler/f18/pull/112
Tree-same-pre-rewrite: false
2018-06-26 15:01:42 -07:00
Tim Keith 2541df532a [flang] Name resolution for derived types.
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
2018-06-22 08:21:19 -07:00
peter klausler 5bc907602c [flang] unit testing for LZBC
Original-commit: flang-compiler/f18@c8541fb8fb
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:16 -07:00
Tim Keith fe1691d21c [flang] Add Dump() routines for debugging.
Add Dump() routines based on operator<< for the type so that they are
easy to call from the debugger. Overload for both pointer and reference
types and for dumping to std::cerr or a specific ostream.

Original-commit: flang-compiler/f18@ec6676eff0
Reviewed-on: https://github.com/flang-compiler/f18/pull/99
2018-06-11 15:40:31 -07:00
Hongyon Suauthai 6f7b4fa691 [flang] Add OpenMP parallel directives and private/firstprivate clauses to parser.
Original-commit: flang-compiler/f18@ea8abe45cc
Reviewed-on: https://github.com/flang-compiler/f18/pull/91
Tree-same-pre-rewrite: false
2018-05-16 07:28:54 -07:00
peter klausler e8490cdc60 [flang] Clean up dump-parse-tree.h
Original-commit: flang-compiler/f18@5024116397
Reviewed-on: https://github.com/flang-compiler/f18/pull/80
Tree-same-pre-rewrite: false
2018-05-04 10:30:34 -07:00
peter klausler da846e6bd9 [flang] reformat for merge
Original-commit: flang-compiler/f18@ccf265dad5
Reviewed-on: https://github.com/flang-compiler/f18/pull/81
Tree-same-pre-rewrite: false
2018-05-04 09:35:12 -07:00
peter klausler 45b6e41494 [flang] Ignore spaces in FORMAT specifications, even in free form.
Original-commit: flang-compiler/f18@3f65d35b1c
Reviewed-on: https://github.com/flang-compiler/f18/pull/81
Tree-same-pre-rewrite: false
2018-05-04 09:35:09 -07:00
peter klausler 5e69a7507d [flang] Make messages more like clang's.
Original-commit: flang-compiler/f18@176cdf8e6c
Reviewed-on: https://github.com/flang-compiler/f18/pull/81
Tree-same-pre-rewrite: false
2018-05-04 09:35:06 -07:00
Stephane Chauveau 63141a0739 [flang] Manual backport of sch_llvm branch
Original-commit: flang-compiler/f18@17ee2d8e3a
Reviewed-on: https://github.com/flang-compiler/f18/pull/78
Tree-same-pre-rewrite: false
2018-05-03 14:54:53 +02:00
Steve Scalpone ead68854e1 [flang] Update CMakefiles and #include paths.
Original-commit: flang-compiler/f18@1b7b8259b3
Reviewed-on: https://github.com/flang-compiler/f18/pull/76
2018-05-02 09:21:03 -07:00
Steve Scalpone 209afdcea2 [flang] Removed unused files and declarations.
Renamed ParseTreeDump to dump-parse-tree.

Original-commit: flang-compiler/f18@9de97328f1
Reviewed-on: https://github.com/flang-compiler/f18/pull/76
Tree-same-pre-rewrite: false
2018-05-02 09:15:33 -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 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
peter klausler 30f337a36d [flang] Finish cleaning up debug-parser.
Original-commit: flang-compiler/f18@0ef551025a
Reviewed-on: https://github.com/flang-compiler/f18/pull/66
Tree-same-pre-rewrite: false
2018-04-23 15:44:28 -07:00
peter klausler 7335482d98 [flang] Complete parser instrumentation and caching of failures.
Original-commit: flang-compiler/f18@9843dbf211
Reviewed-on: https://github.com/flang-compiler/f18/pull/62
2018-04-19 17:02:12 -07:00
peter klausler 56b09e08eb [flang] Parser instrumentation and fail-fast experiment begun.
Original-commit: flang-compiler/f18@ab46163d6e
Reviewed-on: https://github.com/flang-compiler/f18/pull/62
Tree-same-pre-rewrite: false
2018-04-19 15:46:02 -07:00
peter klausler 2c06be3fb8 [flang] First cut at parser instrumentation with pass/fail counters.
Original-commit: flang-compiler/f18@21ed700afa
Reviewed-on: https://github.com/flang-compiler/f18/pull/62
Tree-same-pre-rewrite: false
2018-04-19 13:58:02 -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 c9d838e8a7 [flang] Add -fdebug-dump-parse-tree and -fdebug-resolve-names
"f18 -fdebug-resolve-names -fparse-only ..." is equivalent to what
test-type used to do, so the test-type executable can be eliminated.

-fdebug-dump-parse-tree does the parse-tree dumping that test-sema
does, but test-sema does more so I have left it alone.

Original-commit: flang-compiler/f18@8b3816528e
Reviewed-on: https://github.com/flang-compiler/f18/pull/55
2018-04-12 20:01:40 -07:00
Tim Keith 6c772ac40b [flang] Improve include file sorting.
Includes like "../dir/file.h" should sort after local includes.
This change fixes that and applies the new formatting.

Now the order (in reverse) is:
- system includes
- includes from llvm or clang (this is from the default IncludeCategories)
- includes of ../something
- everything else

Original-commit: flang-compiler/f18@324643d63a
Reviewed-on: https://github.com/flang-compiler/f18/pull/52
2018-04-12 12:23:20 -07:00
Tim Keith da414d7c3f [flang] Collect implicit type rules and report related errors.
ImplicitRules maintains a mapping of initial character of an identifier
to its implicit type.

ImplicitRulesVisitor visits the ImplicitStmt and related parse tree
nodes and updates the rules.

Emit errors messages in these cases:
- implicit type specified more than once for a letter
- IMPLICIT statement and IMPLICIT NONE in same scope
- IMPLICIT statement and IMPLICIT NONE(TYPE) in same scope
- more than one IMPLICIT NONE in a scope
- IMPLICIT statement with empty range of letters
- IMPLICIT NONE statement after PARAMETER statement
- TYPE or EXTERNAL repeated in an IMPLICIT NONE statement

Also start emitting error messages through the parser::Messages
interface. An instance of Messages is created from the cooked source and
saved in the MessageHandler class. It tracks the source location of the
current statement and provides a way to emit messages associated with
that statement.

Original-commit: flang-compiler/f18@e12fea9850
Reviewed-on: https://github.com/flang-compiler/f18/pull/41
Tree-same-pre-rewrite: false
2018-04-06 14:09:49 -07:00
peter klausler 1e1ea723c5 [flang] Better error recovery, some debugging.
Original-commit: flang-compiler/f18@b7509f0e5b
Reviewed-on: https://github.com/flang-compiler/f18/pull/38
Tree-same-pre-rewrite: false
2018-04-02 16:06:18 -07:00
peter klausler af22e07f71 [flang] Revamp messaging. Add ""_err_en_US to denote fatal error messages.
Original-commit: flang-compiler/f18@7ddc807a1b
Reviewed-on: https://github.com/flang-compiler/f18/pull/38
Tree-same-pre-rewrite: false
2018-04-02 15:51:04 -07:00
peter klausler 1f3c41b521 [flang] Emit warnings in free form when a required space is missing.
Original-commit: flang-compiler/f18@e41917d144
Reviewed-on: https://github.com/flang-compiler/f18/pull/35
Tree-same-pre-rewrite: false
2018-03-29 16:06:31 -07:00
peter klausler e0482bb778 [flang] Simplify test-type and test-sema to use parser::Parsing wrapper class.
Original-commit: flang-compiler/f18@3741a652ed
Reviewed-on: https://github.com/flang-compiler/f18/pull/34
Tree-same-pre-rewrite: false
2018-03-28 17:15:00 -07:00
peter klausler 448e3e4cca [flang] Resolve merge with code pushed to master.
Original-commit: flang-compiler/f18@d75d86f28e
Reviewed-on: https://github.com/flang-compiler/f18/pull/34
Tree-same-pre-rewrite: false
2018-03-28 15:11:12 -07:00