Commit graph

496 commits

Author SHA1 Message Date
peter klausler
4795738c40 [flang] Commit work in progress to branch for f18 repository move.
Original-commit: flang-compiler/f18@e0db6903c7
Reviewed-on: https://github.com/flang-compiler/f18/pull/117
Tree-same-pre-rewrite: false
2018-07-09 16:25:57 -07:00
Tim Keith
d7d69474c8 [flang] Fix bug recognizing derived type constructor call
A ProcedureDesignator is a derived type constructor call if the name
resolves to a derived type. We need to recognize it as such and not
report an error. It may be in another derived type so we have to call
FindSymbol() first to find the derived type.

Most of the diffs are due to `symbol` changing from a reference to a
pointer.

In this example we were reporting an error on the first `t1()` and
resolving the second as an external function call.
```
module m
  type :: t1
  end type
  type(t1) :: x = t1()
  type t2
    type(t1) :: y = t1()
  end type
end module
```

Original-commit: flang-compiler/f18@717b22ca2b
Reviewed-on: https://github.com/flang-compiler/f18/pull/116
2018-07-09 15:25:49 -07:00
Tim Keith
a39376c08b [flang] Add missing copyright.
Original-commit: flang-compiler/f18@cf7087b381
Reviewed-on: https://github.com/flang-compiler/f18/pull/114
2018-07-05 10:36:18 -07:00
Tim Keith
c0c19100be [flang] Check consistency of generic interfaces.
The specific procedures in a generic interface must be all functions or
all subroutines. If there is a derived type with the same name they can
only be functions.

Original-commit: flang-compiler/f18@e02cef047a
Reviewed-on: https://github.com/flang-compiler/f18/pull/114
Tree-same-pre-rewrite: false
2018-07-05 10:28:34 -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
peter klausler
97f0a05235 [flang] Incorporate suggestions from code review.
Original-commit: flang-compiler/f18@c66bd9ab15
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
2018-06-22 16:44:23 -07:00
peter klausler
cf410675cf [flang] Begin folding, with simple test, as sanity check on usability.
Original-commit: flang-compiler/f18@3839c65cd5
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:59:28 -07:00
peter klausler
efcbf1f7df [flang] clean up for push
Original-commit: flang-compiler/f18@8b5bbcedba
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:59:28 -07:00
peter klausler
4c11bc07d4 [flang] Prepare for check-in
Original-commit: flang-compiler/f18@2f5b2d5f40
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:59:28 -07:00
peter klausler
4da490882b [flang] Operator overloads for expression construction.
Original-commit: flang-compiler/f18@a4d3a736cf
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:59:27 -07:00
peter klausler
e5e5f6319f [flang] clean up clang warnings from master
Original-commit: flang-compiler/f18@1c9aa95f8d
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:59:25 -07:00
peter klausler
7a3f25ce8a [flang] More refinement, use const on subexpressions.
Original-commit: flang-compiler/f18@f484325c61
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:06 -07:00
peter klausler
953c667703 [flang] Simplification
Original-commit: flang-compiler/f18@a50ce6e499
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:06 -07:00
peter klausler
a55ea1b5d5 [flang] fix builds, all now clear
Original-commit: flang-compiler/f18@7c32a531a0
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:06 -07:00
peter klausler
4b3dea1d38 [flang] Dump complex expressions
Original-commit: flang-compiler/f18@da25b870d3
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:05 -07:00
peter klausler
32b2ce7282 [flang] More dumping code
Original-commit: flang-compiler/f18@43d147144a
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:05 -07:00
peter klausler
508ed8dd76 [flang] Use unique_ptr for operands. Refactor comparisons.
Original-commit: flang-compiler/f18@92e154e76e
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:05 -07:00
peter klausler
a88a55b500 [flang] Expression formatting
Original-commit: flang-compiler/f18@3d0977a57e
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:04 -07:00
peter klausler
dd5470b128 [flang] Change memcpy to memmove for overlap case.
Original-commit: flang-compiler/f18@cb400284e4
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:04 -07:00
peter klausler
9e1ba097f5 [flang] Numeric constant formatting and tests.
Original-commit: flang-compiler/f18@ade6442020
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:04 -07:00
peter klausler
3d867f3202 [flang] Character LEN, operator overloadings
Original-commit: flang-compiler/f18@08c32de24c
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:58:04 -07:00
peter klausler
229d6c413a [flang] Finish first cut at expression.h.
Original-commit: flang-compiler/f18@07142e7fad
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:56:18 -07:00
peter klausler
e03280c09c [flang] Expression work
Original-commit: flang-compiler/f18@b60c84fff4
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:56:17 -07:00
peter klausler
c2e06e25cd [flang] reformat c++
Original-commit: flang-compiler/f18@6c5c9b3165
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:56:17 -07:00
peter klausler
ca1b8d80f6 [flang] first cut at expressions
Original-commit: flang-compiler/f18@b06c5486e4
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:56:17 -07:00
peter klausler
cc13dbdde1 [flang] begin expression representation
Original-commit: flang-compiler/f18@627c057d5c
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:56:16 -07:00
peter klausler
dacbfeef32 [flang] Documentation
Original-commit: flang-compiler/f18@27f6927053
Reviewed-on: https://github.com/flang-compiler/f18/pull/111
Tree-same-pre-rewrite: false
2018-06-22 14:56:16 -07:00
Tim Keith
c7eb38530c [flang] Fix problems in PR 109 when compiling with clang.
This gets the code base back to compiling cleanly with clang after
pull request 109.

