xref: /llvm-project-15.0.7/flang/unittests/Evaluate/expression.cpp (revision 643dfd97)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 using namespace Fortran::evaluate;
13 
14 int 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   FoldingContext context{Fortran::parser::ContextualMessages{nullptr}, defaults,
26       intrinsics, targetCharacteristics};
27   ex1 = Fold(context, std::move(ex1));
28   MATCH("-10_4", ex1.AsFortran());
29   MATCH("1_4/2_4", (DefaultIntegerExpr{1} / DefaultIntegerExpr{2}).AsFortran());
30   DefaultIntegerExpr a{1};
31   DefaultIntegerExpr b{2};
32   MATCH("1_4", a.AsFortran());
33   a = b;
34   MATCH("2_4", a.AsFortran());
35   MATCH("2_4", b.AsFortran());
36   return testing::Complete();
37 }
38 

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026