Commit graph

1150 commits

Author SHA1 Message Date
Tim Keith
9c35cb8948 [flang] Handle TypeStar and ClassStar in GetSymbolType()
Add DeclTypeSpec::AsDerived() to get the DerivedTypeSpec from a
DeclTypeSpec when it has one.

Original-commit: flang-compiler/f18@3bd921d8f3
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
2018-12-17 17:22:42 -08:00
Tim Keith
8a1fbef21b [flang] Treat CHARACTER like other intrinsic types with default kind
Character decl-type-specs with no kind specified had no kind written to
the .mod file. That was different from the other intrinsic types which
always have an explicit type. This change make character like the other
intrinsic types.

Original-commit: flang-compiler/f18@5b4f047a13
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 15:46:30 -08:00
Tim Keith
20e2003009 [flang] Simplify creation of Expr values from ints.
Original-commit: flang-compiler/f18@56f007493b
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 15:19:11 -08:00
Tim Keith
b8b53ba2f4 [flang] Refactoring: improve some names
IntrinsicTypeSpec was used for all intrinsics except for character.
Change it to be a common base class for NumericTypeSpec,
LogicalTypeSpec, and CharacterTypeSpec.

Change DeclTypeSpec to categorize the intrinsics as Numeric, Logical,
and Character. Add some utility methods: AsIntrinsic() and IsNumeric().

In scope.h, give the functions that create DeclTypeSpecs better names.

In semantics.h, replace MakeIntrinsicTypeSpec() with MakeNumericType()
and MakeLogicalType() as it does not apply to character types.

Original-commit: flang-compiler/f18@8ad92d069c
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 12:41:43 -08:00
Tim Keith
de78ae3f09 [flang] Add support for character type specs
Recognize the various ways of specifying character lengths.

Define CharacterTypeSpec with length and kind and store them in the
current scope, as is done with DerivedTypeSpec (which can also have
length parameters).

Note: IntrinsicTypeSpec is no longer used for characters, so it
should have a different name. Similarly, in DeclTypeSpec::Category,
Intrinsic does not include Character.

Original-commit: flang-compiler/f18@5f84785193
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-14 14:04:15 -08:00
Tim Keith
396b3fde60 [flang] Rework how DeclTypeSpecs are stored
Now DeclTypeSpecs are stored in the scope so that they remain available
as long as the scope exists. DeclTypeSpecs for intrinsic types are
stored in the global scope; those for derived types are in the current
scope. They can contains type parameter values so they can't be reused.

Add `Semantics::MakeIntrinsicTypeSpec` to simplify creating
DeclTypeSpecs for intrinsic types.

Replace `std::optional<DeclTypeSpec>` with `DeclTypeSpec *` as they do
not need to be copied around.

Also fix a small bug with writing `class(t(...))` to the module file --
the type parameters were missing.

Original-commit: flang-compiler/f18@e4744418fc
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-14 07:17:12 -08:00
Peter Klausler
4cf72e2f25 [flang] Merge pull request flang-compiler/f18#244 from flang-compiler/pmk1
fix bug noticed by Jean

Original-commit: flang-compiler/f18@c4c54f05f3
Reviewed-on: https://github.com/flang-compiler/f18/pull/244
2018-12-17 10:21:25 -08:00
peter klausler
8b34535de7 [flang] fix bug noticed by Jean
Original-commit: flang-compiler/f18@9acbff7585
Reviewed-on: https://github.com/flang-compiler/f18/pull/244
2018-12-14 13:19:12 -08:00
Peter Klausler
2c33ef58cf [flang] Merge pull request flang-compiler/f18#245 from flang-compiler/pmk3
fix crash that Tim ran into

