Commit graph

185 commits

Author SHA1 Message Date
Jean Perier
4a4ca14cb2 [flang] Comment typos correction
Original-commit: flang-compiler/f18@107c105636
Reviewed-on: https://github.com/flang-compiler/f18/pull/227
Tree-same-pre-rewrite: false
2018-11-19 08:59:07 -08:00
Jean Perier
0562341063 [flang] CFI_allocate: fixed CFI_type_char/cptr
Original-commit: flang-compiler/f18@ba9274d3ee
Reviewed-on: https://github.com/flang-compiler/f18/pull/227
Tree-same-pre-rewrite: false
2018-11-16 08:00:41 -08:00
Jean Perier
cc436e74df [flang] CFI_set_pointer, CFI_section, CFI_select_part and tests
Original-commit: flang-compiler/f18@e3830c5878
Reviewed-on: https://github.com/flang-compiler/f18/pull/227
Tree-same-pre-rewrite: false
2018-11-16 07:10:04 -08:00
peter klausler
e7b93436c3 [flang] Rearrange code to eliminate dependence cycles between f18 library binaries
Original-commit: flang-compiler/f18@88651eecae
Reviewed-on: https://github.com/flang-compiler/f18/pull/265
Tree-same-pre-rewrite: false
2019-01-22 16:31:19 -08:00
peter klausler
f9d6c0a338 [flang] Move default intrinsic type kinds from lib/semantics to lib/common
Original-commit: flang-compiler/f18@887e72dd61
Reviewed-on: https://github.com/flang-compiler/f18/pull/265
Tree-same-pre-rewrite: false
2019-01-22 16:31:18 -08:00
peter klausler
cfe14d0f0b [flang] Make x86 fp behavior emulation conditional.
Original-commit: flang-compiler/f18@0c77a634b3
Reviewed-on: https://github.com/flang-compiler/f18/pull/266
2019-01-22 11:13:44 -08:00
peter klausler
5ceaa14dd9 [flang] done with merge
Original-commit: flang-compiler/f18@9c63eb7a1a
Reviewed-on: https://github.com/flang-compiler/f18/pull/260
Tree-same-pre-rewrite: false
2019-01-17 16:14:36 -08:00
peter klausler
7f3590771e [flang] merge with master, implement a TODO with LEN on ASSOCIATE
Original-commit: flang-compiler/f18@e4501c6fa4
Reviewed-on: https://github.com/flang-compiler/f18/pull/260
Tree-same-pre-rewrite: false
2019-01-17 13:52:10 -08:00
peter klausler
be3b765e2a [flang] basic skeleton of assignment analyzer
remove needless template<> on some function overloads

dodge bogus compiler warning from gcc 8.1.0 only

stricter typing of expressions in symbols

adjust modfile12.f90 expected test results

add Unwrap, massage folding a bit

Use Unwrap to simplify folding

Move KindSelector analysis into expression semantics

fix crash

checkpoint

updates to TypeParamInquiry

support of %KIND type parameter inquiry

equality testing for expressions

checkpoint during PDT implementation

reformat

checkpoint derived type instantiation

checkpoint

resolve merge

debugging failed tests

fix failing resolve37.f90 test

all existing tests pass

clean up all build warnings

fix bug

update copyright dates

fix copyright dates

address review comments

review comment

merge with master after peeling off changes

bugfixing new feature

fix warning from old g++s

tweaks after merging with latest head

more bugfixing

making modfile17.f90 test work

Make kinds into expressions in symbol table types

big refactor for deferring kinds in intrinsic types

modfile17.f90 test passes

clean up TODOs

Simplify types as stored in scopes

Test KIND parameter default init expressions, debug them

Update copyright dates

address comments

remove dead line

address comments

Original-commit: flang-compiler/f18@1f43d0a048
Reviewed-on: https://github.com/flang-compiler/f18/pull/260
Tree-same-pre-rewrite: false
2019-01-17 10:41:08 -08:00
Tim Keith
ee28b70827 [flang] Resolve names in ASSOCIATE and SELECT TYPE
Create `AssocEntityDetails` for symbols that represent entities
identified by the associate-name in ASSOCIATE and SELECT TYPE
constructs.

For ASSOCIATE, create a new scope for the associated entity.
For SELECT TYPE, create a new scope for each of type guard blocks.
Each one contains an associated entity with the appropriate type.

