Commit graph

104 commits

Author SHA1 Message Date
Jinxin Yang
1e33dfb431 [flang] Add missing IS_DEVICE_PTR and LINK clauses for OpenMP parsing
Original-commit: flang-compiler/f18@541d4031e0
Reviewed-on: https://github.com/flang-compiler/f18/pull/501
2019-06-13 15:33:15 -07:00
Peter Steinfeld
93a59505a5 [flang] These changes are for issue 458, to perform semantic checks on DO variable
and initial, final, and step expressions.  As a new extension, we want to allow
REAL and DOUBLE PRECISION values for them by default.

Here's a summary of the changes:
 - There already existed infrastructure for semantic checking of DO loops that
   was partially specific to DO CONCURRENT loops.  Because I re-used some of
   this infrastructure, I renamed some files and classes from "concurrent" to
   "stmt".
 - I added some functions to distinguish among the different kinds of DO
   statements.
 - I added the functions to check-do-stmt.cc to produce the necessary warnins
   and errors.  Note that there are no tests for the warnings since the
   necessary testing infrastructure does not yet exist.
 - I changed test-errors.sh so that additional compilation options can be
   specified in the test source.
 - I added two new tests to test for the various kinds of values that can be
   used for the DO variables and control expressions.  The two tests are
   identical except for the use of different compilation options.
   dosemantics03.f90 specifies the options "-Mstandard -Werror" to produce
   error messages for the use of REAL and DOUBLE PRECISION DO variables and
   controls.  dosemantics04.f90 uses the default options and only produces
   error messages for contructs that are erroneous by default.

Original-commit: flang-compiler/f18@f484660c75
Reviewed-on: https://github.com/flang-compiler/f18/pull/478
Tree-same-pre-rewrite: false
2019-06-10 13:31:31 -07:00
peter klausler
b408a02c14 [flang] Avoid segfault in association semantics by cleaning up code a bit
Original-commit: flang-compiler/f18@04d40c3d75
Reviewed-on: https://github.com/flang-compiler/f18/pull/488
Tree-same-pre-rewrite: false
2019-06-07 10:24:33 -07:00
peter klausler
3e313d43e1 [flang] Fix correction of misparsed struct const as actual arg, and semantics of MODULE PROCEDURE in INTERFACE
Original-commit: flang-compiler/f18@6c86de6cef
Reviewed-on: https://github.com/flang-compiler/f18/pull/477
Tree-same-pre-rewrite: false
2019-06-04 13:37:16 -07:00
peter klausler
59342b0641 [flang] work in progress
checkpoint: changes build, tests all pass

many fixes, ready to test more

Further CLASS(*) support

More fixes for CLASS(*)

Hide data members of DynamicType

implement PRESENT() intrinsic

Original-commit: flang-compiler/f18@044ba12c20
Reviewed-on: https://github.com/flang-compiler/f18/pull/466
Tree-same-pre-rewrite: false
2019-05-20 13:37:28 -07:00
Tim Keith
4c4f4d2807 [flang] Address review comments
Use better names for template parameters of `LoopBounds`, and also
for the constructor arguments.

Use two overloadings of `loopBounds()` instead of `std::is_same_v<>`.

Original-commit: flang-compiler/f18@a2c0c75462
Reviewed-on: https://github.com/flang-compiler/f18/pull/455
Tree-same-pre-rewrite: false
2019-05-09 10:00:13 -07:00
Tim Keith
351dc98948 [flang] Change parse tree to allow DO loop over REAL
It is a common extension to allow DO loops with REAL variable and
bounds. The parse tree currently parses those with the variable
as `scalar-int-variable-name` and the bounds as `scalar-int-expr`.
That causes the INTEGER constraint to be enforced automatically.

Change the grammar and parse tree to treat them as `scalar-variable-name`
and `scalar-expr`. This allows the name and expression to be REAL,
but we will have to verify that they aren't any other type (in a future
change).

To accomplish this, add a template parameter to `LoopBounds` for the type
of the variable name (always `Scalar<Name>` or `Scalar<Integer<Name>>`).
We sometimes need names for the instantiations of `LoopBounds` so add
type aliases like `LoopControl::Bounds` for each one.

Original-commit: flang-compiler/f18@d75aa03970
Reviewed-on: https://github.com/flang-compiler/f18/pull/455
Tree-same-pre-rewrite: false
2019-05-09 08:33:28 -07:00
Tim Keith
5094c3c584 [flang] Save and fetch analyzed Expr in Variable
Add typedExpr data member to Variable like that in Expr.
When expression analysis analyzed a Variable it stores the
resulting evaluate::Expr there.

Add GetExpr overloads in semantics/tools.h for using in statement
semantics. It gets an evaluate::Expr from an Expr, Variable, or
wrapper around one of those. It returns a const pointer so that
clients cannot modify the cached expression (and copies do not
have to be made).