Original-commit: flang-compiler/f18@d7e914719e
Reviewed-on: https://github.com/flang-compiler/f18/pull/245
2018-12-14 13:18:21 -08:00
peter klausler
8b580e4591 [flang] fix crash that Tim ran into
Original-commit: flang-compiler/f18@498a8c6fb8
Reviewed-on: https://github.com/flang-compiler/f18/pull/245
2018-12-14 11:23:14 -08:00
Peter Klausler
e4e584d651 [flang] Merge pull request flang-compiler/f18#246 from flang-compiler/pmk4
add Unwrap

Original-commit: flang-compiler/f18@7516db2447
Reviewed-on: https://github.com/flang-compiler/f18/pull/246
2018-12-14 13:17:16 -08:00
peter klausler
cc2d419fb1 [flang] add Unwrap
Original-commit: flang-compiler/f18@3003363a2d
Reviewed-on: https://github.com/flang-compiler/f18/pull/246
2018-12-14 11:33:32 -08:00
Peter Klausler
5f2d123780 [flang] Merge pull request flang-compiler/f18#243 from flang-compiler/pmk3
Strengthen FORALL scoping check

Original-commit: flang-compiler/f18@0eac648123
Reviewed-on: https://github.com/flang-compiler/f18/pull/243
2018-12-11 14:48:25 -08:00
peter klausler
c6396e0af9 [flang] improve test
Original-commit: flang-compiler/f18@cfcf9dae4d
Reviewed-on: https://github.com/flang-compiler/f18/pull/243
2018-12-11 14:40:01 -08:00
peter klausler
4a80b14eff [flang] revert obsolete tweak
Original-commit: flang-compiler/f18@9b679e34dc
Reviewed-on: https://github.com/flang-compiler/f18/pull/243
Tree-same-pre-rewrite: false
2018-12-11 14:38:10 -08:00
peter klausler
da070db6bb [flang] Strengthen FORALL scoping check
Original-commit: flang-compiler/f18@e57eb41314
Reviewed-on: https://github.com/flang-compiler/f18/pull/243
Tree-same-pre-rewrite: false
2018-12-11 14:38:10 -08:00
Peter Klausler
e704820f41 [flang] Merge pull request flang-compiler/f18#241 from flang-compiler/pmk1
More precise locations for construct name errors; some refactoring

Original-commit: flang-compiler/f18@e41c76cf76
Reviewed-on: https://github.com/flang-compiler/f18/pull/241
2018-12-11 14:26:50 -08:00
peter klausler
ce7f9653c2 [flang] reflect review comment
Original-commit: flang-compiler/f18@6f26bfb905
Reviewed-on: https://github.com/flang-compiler/f18/pull/241
2018-12-10 10:12:11 -08:00
peter klausler
2ab000d218 [flang] delete unused private member to silence clang warning
Original-commit: flang-compiler/f18@d3c5caab34
Reviewed-on: https://github.com/flang-compiler/f18/pull/241
Tree-same-pre-rewrite: false
2018-12-07 17:03:55 -08:00
peter klausler
47d1d07b44 [flang] More precise locations for construct name errors; some refactoring
Original-commit: flang-compiler/f18@2f35605d20
Reviewed-on: https://github.com/flang-compiler/f18/pull/241
Tree-same-pre-rewrite: false
2018-12-07 16:39:22 -08:00
Tim Keith
4602c0ca37 [flang] Merge pull request flang-compiler/f18#239 from flang-compiler/tsk1
Preserve order of type parameters

Original-commit: flang-compiler/f18@83fa2376fd
Reviewed-on: https://github.com/flang-compiler/f18/pull/239
2018-12-07 11:58:12 -08:00
Tim Keith
ee908da853 [flang] Preserve order of type parameters
Type parameters were sorted by the order of the type-param-def-stmts.
But we need to preserve the order of the type-param-name-list.
The is the order of positional parameters in a derived-type-spec.

So add `paramNames` to `DerivedTypeDetails` to preserve the original
order. Using this allows us to write module files with both the
type-param-name-list and type-param-def-stmts in the original order.

Also fix a bug where a duplicate type-param-def caused a spurious
extra error. If `MakeTypeSymbol()` reports an error we should not
call `SetType()` because it will just report another error.