There were two overloadings of `Post(const parser::DeclarationTypeSpec::Type &)`.
The one in DeclarationVisitor needed to call the one in DeclTypeSpecVisitor.
This was fixed by introducing a new function, SetDerivedDeclTypeSpec, to do
the equivalent thing.

Original-commit: flang-compiler/f18@81e447bf4e
Reviewed-on: https://github.com/flang-compiler/f18/pull/110
2018-06-22 14:08:04 -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
Tim Keith
890b6d55e7 [flang] Refactor DeclTypeSpec and DerivedTypeSpec classes.
Make DerivedTypeSpec a simple wrapper around the name of the type.
Leave out type parameter values until we are ready to resolve them
as well.

Change DeclTypeSpec to be an old-fashioned union with an enum to
indicate what is in it. std::variant doesn't work well here because
we wanted the enum visible in the class' API and there is not a
1-to-1 mapping between enumerators and data stored.

Original-commit: flang-compiler/f18@03bdeef790
Reviewed-on: https://github.com/flang-compiler/f18/pull/109
Tree-same-pre-rewrite: false
2018-06-20 13:39:31 -07:00
Tim Keith
b40c9ee2b2 [flang] Change how memory for Symbol instances is managed.
With this change, all instances Symbol are stored in class Symbols.
Scope.symbols_, which used to own the symbol memory, now maps names to
Symbol* instead. This causes a bunch of reference-to-pointer changes
because of the change in type of key-value pairs. It also requires a
default constructor for Symbol, which means owner_ can't be a reference.

Symbols manages Symbol instances by allocating a block of them at a time
and returning the next one when needed. They are never freed.

The reason for the change is that there are a few cases where we need
to have a two symbols with the same name, so they can't both live in
the map in Scope. Those are:
1. When there is an erroneous redeclaration of a name we may delete the
   first symbol and replace it with a new one. If we have saved a pointer
   to the first one it is now dangling. This can be seen by running
   `f18 -fdebug-dump-symbols -fparse-only test/semantics/resolve19.f90`
   under valgrind. Subroutine s is declared twice: each results in a
   scope that contains a pointer back to the symbol for the subroutine.
   After the second symbol for s is created the first is gone so the
   pointer in the scope is invalid.
2. A generic and one of its specifics can have the same name. We currently
   handle that by moving the symbol for the specific into a unique_ptr
   in the generic. So in that case the symbol is owned by another symbol
   instead of by the scope. It is simpler if we only have to deal with
   moving the raw pointer around.