Change CoarrayChecker to make use of GetExpr. It will eventually
replace all references to typedExpr in statement semantics.

Original-commit: flang-compiler/f18@b02a41efe1
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
Tree-same-pre-rewrite: false
2019-04-18 17:48:55 -07:00
peter klausler
f79e3dd0b9 [flang] Generalize tools, clean up common/unwrap.h with new-found knowledge
Original-commit: flang-compiler/f18@aac16907cd
Reviewed-on: https://github.com/flang-compiler/f18/pull/416
Tree-same-pre-rewrite: false
2019-04-16 15:59:04 -07:00
peter klausler
1498911aa2 [flang] Rewrite I/O units in the parse tree when a variable is not character.
Original-commit: flang-compiler/f18@46791a73e7
Reviewed-on: https://github.com/flang-compiler/f18/pull/416
Tree-same-pre-rewrite: false
2019-04-16 12:28:59 -07:00
peter klausler
1b8a78ac13 [flang] Resolve ambiguous I/O unit parse in favor of CharVariable.
Original-commit: flang-compiler/f18@ecabe82825
Reviewed-on: https://github.com/flang-compiler/f18/pull/416
Tree-same-pre-rewrite: false
2019-04-16 12:28:59 -07:00
peter klausler
ce9716d037 [flang] Capture source locations for Designators and Calls
Original-commit: flang-compiler/f18@970333fff7
Reviewed-on: https://github.com/flang-compiler/f18/pull/415
Tree-same-pre-rewrite: false
2019-04-15 15:18:07 -07:00
Tim Keith
b2f84a5eda [flang] More coarray name resolution and semantic checks
Add CoarrayChecker to check for valid team-value in CHANGE TEAM,
SYNC TEAM, and image selector. Check that coarray names and selector
names are distinct in CHANGE TEAM.

Resolve the variable in a coarray-association.
Create a scope for the construct entities of a CHANGE TEAM construct.

Add ResolveSelector to resolve a parser::Selector into an Expr and
optional variable name (and a source location for messages). Make use of
ResolveSelector to handle coarray-association, as well as it's previous
use in associate-stmt.

Improve the check for C1157 in select-type-stmt and add a test.

Add a test for "Associate name must have a type".

Move ResolveName, ResolveDataRef, etc. from ResolveNamesVisitor
to DeclarationVisitor so that they are available in ConstructVisitor
as well. Add ResolveVariable and ResolveDesignator.

In the parse tree, change TeamValue from a type alias to a wrapper
class. We already had a wrapper class anyway, ImageSelectorSpec::Team,
so the new TeamValue can be used instead. This allows the member
of ImageSelectorSpec to be treated like other occurrences of TeamValue.

Original-commit: flang-compiler/f18@f856744b54
Reviewed-on: https://github.com/flang-compiler/f18/pull/414
Tree-same-pre-rewrite: false
2019-04-15 14:07:11 -07:00
Tim Keith
b69c2c6997 [flang] Remove ObjectName alternative from Designator
A simple name in a `Designator` is always parsed as a `DataRef`, not
an `ObjectName`. So remove that alternative.

`StmtFunctionStmt::ConvertToAssignment` was creating a `Designator` with
that alternative: change it to do the same thing as the parser.

Add `GetSimpleName` utility functions to check if an `Expr` or `Variable`
represents a simple name. Many of the places that checked for `ObjectName`
in `Designator` are trying to do that.

Clean up includes and forward declarations in `tools.h`.

Original-commit: flang-compiler/f18@97d44de7b1
Reviewed-on: https://github.com/flang-compiler/f18/pull/410
2019-04-12 16:30:03 -07:00
peter klausler
923c891111 [flang] Do not replace format with namelist if there is no unit (avoiding accidental language extension)
Original-commit: flang-compiler/f18@08562d9b86
Reviewed-on: https://github.com/flang-compiler/f18/pull/394
2019-04-10 08:52:46 -07:00
peter klausler
0e55f2463b [flang] Rewrite read-stmt/write-stmt parse trees for misparsed namelist group names
Original-commit: flang-compiler/f18@e0f1b1c469
Reviewed-on: https://github.com/flang-compiler/f18/pull/394
Tree-same-pre-rewrite: false
2019-04-10 08:52:42 -07:00
peter klausler
4950dfa04e [flang] Redo without macros
Original-commit: flang-compiler/f18@8d955cfb3b
Reviewed-on: https://github.com/flang-compiler/f18/pull/390
2019-04-09 13:29:40 -07:00
peter klausler
d0e7775431 [flang] Revert to forwarding on variadic messaging APIs
Original-commit: flang-compiler/f18@d2e464eb15
Reviewed-on: https://github.com/flang-compiler/f18/pull/390
Tree-same-pre-rewrite: false
2019-04-08 14:29:47 -07:00
peter klausler
dc9c3d1c46 [flang] Fix bug#389, prevent std::move() on forwarded lvalue references
Original-commit: flang-compiler/f18@9d61c091ad
Reviewed-on: https://github.com/flang-compiler/f18/pull/390
Tree-same-pre-rewrite: false
2019-04-08 14:29:45 -07:00
Tim Keith
1599d09041 [flang] Update the grammar with team-value
Everywhere we had `team-variable` except for the FORM TEAM statement is
now `team-value`, according to the N2162 draft standard. The grammar
and parse tree are updated to reflect that.