Original-commit: flang-compiler/f18@3ca55b6333
Reviewed-on: https://github.com/flang-compiler/f18/pull/239
2018-12-06 17:52:43 -08:00
Tim Keith
89efce51d5 [flang] Merge pull request flang-compiler/f18#240 from flang-compiler/tsk10
Fix bug converting actual argument to Fortran

Original-commit: flang-compiler/f18@b529f20ca3
Reviewed-on: https://github.com/flang-compiler/f18/pull/240
2018-12-07 10:09:51 -08:00
Tim Keith
a3b09ef72a [flang] Fix bug converting actual argument to Fortran
This fixes a problem with converting the ubound call in the example
below back to Fortran (in this case, for writing to the .mod file).
One of the ActualArguments encountered in ProcedureRef::AsFortran is
a `std::nullopt`, so we need to handle that case.

```
module m
  real :: x(10)
  real :: y(ubound(x, dim=1))
end module
```

Original-commit: flang-compiler/f18@c5ace6b824
Reviewed-on: https://github.com/flang-compiler/f18/pull/240
2018-12-07 07:41:49 -08:00
Tim Keith
738c47bf9b [flang] Merge pull request flang-compiler/f18#238 from flang-compiler/tsk11
Rework expression evaluation in symbol table

Original-commit: flang-compiler/f18@0e91bd3472
Reviewed-on: https://github.com/flang-compiler/f18/pull/238
2018-12-06 14:37:32 -08:00
Tim Keith
8ae55f79bc [flang] Rework when symbol table expressions are evaluated
It's not good enough to evaluate expressions in the symbol table after
name resolution has completed. This is because we need the values of
constant expressions for types, for example, we need to evaluate `k` in
`integer(k) :: x` to know the type of `x`.

So, eliminate `LazyExpr` and call `EvaluateExpr()` on expressions that
we need in the symbol table. The latter evaluates and folds an
expression in the current context. This is now possible because symbols
are added to `parser::Name` as soon as possible rather than in a pass
after name resolution. Along with `LazyExpr` we can eliminate the whole
`ResolveSymbolExprs` pass that used to resolve them.

In resolve-names.cc, many `Pre` functions are changed to `Post` so that
names are resolved before doing the associated processing. For example,
with intrinsic type specs, names in the kind expression must be resolved
before attempting to evaluate that expression.

In `GetSymbolType()` in type.cc, handle both `ObjectEntityDetails` and
`EntityDetails` by using `Symbol::GetType()`.

Add explicit declarations in label01.F90 because we can't handle
implicitly typed array bounds yet.

Original-commit: flang-compiler/f18@d67716640b
Reviewed-on: https://github.com/flang-compiler/f18/pull/238
2018-12-06 07:16:52 -08:00
Tim Keith
d6b37b1967 [flang] Fix error is Negation on integer
The minus sign was missing.

Original-commit: flang-compiler/f18@5fa0a97de5
Reviewed-on: https://github.com/flang-compiler/f18/pull/238
Tree-same-pre-rewrite: false
2018-12-06 07:16:52 -08:00
Tim Keith
1c856ac972 [flang] Add common base class for context, Walk(), and Say()
We need access to the SemanticsContext and Walk() function everywhere,
so move them to a BaseVisitor, a base class at the root of the class
hierarchy.

Also move MessageHandler to be a data member of BaseVisitor and forward
Say calls to it.

Original-commit: flang-compiler/f18@eb9adc342a
Reviewed-on: https://github.com/flang-compiler/f18/pull/238
Tree-same-pre-rewrite: false
2018-12-06 07:16:52 -08:00
Tim Keith
d7ba02ab8c [flang] Change when symbol is set in parser::Name
Rework how `parser::Name` is resolved to contain a `Symbol`. so that
constants in types can be evaluated. For example:
```
  integer, parameter :: k = 8
  integer(k) :: i
```
The old approach of collecting the symbols at the end of name resolution
and filling in the `parser::Name` does not work because the type of `i`
needs to be set in the symbol table.

