1#include "flang/Evaluate/expression.h"
2#include "testing.h"
3#include "flang/Evaluate/fold.h"
4#include "flang/Evaluate/intrinsics.h"
5#include "flang/Evaluate/target.h"
6#include "flang/Evaluate/tools.h"
7#include "flang/Parser/message.h"
8#include <cstdio>
9#include <cstdlib>
10#include <string>
11
12using namespace Fortran::evaluate;
13
14int main() {
15 using DefaultIntegerExpr = Expr<Type<TypeCategory::Integer, 4>>;
16 TEST(DefaultIntegerExpr::Result::AsFortran() == "INTEGER(4)");
17 MATCH("666_4", DefaultIntegerExpr{666}.AsFortran());
18 MATCH("-1_4", (-DefaultIntegerExpr{1}).AsFortran());
19 auto ex1{
20 DefaultIntegerExpr{2} + DefaultIntegerExpr{3} * -DefaultIntegerExpr{4}};
21 MATCH("2_4+3_4*(-4_4)", ex1.AsFortran());
22 Fortran::common::IntrinsicTypeDefaultKinds defaults;
23 auto intrinsics{Fortran::evaluate::IntrinsicProcTable::Configure(defaults)};
24 TargetCharacteristics targetCharacteristics;
25 Fortran::common::LanguageFeatureControl languageFeatures;
26 std::set<std::string> tempNames;
27 FoldingContext context{Fortran::parser::ContextualMessages{nullptr}, defaults,
28 intrinsics, targetCharacteristics, languageFeatures, tempNames};
29 ex1 = Fold(context, std::move(ex1));
30 MATCH("-10_4", ex1.AsFortran());
31 MATCH("1_4/2_4", (DefaultIntegerExpr{1} / DefaultIntegerExpr{2}).AsFortran());
32 DefaultIntegerExpr a{1};
33 DefaultIntegerExpr b{2};
34 MATCH("1_4", a.AsFortran());
35 a = b;
36 MATCH("2_4", a.AsFortran());
37 MATCH("2_4", b.AsFortran());
38 return testing::Complete();
39}
40

source code of flang/unittests/Evaluate/expression.cpp