Commit graph

237 commits

Author SHA1 Message Date
Jean Perier
be8b657ae3 [flang] removed hard coded path
Original-commit: flang-compiler/f18@d2fcd31257
2019-03-21 08:49:38 -07:00
Jean Perier
4073e47343 [flang] Add test framework for folding
Original-commit: flang-compiler/f18@d6b658c318
Tree-same-pre-rewrite: false
2019-03-21 08:31:21 -07:00
Tim Keith
299628e2cb [flang] Strip whitespace from parse tree source locations
Parse tree nodes have `source` fields that map the node back to
a range in the cooked input stream. These are used for names and
to locate error messages.

This change strips spaces from the beginning and end of those
source ranges before they are saved. This fixes two problems:
1. For a statement like this: `generic :: operator(+) => ...`,
   the name of the symbol we want to create is "operator(+)" but
   the parser was including the following space in the CharBlock
   it captured.
2. Error messages referring to parts of expressions sometimes included
   extra spaces in the source locations. For example:
   ```
   t.f90:9:29: error: subscripts may be applied only to an object or component
    integer, parameter :: b = a(1) + 1
                              ^^^^^
   t.f90:4:8: error: operands to LOGICAL operation must be LOGICAL
    i = j .or. k
         ^^^^^^^
   ```

Original-commit: flang-compiler/f18@fa14297967
Reviewed-on: https://github.com/flang-compiler/f18/pull/343
Tree-same-pre-rewrite: false
2019-03-19 13:38:54 -07:00
Tim Keith
3ec5e102e2 [flang] Name resolution for defined operators
Instead of tracking just genericName_ while in a generic interface
block or generic statement, now we immediately create a symbol for it.
A parser::Name isn't good enough because a defined-operator or
defined-io-generic-spec doesn't have a name.

Change the parse tree to add a source field to GenericSpec. Use these
as names for symbols for defined-operator and defined-io-generic-spec
(e.g. "operator(+)" or "read(formatted)").

Change the source for defined-op-name to include the dots so that they
can be distinguished from normal symbols with the same name (e.g. you
can have both ".foo." and "foo"). These symbols have names in the symbol
table like ".foo.", not "operator(.foo.)", because references to them
have that form.

Add GenericKind enum to GenericDetails and GenericBindingDetails.
This allows us to know a symbol is "assignment(=)", for example,
without having to do a string comparison.

Add GenericSpecInfo to handle analyzing the various kinds of
generic-spec and generating symbol names and GenericKind for them.

Add reference to LanguageFeatureControl to SemanticsContext so that
they can be checked during semantics. For this change, if
LogicalAbbreviations is enabled, report an error if the user tries
to define an operator named ".T." or ".F.".

Add resolve-name-utils.cc to hold utility functions and classes that
don't have to be in the ResolveNamesVisitor class hierarchy. The goal
is to reduce the size of resolve-names.cc where possible.

Original-commit: flang-compiler/f18@3081f694e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/338
2019-03-18 11:48:02 -07:00
peter klausler
e3b632337d [flang] add structconst04.f90 test and fixes to pass it
Original-commit: flang-compiler/f18@d857c843f5
Reviewed-on: https://github.com/flang-compiler/f18/pull/322
Tree-same-pre-rewrite: false
2019-03-09 10:25:07 -08:00
Tim Keith
d19308787c [flang] Add test for AssignmentChecker
Add a test to verify that AssignmentChecker is actually running.