3. A generic and a derived type can have the same name. This case isn't
   handled yet, but it can be done like flang-compiler/f18#2 above. It's more complicated
   because the derived type and the generic can be declared in either
   order.

Original-commit: flang-compiler/f18@55a68cf023
Reviewed-on: https://github.com/flang-compiler/f18/pull/107
2018-06-19 16:06:41 -07:00
Tim Keith
0d701085e0 [flang] Fix bug in adding symbols to parse tree.
We were collecting symbols in a map of SourceName to Symbol*.
This is wrong because sometimes different occurrences of a name
map to different symbols (e.g. in different scopes).
SourceName::begin() is unique for each occurrence so use that
as the map key instead.

The problem can be reproduced by running:
`f18 -fdebug-resolve-names -fparse-only -fdebug-dump-parse-tree`
on the following source. The two symbols 'i' should have different
types and they were both coming out as INTEGER because they both
pointed to the first symbol for 'i'.

```
module m
  integer :: i
contains
  subroutine s
    real :: i
  end
end
```

Original-commit: flang-compiler/f18@a165c717ff
Reviewed-on: https://github.com/flang-compiler/f18/pull/107
Tree-same-pre-rewrite: false
2018-06-19 14:59:41 -07:00
peter klausler
b23701f7d0 [flang] Rearrange some facilities into a new lib/common.
Original-commit: flang-compiler/f18@279af1e817
Reviewed-on: https://github.com/flang-compiler/f18/pull/106
2018-06-18 11:05:17 -07:00
Tim Keith
6178163bfd [flang] Add name resolution tests
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
2018-06-15 14:54:34 -07:00
peter klausler
adc3fc1777 [flang] Test 64-bit reals too.
Original-commit: flang-compiler/f18@67fd551441
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
2018-06-15 10:02:09 -07:00
peter klausler
57f4186ca2 [flang] Address review comments
Original-commit: flang-compiler/f18@d96917c701
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:09 -07:00
peter klausler
b19a9baba4 [flang] More rearrangement, and debug an edge case with Underflow flag.
Original-commit: flang-compiler/f18@57ef08433e
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:07 -07:00
peter klausler
7e7d97ed4c [flang] Move member functions complex.h -> complex.cc
Original-commit: flang-compiler/f18@445333b13e
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:06 -07:00
peter klausler
b0e644e708 [flang] Remove work-around in resolve-names.cc.
Original-commit: flang-compiler/f18@5dc0e037f5
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:05 -07:00
peter klausler
18d3312600 [flang] Cleaning up Real<> for review.
Original-commit: flang-compiler/f18@a87f324a7f
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:04 -07:00
peter klausler
fcf72703d2 [flang] Prepare for review.
Original-commit: flang-compiler/f18@266d25f630
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:03 -07:00
peter klausler
fbcf2920e1 [flang] Less exhaustive REAL testing by default.
Original-commit: flang-compiler/f18@d61ac7da9b
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:01 -07:00
peter klausler
2391eb8de9 [flang] COMPLEX
Original-commit: flang-compiler/f18@452d602fbb
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:00 -07:00
peter klausler
ed71134af7 [flang] LOGICAL
Original-commit: flang-compiler/f18@6ec49f6edc
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:59 -07:00
peter klausler
564292ccf7 [flang] Revamp type.h, add LOGICAL
Original-commit: flang-compiler/f18@f7d77887a2
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:58 -07:00
peter klausler
9e35c7e731 [flang] All operations now work and match x86, all modes and flags.
Original-commit: flang-compiler/f18@c69eef6524
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:57 -07:00
peter klausler
52ef92b513 [flang] More real work. All ops, rounding modes, and flags good except for division.
Original-commit: flang-compiler/f18@ea697295db
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:55 -07:00
peter klausler
fab448de59 [flang] Check flag bits.
Original-commit: flang-compiler/f18@b63e39aae7
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:54 -07:00
peter klausler
9ea409dd29 [flang] Multiplication, more tests.
Original-commit: flang-compiler/f18@e7ef16d216
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:53 -07:00