The symbol field in `parser::Name` is now mutable so that we can set it
during name resolution. `RewriteParseTree` no longer needs to do that
(it still warns about unresolved ones), so it does not need to collect
symbols and fill them in. Consequently, we can eliminate "occurrences"
from symbols -- we just need the name where each is first defined.

This requires a lot of refactoring in `resolve-names.cc` to pass around
`parser::Name` rather than `SourceName` so that we can resolve the
name to a symbol.

Fix some bugs where we stored `SourceName *` instead of `SourceName`
in the symbol table. The pointers were into the parse tree, so they
were only valid as long as the parse tree was around. The symbol
table needs to remain valid longer than that, so the names need to
be copied. `parser::Name` is not used in the symbol table.

Eliminate `GenericSpec`. Currently all we need to do is to resolve
the kinds of GenericSpec that contain names.

Add `ScopeName` kind of `MiscDetails` for when we need a symbol in
the scope to match the name of the scope. For example, `module m`
cannot contain a declaration of a new `m`. Subprograms need real
details because they can be called recursively.

Fix output of partially resolved modules where we know it is a submodule
but have not yet resolved the ancestor.

Original-commit: flang-compiler/f18@5c1a4b99d2
Reviewed-on: https://github.com/flang-compiler/f18/pull/238
Tree-same-pre-rewrite: false
2018-12-06 07:16:52 -08:00
Peter Klausler
018d850af9 [flang] Merge pull request flang-compiler/f18#237 from flang-compiler/pmk1
Use `std::optional<>::value()` where appropriate in place of `operator*`.

Original-commit: flang-compiler/f18@611ee9be5d
Reviewed-on: https://github.com/flang-compiler/f18/pull/237
2018-12-05 13:36:03 -08:00
peter klausler
d5bb7c5888 [flang] one more file
Original-commit: flang-compiler/f18@9d3f502e80
Reviewed-on: https://github.com/flang-compiler/f18/pull/237
2018-12-05 13:06:00 -08:00
peter klausler
1b1f60ff50 [flang] Use std::optional<>::value() where appropriate.
Original-commit: flang-compiler/f18@4278b79b3d
Reviewed-on: https://github.com/flang-compiler/f18/pull/237
Tree-same-pre-rewrite: false
2018-12-05 13:03:39 -08:00
Peter Klausler
bf9d7ba483 [flang] Merge pull request flang-compiler/f18#236 from flang-compiler/pmk1
work around template specialization problem

Original-commit: flang-compiler/f18@d122b4e618
Reviewed-on: https://github.com/flang-compiler/f18/pull/236
2018-12-04 16:39:33 -08:00
peter klausler
d8f4072aba [flang] work around template specialization problem
Original-commit: flang-compiler/f18@1d67d72bea
Reviewed-on: https://github.com/flang-compiler/f18/pull/236
2018-12-04 15:52:50 -08:00
Peter Klausler
840acd5314 [flang] Merge pull request flang-compiler/f18#235 from flang-compiler/pmk1
last minute changes for recent PR that were not pushed, sorry

Original-commit: flang-compiler/f18@f9ee3753ea
Reviewed-on: https://github.com/flang-compiler/f18/pull/235
2018-12-04 10:51:41 -08:00
peter klausler
46aee9943c [flang] last minute changes for recent PR that were not pushed, sorry
Original-commit: flang-compiler/f18@9f9258e006
Reviewed-on: https://github.com/flang-compiler/f18/pull/235
2018-12-04 10:21:38 -08:00
Peter Klausler
72dc00cdbd [flang] Merge pull request flang-compiler/f18#234 from flang-compiler/pmk0
Refactoring of expr analysis API and implementation