Original-commit: flang-compiler/f18@2c91604e9b
Reviewed-on: https://github.com/flang-compiler/f18/pull/315
Tree-same-pre-rewrite: false
2019-03-06 14:12:20 -08:00
peter klausler
da2ebb6063 [flang] Improve error messages
Original-commit: flang-compiler/f18@4046134512
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:25 -08:00
peter klausler
8a57433273 [flang] C1594 constraint checking on pointer components in struct constructors
Original-commit: flang-compiler/f18@386cd8a9b4
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:24 -08:00
peter klausler
ec8e8b8277 [flang] Length conversions in array constructors, and fix their formatting
Original-commit: flang-compiler/f18@88cdb49f48
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:24 -08:00
peter klausler
69352908e0 [flang] Character length conversion on structure constructor component assignments
Original-commit: flang-compiler/f18@051c1dd923
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:24 -08:00
peter klausler
3edc423bf8 [flang] Add SetLength operator to make character length changes explicit
Original-commit: flang-compiler/f18@f2d751d8a6
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:23 -08:00
peter klausler
431b84880a [flang] snapshot of work in progress
Original-commit: flang-compiler/f18@56e83d4dd6
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:23 -08:00
Tim Keith
ef5499fd74 [flang] Fix bug in test_modfile.sh
The expected mod files specified in the test do not necessarily
appear in sorted order, and the desired order depends on what the
`comm` command expects. So sort them to be sure it is right.

Original-commit: flang-compiler/f18@730d0d0562
Reviewed-on: https://github.com/flang-compiler/f18/pull/309
2019-02-28 11:05:49 -08:00
Tim Keith
ebcfd01ae3 [flang] Fix bug with host-association in module procedure interface body
A module procedure interface body can access entities in its host
without an IMPORT statement. So the `ImportKind` of the scope created
for such an interface body should be `Default`, not `None` as it is
for other interface bodies.

Original-commit: flang-compiler/f18@24bb2668fd
Reviewed-on: https://github.com/flang-compiler/f18/pull/305
Tree-same-pre-rewrite: false
2019-02-28 10:38:17 -08:00
Tim Keith
0b9621b635 [flang] Allow module procedure and generic with same name
The `GenericDetails::CheckSpecific()` check was happening too early.
We have to wait until all procedures of the generic have been seen.
The generic can have the same name as a module procedure only if that
module procedure is a specific procedure of the generic.

Improve the `SayAlreadyDeclared` error message when the previous
declaration is a use-association

Original-commit: flang-compiler/f18@269e3db602
Reviewed-on: https://github.com/flang-compiler/f18/pull/305
Tree-same-pre-rewrite: false
2019-02-28 10:38:17 -08:00
Tim Keith
563e65ded1 [flang] Fix .mod file for symbols with same name as generic
When a generic has the same name as a module procedure or derived type,
the latter weren't being written to the `.mod` file. Fix that by calling
`PutSymbol()` on those symbols from the generic. Change `PutSymbol()` to
accept `Symbol *` to make that more convenient.

Original-commit: flang-compiler/f18@1778efe981
Reviewed-on: https://github.com/flang-compiler/f18/pull/305
Tree-same-pre-rewrite: false
2019-02-28 10:38:17 -08:00
Tim Keith
9a497ddbad [flang] Fix resolution of function prefix type
When a function-stmt has a type in the prefix (`type(t) function f()`),
the type cannot be resolve until after processing the USE and IMPLICIT
statements. So save the parse-tree of the type and process it at the
end of the specification section.

Add `ProcessTypeSpec()` to handle the process of setting up to walk
a type spec, walking it, restoring the state, and returning the type
spec. We do this several other places too.

Original-commit: flang-compiler/f18@bcde294d0e
Reviewed-on: https://github.com/flang-compiler/f18/pull/305
Tree-same-pre-rewrite: false
2019-02-28 10:38:17 -08:00
Tim Keith
1ec4ec88bf [flang] Fix bug determining type of statement entity
A statement entity (`data-i-do-variable` or `ac-do-variable`) that
doesn't have a type specified gets the type it would have in the
enclosing scope. That means if there is a visible variable with the
same name, the statement entity gets its type. We were failing to
do that and just applying the implicit rules.

Original-commit: flang-compiler/f18@72bc7c29ba
Reviewed-on: https://github.com/flang-compiler/f18/pull/305
Tree-same-pre-rewrite: false
2019-02-28 10:38:17 -08:00
Tim Keith
f1bcb92180 [flang] Handle subprogram declaration after call
If an external subprogram is called and then declared, we have to
replace the `ProcEntityDetails` with `SubprogramDetails` in the symbol.
While doing so we can also check that the call was consistent with the
declaration for function vs. subprogram.