The addition of the production for `team-value` caused productions
R1177-R1181 to have their numbers increased by one.

Original-commit: flang-compiler/f18@9071f0a352
Reviewed-on: https://github.com/flang-compiler/f18/pull/387
2019-04-06 11:17:07 -07:00
peter klausler
0ff94b9d0b [flang] Define and use UnlabeledStatement<> for if & forall
Original-commit: flang-compiler/f18@028e6aba6c
Reviewed-on: https://github.com/flang-compiler/f18/pull/373
Tree-same-pre-rewrite: false
2019-04-01 16:23:32 -07:00
peter klausler
e0f76d2306 [flang] Support CONVERT= and DISPOSE= on INQUIRE
Original-commit: flang-compiler/f18@fbedd32376
Reviewed-on: https://github.com/flang-compiler/f18/pull/352
Tree-same-pre-rewrite: false
2019-04-01 10:14:19 -07:00
peter klausler
822810f017 [flang] Check int literals for overflow when kind is known.
improve test

Original-commit: flang-compiler/f18@09ce783cd3
Reviewed-on: https://github.com/flang-compiler/f18/pull/352
Tree-same-pre-rewrite: false
2019-04-01 10:14:16 -07:00
peter klausler
5b0e18b0e4 [flang] Allow multiple associations on legacy POINTER declaration
fix that fix

Original-commit: flang-compiler/f18@f096b73842
Reviewed-on: https://github.com/flang-compiler/f18/pull/352
Tree-same-pre-rewrite: false
2019-04-01 10:14:12 -07:00
peter klausler
afd0c19fec [flang] cleanup after extraction and merging
Original-commit: flang-compiler/f18@6314daadc1
Reviewed-on: https://github.com/flang-compiler/f18/pull/346
Tree-same-pre-rewrite: false
2019-03-20 11:49:32 -07:00
peter klausler
ad057a42fa [flang] Remove OwningPointer, use unique_ptr better instead.
Original-commit: flang-compiler/f18@89aff868aa
Reviewed-on: https://github.com/flang-compiler/f18/pull/346
Tree-same-pre-rewrite: false
2019-03-20 11:38:45 -07:00
peter klausler
62c39b72af [flang] Still do scalar- constraint check.
Original-commit: flang-compiler/f18@e50b4c4b48
Reviewed-on: https://github.com/flang-compiler/f18/pull/342
2019-03-19 11:59:58 -07:00
peter klausler
e1a9c85e72 [flang] Simplify grammar for STOP/ERROR STOP.
Original-commit: flang-compiler/f18@eddaea25a2
Reviewed-on: https://github.com/flang-compiler/f18/pull/342
Tree-same-pre-rewrite: false
2019-03-19 11:44:35 -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
3204a1c1b9 [flang] checkpoint
Original-commit: flang-compiler/f18@0c9bdc7032
Reviewed-on: https://github.com/flang-compiler/f18/pull/333
Tree-same-pre-rewrite: false
2019-03-14 14:52:44 -07:00
peter klausler
f3abed639d [flang] Fix misparsings of substrings in the parse tree, not in expressions.
Original-commit: flang-compiler/f18@53d0e26d92
Reviewed-on: https://github.com/flang-compiler/f18/pull/322
Tree-same-pre-rewrite: false
2019-03-09 10:25:07 -08: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
peter klausler
64ea462e3a [flang] Resolve misparse of structure constructor as function reference.
Original-commit: flang-compiler/f18@5b6b2540f6
Reviewed-on: https://github.com/flang-compiler/f18/pull/322
Tree-same-pre-rewrite: false
2019-03-09 10:25:06 -08:00
peter klausler
ab74d1ac0c [flang] Rename to Fortran.h, update style guide, run clang-format
Original-commit: flang-compiler/f18@aa2907d226
Reviewed-on: https://github.com/flang-compiler/f18/pull/308
Tree-same-pre-rewrite: false
2019-02-28 11:48:15 -08:00
peter klausler
6a56782b2f [flang] fix flang-compiler/f18#303, better error recovery for misplaced type parameter declarations
Original-commit: flang-compiler/f18@ebaa23cbcd
Reviewed-on: https://github.com/flang-compiler/f18/pull/307
2019-02-28 09:31:16 -08:00
Tim Keith
efd7bdb030 [flang] Remove TODO for saved-entity
The parser can't distinguish `saved-entity -> object-name` from
`saved-entity -> proc-pointer-name`. So just use `kind` == `Entity`
for those cases. Name resolution will verify it is the right kind
of entity name.

