Commit graph

5 commits

Author SHA1 Message Date
Tim Keith
1c291436f5 [flang] Implement parse tree rewriting.
Add parse-tree-mutator.h like parse-tree-visitor.h except that the Walk
functions take non-const references to parse tree nodes so the Pre and
Post methods of the mutator that are passed around can make changes to
the parse tree.

Change ExecutionPart to be a class that wraps a list so that it can be
identified during parse tree walking.

Add Symbol* field to parser::Name for the result of symbol resolution.
In parse tree dumper, dump symbol when it is there instead of just name.

Add RewriteParseTree to walk the parse tree, fill in resolved symbols in
Name nodes, and make necessary changes to the structure. Currently that
consists of rewriting statement functions as array assignments when
appropriate.

In ResolveNames, call RewriteParseTree if the resolution was successful.
Recognize a statement function that comes after a mis-identified
statement function and report an error. resolve08.f90 tests this case.

Add -fdebug-dump-symbols to dump the scope tree and symbols in each scope.
This is implemented by DumpSymbols in resolve-names.cc. Add an optional
symbol to scopes that correspond to symbols (e.g. subprograms). Remove
debug output from ResolveNamesVisitor as this option can be used instead.

Original-commit: flang-compiler/f18@9cd3372265
Reviewed-on: https://github.com/flang-compiler/f18/pull/60
Tree-same-pre-rewrite: false
2018-04-18 15:06:35 -07:00
Stephane Chauveau
f49e2dfa2a [flang] Merge with current master and move code to lib/semantics/
Original-commit: flang-compiler/f18@8b31a01102
Reviewed-on: https://github.com/flang-compiler/f18/pull/24
Tree-same-pre-rewrite: false
2018-03-26 16:35:34 +02:00
Tim Keith
a3de9d789c [flang] Partial implementation of Symbols and Scopes.
A Symbol consists of a common part (in class Symbol) containing name,
owner, attributes. Information for a specific kind of symbol is in a
variant containing one of the *Details classes. So the kind of symbol is
determined by the type of details class stored in the details_ variant.

For scopes there is a single Scope class with an enum indicating the
kind. So far there isn't a need for extra kind-specific details as with
Symbols but that could change. Symbols defined in a Scope are stored
there in a simple map.

resolve-names.cc is a partial implementation of a parse-tree walker that
resolves names to Symbols. Currently is only handles functions (which
introduce a new Scope) and entity-decls. The test-type executable was
reused as a driver for this to avoid the need for a new one.

Sample output is below. When each "end function" is encountered the
scope is dumped, which shows the symbols defined in it.

$ cat a.f90
pure integer(8) function foo(arg1, arg2) result(res)
  integer :: arg1
  real :: arg2
contains
  function bar(arg1)
    real :: bar
    real :: arg1
  end function
end function

$ Debug/tools/f18/test-type a.f90
Subprogram scope: 0 children
  arg1:  Entity type: REAL
  bar:  Entity type: REAL
Subprogram scope: 1 children
  arg1:  Entity type: INTEGER
  arg2:  Entity type: REAL
  bar:  Subprogram (arg1)
  foo:  Subprogram (arg1, arg2) result(res)
  res:  Entity type: INTEGER(8)

Original-commit: flang-compiler/f18@1cd2fbc04d
Reviewed-on: https://github.com/flang-compiler/f18/pull/30
Tree-same-pre-rewrite: false
2018-03-22 17:25:34 -07:00
Tim Keith
600788e5f7 [flang] Add MakeTypes to build types using visitor.
This replaces the manual walking code in test-type.cc. It walks the
parse tree and constructs DeclTypeSpec and DerivedTypeDef objects for
each type encountered. It's in a new file, make-types.cc, so that
failing compilations complete faster.

Handle more parts of derived type definitions.

Also some minor cleanups in type.h and type.cc.

Original-commit: flang-compiler/f18@859e7e2665
Reviewed-on: https://github.com/flang-compiler/f18/pull/23
Tree-same-pre-rewrite: false
2018-03-01 15:24:35 -08:00
Stephane Chauveau
8f6f23fc54 [flang] Add simple recursive CMake directory structure
Original-commit: flang-compiler/f18@a021b2ca76
Reviewed-on: https://github.com/flang-compiler/f18/pull/13
Tree-same-pre-rewrite: false
2018-02-19 14:28:12 +01:00