Original-commit: flang-compiler/f18@e43a2dae79
Reviewed-on: https://github.com/flang-compiler/f18/pull/305
Tree-same-pre-rewrite: false
2019-02-28 10:38:17 -08:00
peter klausler
204a50d283 [flang] unparse interfaces as PROCEDURE(TYPE(REAL)) to avoid ambiguity
Original-commit: flang-compiler/f18@efef1f1ad1
Reviewed-on: https://github.com/flang-compiler/f18/pull/304
2019-02-27 12:30:57 -08:00
peter klausler
94baaab8a8 [flang] address review comments
Original-commit: flang-compiler/f18@6f4af0fc1b
Reviewed-on: https://github.com/flang-compiler/f18/pull/304
Tree-same-pre-rewrite: false
2019-02-27 11:12:16 -08:00
peter klausler
92b0c8412c [flang] prep for review
Original-commit: flang-compiler/f18@794e6a42ec
Reviewed-on: https://github.com/flang-compiler/f18/pull/304
Tree-same-pre-rewrite: false
2019-02-26 16:22:43 -08:00
peter klausler
e6067aea50 [flang] rebasing
Original-commit: flang-compiler/f18@ff6c0be908
Reviewed-on: https://github.com/flang-compiler/f18/pull/304
Tree-same-pre-rewrite: false
2019-02-26 16:21:29 -08:00
peter klausler
f953583dea [flang] checkpoint
Original-commit: flang-compiler/f18@4d907e3184
Reviewed-on: https://github.com/flang-compiler/f18/pull/304
Tree-same-pre-rewrite: false
2019-02-26 16:21:26 -08:00
peter klausler
2d76abcd07 [flang] checkpoint
Original-commit: flang-compiler/f18@a2b1c94ddb
Reviewed-on: https://github.com/flang-compiler/f18/pull/304
Tree-same-pre-rewrite: false
2019-02-26 16:18:56 -08:00
Tim Keith
b6eb981caa [flang] Handle SAVE attribute and statement
As with COMMON blocks, we can't completely check SAVE statements and
attributes until the end of the specification part when we have seen
full declarations of entities. So when SAVE is specified, add it to one
of the two sets in `saveInfo_`. At the end of the specification part,
check that those entities can have SAVE applied and set it if it is
not already implicitly set (e.g. due to being in a module). Also apply
the "global" SAVE if present (i.e. setting it on every applicable
entity).

Add `IsDummy()` and `IsFuncResult()` to `Symbol` to simplify some of
the checks. Also detect attempts to put a function result in a common
block.

Original-commit: flang-compiler/f18@af19c02bac
Reviewed-on: https://github.com/flang-compiler/f18/pull/298
2019-02-21 08:59:38 -08:00
Tim Keith
a6874f8ee8 [flang] More work on COMMON blocks
Common block names can't clash with other names, so add `commonBlocks_`
to `Scope` to record the common blocks of a scoping unit. This requires
changes to how scopes are dumped and written to `.mod` files.

Support common blocks in BIND statements. Add optional bind-name to
`CommonBlockDetails`.

Add `CheckNotInBlock()` for checking statements that are not allowed in
block constructs.

In `rewrite-parse-tree.cc`, no longer skip check for resolved names in
common statements. But do skip the checks in compiler directives.

Original-commit: flang-compiler/f18@805a1ffd9b
Reviewed-on: https://github.com/flang-compiler/f18/pull/298
Tree-same-pre-rewrite: false
2019-02-21 08:48:20 -08:00
Tim Keith
8a03a67cb0 [flang] Change handling of BIND attributes
Previously `BIND(C, NAME="...")` caused `bindName` to be set but not
the `BIND` attribute. This made writing the `.mod` file easier, but it
makes it hard to ask: does this symbol have a C binding.

