mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 07:26:40 +00:00

The non-GTest library will be shared by unittests of Flang and Flang-RT. Promote it as a regular library for use by both projects. In the long term, we may want to convert these to regular GTest checks to avoid having multiple testing frameworks.
40 lines
1.5 KiB
C++
40 lines
1.5 KiB
C++
#include "flang/Evaluate/expression.h"
|
|
#include "flang/Evaluate/fold.h"
|
|
#include "flang/Evaluate/intrinsics.h"
|
|
#include "flang/Evaluate/target.h"
|
|
#include "flang/Evaluate/tools.h"
|
|
#include "flang/Parser/message.h"
|
|
#include "flang/Testing/testing.h"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
|
|
using namespace Fortran::evaluate;
|
|
|
|
int main() {
|
|
using DefaultIntegerExpr = Expr<Type<TypeCategory::Integer, 4>>;
|
|
TEST(DefaultIntegerExpr::Result::AsFortran() == "INTEGER(4)");
|
|
MATCH("666_4", DefaultIntegerExpr{666}.AsFortran());
|
|
MATCH("-1_4", (-DefaultIntegerExpr{1}).AsFortran());
|
|
auto ex1{
|
|
DefaultIntegerExpr{2} + DefaultIntegerExpr{3} * -DefaultIntegerExpr{4}};
|
|
MATCH("2_4+3_4*(-4_4)", ex1.AsFortran());
|
|
Fortran::common::IntrinsicTypeDefaultKinds defaults;
|
|
auto intrinsics{Fortran::evaluate::IntrinsicProcTable::Configure(defaults)};
|
|
TargetCharacteristics targetCharacteristics;
|
|
Fortran::common::LanguageFeatureControl languageFeatures;
|
|
std::set<std::string> tempNames;
|
|
FoldingContext context{Fortran::parser::ContextualMessages{nullptr}, defaults,
|
|
intrinsics, targetCharacteristics, languageFeatures, tempNames};
|
|
ex1 = Fold(context, std::move(ex1));
|
|
MATCH("-10_4", ex1.AsFortran());
|
|
MATCH("1_4/2_4", (DefaultIntegerExpr{1} / DefaultIntegerExpr{2}).AsFortran());
|
|
DefaultIntegerExpr a{1};
|
|
DefaultIntegerExpr b{2};
|
|
MATCH("1_4", a.AsFortran());
|
|
a = b;
|
|
MATCH("2_4", a.AsFortran());
|
|
MATCH("2_4", b.AsFortran());
|
|
return testing::Complete();
|
|
}
|