For SELECT TYPE, also create a place-holder symbol for the
associate-name in the SELECT TYPE statement. The real symbols
are in the new scopes and none of them is uniquely identified
with the associate-name.

Handling of `Selector` is common between these, with
`associate-name => expr | variable` recorded in
`ConstructVisitor::association_`.

When the selector is an expression, derive the type of the associated
entity from the type of the expression. This required some refactoring
of how `DeclTypeSpec`s are created. The `DerivedTypeSpec` that comes
from and expression is const so we can only create const `DeclTypeSpec`s
from it. But there were times during name resolution when we needed to
set type parameters in the current `DeclTypeSpec`. Now the non-const
`DerivedTypeSpec` is saved separately from the const `DeclTypeSpec`
while we are processing a declaration type spec. This makes it
unnecessary to save the derived type name.

Add a type alias for `common::Indirection` to reduce verbosity.

Original-commit: flang-compiler/f18@b7668cebe4
Reviewed-on: https://github.com/flang-compiler/f18/pull/261
Tree-same-pre-rewrite: false
2019-01-15 16:59:20 -08:00
Tim Keith
a1a55f007c [flang] Resolve name in PASS and BIND attributes
These are recognized along with other attributes and saved in
`passName_` and `bindName_`. The functions `SetPassNameOn()` and
`SetBindNameOn()` set them in a symbol if they are present.
They are also written to `.mod` files.

Add `MakePlaceholder()` to make symbols for names that otherwise
wouldn't have one. This allows us to assign a symbol to every name
and report errors for those that don't have one. Make use of this
for PASS names, which don't have explicit symbols.

Change `ObjectEntityDetails` and `ProcEntityDetails` to be sub-classes
of `EntityDetails`. They each contain a superset of the information in
`EntityDetails` so this reduces some duplication.

Original-commit: flang-compiler/f18@404c920840
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
Tree-same-pre-rewrite: false
2019-01-08 12:14:35 -08:00
peter klausler
4d115f2383 [flang] Restore readability improvement from code review comment that did not make it into a merge into master, and repair expected test results.
Original-commit: flang-compiler/f18@4f1946765e
Reviewed-on: https://github.com/flang-compiler/f18/pull/255
2019-01-08 09:56:57 -08:00
peter klausler
5cf5315343 [flang] fold analyzed bounds expressions
Original-commit: flang-compiler/f18@17810319ae
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
2019-01-07 16:31:59 -08:00
peter klausler
13ed85789d [flang] Symbol changes for PDT instantiation
Original-commit: flang-compiler/f18@0c545a026d
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
Tree-same-pre-rewrite: false
2019-01-07 15:05:53 -08:00
peter klausler
2ad9986698 [flang] Support operator== for expressions.
Original-commit: flang-compiler/f18@42013513e9
Reviewed-on: https://github.com/flang-compiler/f18/pull/251
2019-01-04 14:05:53 -08:00
peter klausler
c6df6af013 [flang] update error message texts in test
Original-commit: flang-compiler/f18@42c0d5d950
Reviewed-on: https://github.com/flang-compiler/f18/pull/250
Tree-same-pre-rewrite: false
2018-12-28 16:01:46 -08:00
Tim Keith
8d959bb943 [flang] Add support for type-bound generics
Record the bindings in a symbol with GenericBindingDetails, including
bindings inherited from extended types. Check that they have consistent
accessibility.

Original-commit: flang-compiler/f18@0f780abcea
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
2018-12-26 14:31:26 -08:00
Tim Keith
a7e91f2335 [flang] Fix bug making symbol for external procedure
When we encounter a ProcedureDesignator, if it is an external procedure
(i.e. there is no visible declaration) it must be implicitly created in
the global scope, not the current scope.

If there is already a symbol there (i.e. a module) it is an error, even
if that symbol is not visible due to an IMPORT statement.

Original-commit: flang-compiler/f18@835e234ded
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
2018-12-18 16:35:31 -08:00
Tim Keith
bc469ef570 [flang] Resolve names in ProcedureStmt and GenericStmt
We need to save the names of specific procedures that appear in a
ProcedureStmt or GenericStmt to resolve at the end of the specification
section. They may be forward references to interface bodies.