This change causes the `BIND` attribute to be set whenever there is
`BIND(C)` in the source, regardless of whether there is a name or not.
`bindName` is only set when the `BIND` attribute is also set.

Original-commit: flang-compiler/f18@5a6706ffcb
Reviewed-on: https://github.com/flang-compiler/f18/pull/298
Tree-same-pre-rewrite: false
2019-02-21 08:47:12 -08:00
peter klausler
6ed79af787 [flang] address review comments
Original-commit: flang-compiler/f18@a27f240bd4
Reviewed-on: https://github.com/flang-compiler/f18/pull/291
2019-02-19 10:08:10 -08:00
peter klausler
2793b663d6 [flang] Check for recursive EXTENDS()
Original-commit: flang-compiler/f18@8d0a9bb360
Reviewed-on: https://github.com/flang-compiler/f18/pull/291
Tree-same-pre-rewrite: false
2019-02-18 14:15:33 -08:00
peter klausler
88631be8b4 [flang] fix flang-compiler/f18#283 - recursive use of derived types
Original-commit: flang-compiler/f18@f8889b83fc
Reviewed-on: https://github.com/flang-compiler/f18/pull/291
Tree-same-pre-rewrite: false
2019-02-18 14:15:32 -08:00
peter klausler
475d72f8e6 [flang] push for review
Original-commit: flang-compiler/f18@17dc735911
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 14:26:23 -08:00
peter klausler
2f12ee4f52 [flang] complete transfer of struct constructor code to expression.cc
Original-commit: flang-compiler/f18@e6178b2fc7
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:29:07 -08:00
peter klausler
f5bc9fd1d1 [flang] checkpoint, much code moved out of name resolution
Original-commit: flang-compiler/f18@8a081e82fa
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:28:09 -08:00
peter klausler
4d1a8a3ac8 [flang] checkpoint, tests pass
Original-commit: flang-compiler/f18@d90d5d9244
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:24:13 -08:00
peter klausler
4313f4c762 [flang] checkpoint array/struct constructor work
Original-commit: flang-compiler/f18@b0a574fa35
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:22:09 -08:00
Tim Keith
543b15bca4 [flang] Add support for common blocks
A symbol for a common block has `CommonBlockDetails` which contains
a list of the symbols that are in the common block.

The name of the symbol for the blank common block is the empty string.
That preserves the property that every symbol name is a substring of
the cooked source. We use the 0-length substring starting at the COMMON
statement so that when symbols are sorted by the location of the start
of the name it ends up in the right place.

Some of the checks on members of common blocks don't happen until the
end of the scope. They can't happen earlier because we don't necessarily
know the type and attributes.

Enhance `test_errors.sh` so that multiple errors can be expected for
a single line.

Original-commit: flang-compiler/f18@2c4ca6b5d3
Reviewed-on: https://github.com/flang-compiler/f18/pull/286
2019-02-14 07:59:20 -08:00
Tim Keith
e5965b4752 [flang] Fix bug setting type from association expression
When an association selector is an expression, we get the type of the
associate-name from the type of the expression. If that is a derived
type, we were failing to get the derived type scope in copy of the
type that was made. That meant the component names were not resolved.

The fix is to copy the scope in the copy and move constructors of
`DerivedTypeSpec`. As a result, `DerivedTypeSpec::Instantiate` cannot
assume that the `scope_` is not set.

Original-commit: flang-compiler/f18@79eaa8c47f
Reviewed-on: https://github.com/flang-compiler/f18/pull/281
Tree-same-pre-rewrite: false
2019-02-11 10:49:48 -08:00
Tim Keith
d396a8845b [flang] Resolve kind parameters on literal constants
When the kind parameter is a constant name, that name must be resolved.

Add `CheckIntrinsicKind` and `CheckIntrinsicSize` for common checking of
valid intrinsic kinds. Previous we had different forms of the error
message depending on the context ( "unsupported INTEGER(KIND=47)" and
"INTEGER(KIND=47) is not a supported type").

