mirror of
https://github.com/intel/llvm.git
synced 2026-01-22 15:41:35 +08:00
[flang] Save AllocateObject and PointerObject analyzed expression
`parser::AllocateObject` and `parser::PointerObject` can be represented as typed expressions once analyzed. This simplifies the work for parse-tree consumers that work with typed expressions to deal with allocatable and pointer objects such as lowering. This change also makes it easier to add typedExpr in the future by automatically handling nodes that have this member when possible. Changes: - Add a `mutable TypedExpr typedExpr` field to `parser::PointerObject` and `parser::AllocateObject`. - Add a `parser::HasTypedExpr<T>` helper to better share code relating to typedExpr in the parse tree. - Add hooks in `semantics::ExprChecker` for AllocateObject and PointerObject nodes, and use ExprOrVariable on it to analyze and set the tyedExpr field during expression analysis. This required adding overloads for `AssumedTypeDummy`. - Update check-nullify.cpp and check-deallocate.cpp to not re-analyze the StructureComponent but to use the typedExpr field instead. - Update dump/unparse to use HasTypedExpr and use the typedExpr when there is one. Differential Revision: https://reviews.llvm.org/D98256
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "flang/Parser/characters.h"
|
||||
#include "flang/Parser/parse-tree-visitor.h"
|
||||
#include "flang/Parser/parse-tree.h"
|
||||
#include "flang/Parser/tools.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
@@ -48,6 +49,14 @@ public:
|
||||
Unparse(x);
|
||||
Post(x);
|
||||
return false; // Walk() does not visit descendents
|
||||
} else if constexpr (HasTypedExpr<T>::value) {
|
||||
// Format the expression representation from semantics
|
||||
if (asFortran_ && x.typedExpr) {
|
||||
asFortran_->expr(out_, *x.typedExpr);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
Before(x);
|
||||
return true; // there's no Unparse() defined here, Walk() the descendents
|
||||
@@ -816,15 +825,6 @@ public:
|
||||
}
|
||||
|
||||
// R1001 - R1022
|
||||
bool Pre(const Expr &x) {
|
||||
if (asFortran_ && x.typedExpr) {
|
||||
// Format the expression representation from semantics
|
||||
asFortran_->expr(out_, *x.typedExpr);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
void Unparse(const Expr::Parentheses &x) { Put('('), Walk(x.v), Put(')'); }
|
||||
void Before(const Expr::UnaryPlus &) { Put("+"); }
|
||||
void Before(const Expr::Negate &) { Put("-"); }
|
||||
|
||||
Reference in New Issue
Block a user