We were saving them in the GenericDetails but that was not the right
place: we need to save the parser::Name so that we can eventually
resolve it to a Symbol, but the symbol table should not contains
references to Name because they go away with the parse tree.

The fix is to save the mapping in a new multimap, specificProcs_ in
InterfaceVisitor. We can reference parser::Names there and resolve them
during ResolveSpecificsInGenerics(). We no longer need to clutter
GenericDetails with data structures for unresolved names.

Also handle the case where a specific procedure is use-associated from
another module.

Original-commit: flang-compiler/f18@c7f7b1e72d
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
2018-12-18 07:59:40 -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
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
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
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
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
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
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
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
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
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
peter klausler
8cb33d85a7 [flang] dodge gcc warning on test
Original-commit: flang-compiler/f18@10e9a82088
Reviewed-on: https://github.com/flang-compiler/f18/pull/231
2018-11-28 16:44:38 -08:00
peter klausler
2067929b5a [flang] tested
Original-commit: flang-compiler/f18@e77681a2ff
Reviewed-on: https://github.com/flang-compiler/f18/pull/231
Tree-same-pre-rewrite: false
2018-11-28 16:20:16 -08:00
peter klausler
7f603f6e15 [flang] debugged full precision FP formatting
Original-commit: flang-compiler/f18@ac9a684b91
Reviewed-on: https://github.com/flang-compiler/f18/pull/231
Tree-same-pre-rewrite: false
2018-11-28 10:33:09 -08:00
peter klausler
2fe5b128bd [flang] debugging
Original-commit: flang-compiler/f18@9f30eac130
Reviewed-on: https://github.com/flang-compiler/f18/pull/231
Tree-same-pre-rewrite: false
2018-11-28 10:33:09 -08:00
peter klausler
a10b7bc006 [flang] revamp Real::Read(), use it for mutual testing of ScaledDecimals
Original-commit: flang-compiler/f18@a2054bb9df
Reviewed-on: https://github.com/flang-compiler/f18/pull/225
Tree-same-pre-rewrite: false
2018-11-13 16:02:52 -08:00
peter klausler
bf7c03dbfb [flang] binary->decimal conversion for module files
Original-commit: flang-compiler/f18@6364799e7a
Reviewed-on: https://github.com/flang-compiler/f18/pull/225
Tree-same-pre-rewrite: false
2018-11-13 11:29:54 -08:00
peter klausler
c4601e2bc2 [flang] save work in progress
Original-commit: flang-compiler/f18@98bac3d297
Reviewed-on: https://github.com/flang-compiler/f18/pull/225
Tree-same-pre-rewrite: false
2018-11-08 09:38:04 -08:00
peter klausler
4f6275a1f7 [flang] Rename Dump() as AsFortran(), tweak output for use in .mod files
Original-commit: flang-compiler/f18@4e9dd16d6a
Reviewed-on: https://github.com/flang-compiler/f18/pull/225
Tree-same-pre-rewrite: false
2018-11-08 09:38:03 -08:00
Jean Perier
2ab0f0d86a [flang] Changed CFI_CDESC_T macro in C++. Cleaned related tests.
Original-commit: flang-compiler/f18@752f8eefa0
Reviewed-on: https://github.com/flang-compiler/f18/pull/222
Tree-same-pre-rewrite: false
2018-11-06 09:07:27 -08:00
Jean Perier
c3682c3ab7 [flang] Fixed CFI_establish. Improved and renamed related test suit
Original-commit: flang-compiler/f18@b75d858e4f
Reviewed-on: https://github.com/flang-compiler/f18/pull/222
Tree-same-pre-rewrite: false
2018-11-05 07:07:18 -08:00
Jean Perier
63c88cdbc0 [flang] Fixed CFI_DESC_T macro. Started unit test for C interop
Original-commit: flang-compiler/f18@f29b80c758
Reviewed-on: https://github.com/flang-compiler/f18/pull/222
Tree-same-pre-rewrite: false
2018-11-02 09:42:35 -07:00
Tim Keith
9095548553 [flang] Resolve expressions in symbols
Add `LazyExpr` class to represent expressions in the symbol table.
Initially they contain a pointer to an expression in the parse tree.
After name resolution is complete and symbols are filled in in the parse
tree, `LazyExpr`s are resolved to `evaluate::Expr<evaluate::SomeType>`.
This is done by `ResolveSymbolExprs()`.

