Commit graph

374 commits

Author SHA1 Message Date
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
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
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
peter klausler
ae98068360 [flang] Refactor rounding code.
Original-commit: flang-compiler/f18@8ef2418791
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:53 -07:00
peter klausler
efa5de0080 [flang] Get real add/subtract working and tested.
Original-commit: flang-compiler/f18@c1b4389638
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:52 -07:00
peter klausler
518b2094b2 [flang] start negative number tests
Original-commit: flang-compiler/f18@1b52ec8d3b
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:49 -07:00
peter klausler
99c23c1a92 [flang] Get back to passing all tests.
Original-commit: flang-compiler/f18@d08dc86ede
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:47 -07:00
peter klausler
3fb4757cc7 [flang] Use EnumSet<> for real flags
Original-commit: flang-compiler/f18@a61f193036
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:46 -07:00
peter klausler
b940e3de3f [flang] some real debugging
Original-commit: flang-compiler/f18@9653814ed3
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:45 -07:00
peter klausler
eb9ad7ef07 [flang] begin testing reals
Original-commit: flang-compiler/f18@9d261b594b
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:44 -07:00
peter klausler
321056b53c [flang] Convert REAL code to use IEEE encodings.
Original-commit: flang-compiler/f18@b36e50f465
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:43 -07:00
peter klausler
e850b8d90b [flang] real work
Original-commit: flang-compiler/f18@030347a906
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:42 -07:00
peter klausler
59f16575ee [flang] More work on reals.
Original-commit: flang-compiler/f18@3ba634a214
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:40 -07:00
peter klausler
96d560b84b [flang] more work on reals
Original-commit: flang-compiler/f18@3afe85bf15
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:39 -07:00
peter klausler
0fb4b25ac8 [flang] begin real.h
Original-commit: flang-compiler/f18@b0f0cd8961
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:37 -07:00
peter klausler
5ee73b23c1 [flang] bugfixing from clang build
Original-commit: flang-compiler/f18@a05e108288
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:36 -07:00
peter klausler
0bdde28cd7 [flang] Reading numbers from strings.
Original-commit: flang-compiler/f18@8cbadfe777
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:52:35 -07:00