2019-04-01 21:30:08 +02:00
|
|
|
// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
|
2018-06-19 23:16:01 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "../../lib/evaluate/expression.h"
|
2018-06-19 23:17:14 +02:00
|
|
|
#include "testing.h"
|
2018-10-27 00:10:24 +02:00
|
|
|
#include "../../lib/evaluate/fold.h"
|
2018-10-16 22:24:57 +02:00
|
|
|
#include "../../lib/evaluate/tools.h"
|
2018-08-01 18:45:59 +02:00
|
|
|
#include "../../lib/parser/message.h"
|
2018-06-19 23:16:01 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2018-06-21 01:50:27 +02:00
|
|
|
#include <sstream>
|
2018-06-22 22:00:13 +02:00
|
|
|
#include <string>
|
2018-06-19 23:16:01 +02:00
|
|
|
|
|
|
|
using namespace Fortran::evaluate;
|
|
|
|
|
2018-11-06 00:02:37 +01:00
|
|
|
template<typename A> std::string AsFortran(const A &x) {
|
2018-06-22 22:00:13 +02:00
|
|
|
std::stringstream ss;
|
2018-11-06 00:02:37 +01:00
|
|
|
x.AsFortran(ss);
|
2018-06-22 22:00:13 +02:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2018-06-19 23:16:01 +02:00
|
|
|
int main() {
|
2018-10-16 22:24:57 +02:00
|
|
|
using DefaultIntegerExpr = Expr<Type<TypeCategory::Integer, 4>>;
|
2018-11-06 00:02:37 +01:00
|
|
|
TEST(DefaultIntegerExpr::Result::AsFortran() == "Integer(4)");
|
|
|
|
MATCH("666_4", AsFortran(DefaultIntegerExpr{666}));
|
2019-04-01 19:54:22 +02:00
|
|
|
MATCH("-1_4", AsFortran(-DefaultIntegerExpr{1}));
|
2018-08-01 18:45:59 +02:00
|
|
|
auto ex1{
|
|
|
|
DefaultIntegerExpr{2} + DefaultIntegerExpr{3} * -DefaultIntegerExpr{4}};
|
2019-04-01 21:30:08 +02:00
|
|
|
MATCH("2_4+3_4*(-4_4)", AsFortran(ex1));
|
2018-06-22 23:51:15 +02:00
|
|
|
Fortran::parser::CharBlock src;
|
2018-07-24 21:58:29 +02:00
|
|
|
Fortran::parser::ContextualMessages messages{src, nullptr};
|
|
|
|
FoldingContext context{messages};
|
2018-10-27 00:10:24 +02:00
|
|
|
ex1 = Fold(context, std::move(ex1));
|
2018-11-06 00:02:37 +01:00
|
|
|
MATCH("-10_4", AsFortran(ex1));
|
2019-04-01 19:54:22 +02:00
|
|
|
MATCH("1_4/2_4", AsFortran(DefaultIntegerExpr{1} / DefaultIntegerExpr{2}));
|
2018-06-22 22:00:13 +02:00
|
|
|
DefaultIntegerExpr a{1};
|
|
|
|
DefaultIntegerExpr b{2};
|
2018-11-06 00:02:37 +01:00
|
|
|
MATCH("1_4", AsFortran(a));
|
2018-06-22 22:00:13 +02:00
|
|
|
a = b;
|
2018-11-06 00:02:37 +01:00
|
|
|
MATCH("2_4", AsFortran(a));
|
|
|
|
MATCH("2_4", AsFortran(b));
|
2018-06-19 23:16:01 +02:00
|
|
|
return testing::Complete();
|
|
|
|
}
|