Change `Bound` and `ParamValue` to save their value as a `LazyExpr`.
Change `ObjectEntityDetails` and `TypeParamDetails` to save the initial
value as a `LazyExpr`.

Eliminate `IntExpr` and `IntConst` classes, which were just place-holders.

Add `Clone()` to `ShapeSpec`, `Bound`, `LazyExpr`. Normally they should
be moved but in `ObjectEntityDetails::set_shape()` we need to make copies.

Save type parameter values in `derivedTypeSpec_`. `typeParamValue_` is
not needed.

Write out initial values, type parameter values, and bounds to .mod files.

Evaluate parameter values in expressions.

Make some errors non-fatal so that tests can continue to pass.

Original-commit: flang-compiler/f18@b90cadfc53
Reviewed-on: https://github.com/flang-compiler/f18/pull/223
Tree-same-pre-rewrite: false
2018-11-06 17:18:06 -08:00
peter klausler
0a56867df9 [flang] Back out needless macro change that led to clang-format grief
Original-commit: flang-compiler/f18@5a6e55df11
Reviewed-on: https://github.com/flang-compiler/f18/pull/219
Tree-same-pre-rewrite: false
2018-10-26 16:31:20 -07:00
peter klausler
abac228b82 [flang] Complete refactor of Fold() - checkpoint
Original-commit: flang-compiler/f18@5061171268
Reviewed-on: https://github.com/flang-compiler/f18/pull/219
Tree-same-pre-rewrite: false
2018-10-26 15:21:01 -07:00
peter klausler
84ea49d062 [flang] rearrange arguments into dummy argument order
Original-commit: flang-compiler/f18@3bab0f55de
Reviewed-on: https://github.com/flang-compiler/f18/pull/219
Tree-same-pre-rewrite: false
2018-10-26 15:16:46 -07:00
peter klausler
ef9dd9d1fe [flang] refactor a bit, and rearrange actual arguments into dummy order on intrinsic calls
Original-commit: flang-compiler/f18@1f50ace68b
Reviewed-on: https://github.com/flang-compiler/f18/pull/219
Tree-same-pre-rewrite: false
2018-10-26 15:16:41 -07:00
peter klausler
fdd3a2adca [flang] Use Attrs for intrinsic results rather than flags.
Original-commit: flang-compiler/f18@14c9199718
Reviewed-on: https://github.com/flang-compiler/f18/pull/219
Tree-same-pre-rewrite: false
2018-10-26 15:15:54 -07:00
Tim Keith
507121f63f [flang] Process SeparateModuleSubprogram during name resolution
When a SeparateModuleSubprogram is encountered, check that there is a
corresponding declaration in the current module/submodule or an ancestor.
When it's the current program unit, special handling is required to
avoid trying to declare it again.

Module subprograms with the `MODULE` prefix are handled similarly.
The `hasModulePrefix` flag is passed in to `BeginSubprogram` to
distinguish this case.

Extract common part of `Post(SubroutineStmt)` and `Post(FunctionStmt)` into
`PostSubprogramStmt`. Add code there to ensure that separate module
procedures do not have `EXTERNAL` set. This requires a fix to `ModFileWriter`
to correctly decide when a subprogram is declared in an interface block.

Extract `WalkSubprogramPart` into a separate function. It walks the
internal or module subprograms collecting their names. It is needed to
handle separate module subprograms.

Original-commit: flang-compiler/f18@339b65f251
Reviewed-on: https://github.com/flang-compiler/f18/pull/218
Tree-same-pre-rewrite: false
2018-10-26 07:34:50 -07:00
Jean Perier
f7e7cb349b [flang] Changed .clang-format so that it will not add a comment after the closing brace of each namespace. Removed all such previous comments from all .cc and .h files
Original-commit: flang-compiler/f18@aa7f55e15f
Reviewed-on: https://github.com/flang-compiler/f18/pull/217
2018-10-25 05:55:23 -07:00
Eric Schweitz
fd93b9f3ae [flang] Fix conflicts
Fix more rotten bits
Fix the tests to reflect merges

Original-commit: flang-compiler/f18@b9a1a8b809
Reviewed-on: https://github.com/flang-compiler/f18/pull/196
2018-10-24 12:22:42 -07:00