Report error for parameters without initialization where are they
declared (in `Post(EntityDecl)`) rather than where they are referenced
(in `AnalyzeExpr`).

Remove error message from `AnalyzeKindParam`: `AnalyzeExpr` will report
the error (e.g. not integer, not constant, etc.).

Remove "name was not resolved" error from `AnalyzeExpr`: it should be
reported by name resolution.

Original-commit: flang-compiler/f18@9b0a99ce66
Reviewed-on: https://github.com/flang-compiler/f18/pull/281
Tree-same-pre-rewrite: false
2019-02-08 16:03:23 -08:00
Tim Keith
2a43e78c17 [flang] Improvements to name resolution in data statements
Handle variables in data statements differently from implied dos:
If a variable is first mentioned in a data statement, it is implicitly
declared in the current scope (and subsequent type declarations only
confirm the type).
In the implied do case, the only variables that can be implicitly
declared are the iteration variables. They must be created in the new
ImpliedDos scope. There must be one such scope for each data-stmt-object
because the variable name can be reused.

Resolve references to named constants, e.g. in complex-literal-constant
and data-stmt-value. This requires changing the handling of
named-constant-def as that is a definition, not a reference.

Original-commit: flang-compiler/f18@9952b56af0
Reviewed-on: https://github.com/flang-compiler/f18/pull/277
Tree-same-pre-rewrite: false
2019-02-06 17:18:02 -08:00
Tim Keith
da46e49a01 [flang] Resolve namelist group and object names
Namelist groups are represents by symbols with `NamelistDetails`.
Those contain a list of symbols representing the objects in the group.
References to namelist groups in io-control-spec are resolved.

In `.mod` files, namelist groups are written out at the end of the
module specification section. This is so that the declarations of the
objects in the namelist group appear before they are referenced.

Original-commit: flang-compiler/f18@8b70dbcac7
Reviewed-on: https://github.com/flang-compiler/f18/pull/277
Tree-same-pre-rewrite: false
2019-02-05 14:43:00 -08:00
peter klausler
7f7c44f425 [flang] address comments
Original-commit: flang-compiler/f18@ccbb1a2036
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-02-04 10:39:41 -08:00
peter klausler
fef7fcd45f [flang] More value semantics in Constant<> and GetScalarConstantValue
Original-commit: flang-compiler/f18@c7acce4685
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-02-01 13:37:49 -08:00
peter klausler
ef77d38c21 [flang] add conversions to array constructor test
Original-commit: flang-compiler/f18@881c195a26
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-01-31 10:16:26 -08:00
peter klausler
140b4adcfe [flang] Address review comments, fix some f90_correct failures
Original-commit: flang-compiler/f18@e468f8cd54
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-01-31 09:59:37 -08:00
peter klausler
1c95fef459 [flang] pass tests
Original-commit: flang-compiler/f18@db22dc2294
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-01-31 09:59:35 -08:00
peter klausler
2a88fef290 [flang] array constructor folding with test
Original-commit: flang-compiler/f18@37e7a8e666
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-01-31 09:59:34 -08:00
peter klausler
0ae3d43d76 [flang] Run expression semantic analysis with rest of semantics.
checkpoint array constructor semantics work

checkpoint

array constructors of lengthless intrinsic types

checkpoint

Correct ambiguous substring refs misparsed as array elements

Original-commit: flang-compiler/f18@2232549efe
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-01-31 09:59:28 -08:00
peter klausler
74a77dd2ed [flang] Use IEEE-754 terminology better: subnormal, not denormal(ized)
Original-commit: flang-compiler/f18@57b0ebb558
Reviewed-on: https://github.com/flang-compiler/f18/pull/273
2019-01-29 16:47:41 -08:00
Jean Perier
8453e1bc13 [flang] Cleaned folding test helper template
Original-commit: flang-compiler/f18@b402c0a09c
2019-01-25 03:24:31 -08:00