Original-commit: flang-compiler/f18@69d7c0e025
Reviewed-on: https://github.com/flang-compiler/f18/pull/298
Tree-same-pre-rewrite: false
2019-02-21 08:48:30 -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
5b79ffc5f6 [flang] checkpoint
Original-commit: flang-compiler/f18@156791b288
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:22:10 -08:00
peter klausler
d3559a5d18 [flang] Name resolution for structure constructors
Original-commit: flang-compiler/f18@9d60038f03
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:22:04 -08:00
Tim Keith
b60fd092f5 [flang] Simplify CommonStmt in parse tree
The grammar requires parsing the first common block in a common stmt
differently from the others: the '//' is optional for the blank common.

But once it's parsed, it is easier to work with if each is represented
as a `parser::CommonStmt::Block`. This is achieved by using the same
constructor for `CommonStmt` but then including the first block in
the list of blocks.

Original-commit: flang-compiler/f18@dd46afd6b5
Reviewed-on: https://github.com/flang-compiler/f18/pull/284
2019-02-12 16:13:58 -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
e30ef0ec8d [flang] Roll up small tweaks to parser and semantics.
Original-commit: flang-compiler/f18@57d823a809
Reviewed-on: https://github.com/flang-compiler/f18/pull/254
2019-01-07 15:38:48 -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
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
Tim Keith
ed94af4c47 [flang] More name resolution for construct entities
Push a new scope for constructs and statements that require one
(DataStmt, DO CONCURRENT, ForallConstruct, ForallStmt -- there are more
to do). Currently we use the Block kind of scope because there is no
difference. Perhaps that kind should be renamed to Construct, though it
does apply to statements as well as constructs.

Add DeclareConstructEntity to create a construct or statement entity.
When the type is not specified it can come from the type of a symbol in
the enclosing scope with the same name. Change DeclareObjectEntity et al.
to return the symbol declared, for the benefit of DeclareConstructEntity.

Use DeclareConstructEntity for DO CONCURRENT index-name, LOCAL, and
LOCAL_INIT variables and the data-i-do-variable in DataImpliedDo

Names in SHARED locality spec need special handling: create a new kinds
of symbol with HostAssocDetails to represent the host-association of the
shared variables within the construct scope. That symbol gets the
LocalityShared flag without affecting the symbol in the outer scope.
HostAssoc symbols may be useful in other contexts, e.g. up-level
references to local variables.

Add parser::DoConstruct::IsDoConcurrent() because DO CONCURRENT loops
introduce a construct scope while other DO loops do not.

Move CanonicalizeDo to before name resolution so that name resolution
doesn't have to deal with labeled DO CONCURRENT loops.

Allow for type of index name to be specified in ConcurrentHeader.

Resolve the derived type name in an AllocateStmt, StructureConstructor

Original-commit: flang-compiler/f18@bc7b989136
Reviewed-on: https://github.com/flang-compiler/f18/pull/214
2018-10-18 09:06:11 -07:00
peter klausler
c71aecb787 [flang] Correct the spelling of LOCAL_INIT clauses on DO CONCURRENT statements.
Original-commit: flang-compiler/f18@bfc869ad5f
Reviewed-on: https://github.com/flang-compiler/f18/pull/198
2018-10-02 10:03:37 -07:00
peter klausler
a5687fd579 [flang] source provenances for expressions
Original-commit: flang-compiler/f18@5fe292fcac
Reviewed-on: https://github.com/flang-compiler/f18/pull/195
Tree-same-pre-rewrite: false
2018-09-25 15:24:00 -07:00
peter klausler
93a7f1f85c [flang] work on structure components
Original-commit: flang-compiler/f18@619b6957b4
Reviewed-on: https://github.com/flang-compiler/f18/pull/195
Tree-same-pre-rewrite: false
2018-09-25 15:23:58 -07:00
peter klausler
6c6234be9e [flang] clean up for review
Original-commit: flang-compiler/f18@d3d81b1e6f
Reviewed-on: https://github.com/flang-compiler/f18/pull/183
Tree-same-pre-rewrite: false
2018-09-12 16:29:20 -07:00
peter klausler
003c8329ba [flang] add left(), right(), and comments
Original-commit: flang-compiler/f18@372fd06508
Reviewed-on: https://github.com/flang-compiler/f18/pull/183
Tree-same-pre-rewrite: false
2018-09-12 16:29:16 -07:00