Original-commit: flang-compiler/f18@2a1fb648d9
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
2018-12-04 10:18:10 -08:00
peter klausler
34642dab32 [flang] fixes
Original-commit: flang-compiler/f18@d312b2298a
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
2018-12-03 17:20:28 -08:00
peter klausler
972e4b59d5 [flang] address review comments
Original-commit: flang-compiler/f18@2f4b7ac97c
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
Tree-same-pre-rewrite: false
2018-12-03 16:44:25 -08:00
peter klausler
1089f0195c [flang] complete refactor of expression analysis api and impl
Original-commit: flang-compiler/f18@fc83cdeabb
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
Tree-same-pre-rewrite: false
2018-12-03 11:40:53 -08:00
peter klausler
e5df69e965 [flang] checkpoint before another refactoring
Original-commit: flang-compiler/f18@033efb95c2
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
Tree-same-pre-rewrite: false
2018-11-30 16:04:51 -08:00
peter klausler
4da74f5107 [flang] checkpoint
Original-commit: flang-compiler/f18@1c65ed9a6f
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
Tree-same-pre-rewrite: false
2018-11-30 15:23:33 -08:00
peter klausler
659c32947c [flang] checkpoint during refactor
Original-commit: flang-compiler/f18@01fe82b95b
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
Tree-same-pre-rewrite: false
2018-11-30 14:03:05 -08:00
Peter Klausler
3e5f360c9f [flang] Merge pull request flang-compiler/f18#233 from flang-compiler/pmk1
small TODO: eliminate per-specialization flag in expression type representation

Original-commit: flang-compiler/f18@03a2a10a48
Reviewed-on: https://github.com/flang-compiler/f18/pull/233
2018-11-29 13:39:51 -08:00
peter klausler
a0a60e8d6a [flang] address TODO: replace Type flag member with IsSpecificIntrinsicType<T> predicate
Original-commit: flang-compiler/f18@68b89c008f
Reviewed-on: https://github.com/flang-compiler/f18/pull/233
2018-11-29 10:25:46 -08:00
Tim Keith
ec2183cd75 [flang] Merge pull request flang-compiler/f18#230 from flang-compiler/tsk2
Add mapping of source location to Scope

Original-commit: flang-compiler/f18@bec1cfdc05
Reviewed-on: https://github.com/flang-compiler/f18/pull/230
2018-11-29 12:27:34 -08:00
Tim Keith
7704b1fcf9 [flang] Add ExtendToCover() to CharBlock and Interval
Use them in Scope::AddSourceRange().

Original-commit: flang-compiler/f18@ec2f6db46a
Reviewed-on: https://github.com/flang-compiler/f18/pull/230
2018-11-29 09:10:19 -08:00
Tim Keith
cef802b1b4 [flang] Add mapping of source location to Scope
Each Scope now tracks the source locations that it and its nested scopes
span. This is achieved by extending the source range of a scope for each
statement encountered while it is the current scope.

Semantics::FindScope maps a source location (from the cooked character
stream) to the narrowest scope that contains it.

Original-commit: flang-compiler/f18@7b4d2bb113
Reviewed-on: https://github.com/flang-compiler/f18/pull/230
Tree-same-pre-rewrite: false
2018-11-28 15:55:55 -08:00
Tim Keith
a640a8f0dd [flang] Merge pull request flang-compiler/f18#232 from flang-compiler/tsk9
Change formatting of common::visitors{}

Original-commit: flang-compiler/f18@a442658ec5
Reviewed-on: https://github.com/flang-compiler/f18/pull/232
2018-11-29 12:26:57 -08:00
Tim Keith
daa0b054ba [flang] Change formatting of common::visitors{}
Including a comma after the last lambda in a `common::visitors{}` list
causes clang-format to do a better job of formatting them.

Add that recommendation to C++style.md, insert the missing commas,
and reformat the changed files.

Original-commit: flang-compiler/f18@a2486ca3b6
Reviewed-on: https://github.com/flang-compiler/f18/pull/232
2018-11-29 09:27:34 -08:00