2018-06-19 23:16:01 +02:00
|
|
|
// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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-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-06-22 22:00:13 +02:00
|
|
|
template<typename A> std::string Dump(const A &x) {
|
|
|
|
std::stringstream ss;
|
|
|
|
x.Dump(ss);
|
|
|
|
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-06-22 00:35:25 +02:00
|
|
|
TEST(DefaultIntegerExpr::Result::Dump() == "Integer(4)");
|
2018-08-17 18:50:32 +02:00
|
|
|
MATCH("666_4", Dump(DefaultIntegerExpr{666}));
|
|
|
|
MATCH("(-1_4)", Dump(-DefaultIntegerExpr{1}));
|
2018-08-01 18:45:59 +02:00
|
|
|
auto ex1{
|
|
|
|
DefaultIntegerExpr{2} + DefaultIntegerExpr{3} * -DefaultIntegerExpr{4}};
|
2018-08-17 18:50:32 +02:00
|
|
|
MATCH("(2_4+(3_4*(-4_4)))", Dump(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-07-05 19:47:01 +02:00
|
|
|
ex1.Fold(context);
|
2018-08-17 18:50:32 +02:00
|
|
|
MATCH("-10_4", Dump(ex1));
|
2018-08-20 18:29:08 +02:00
|
|
|
MATCH("(1_4/2_4)", Dump(DefaultIntegerExpr{1} / DefaultIntegerExpr{2}));
|
2018-06-22 22:00:13 +02:00
|
|
|
DefaultIntegerExpr a{1};
|
|
|
|
DefaultIntegerExpr b{2};
|
2018-08-17 18:50:32 +02:00
|
|
|
MATCH("1_4", Dump(a));
|
2018-06-22 22:00:13 +02:00
|
|
|
a = b;
|
2018-08-17 18:50:32 +02:00
|
|
|
MATCH("2_4", Dump(a));
|
|
|
|
MATCH("2_4", Dump(b));
|
2018-06-19 23:16:01 +02:00
|
|
|
return testing::Complete();
|
|
|
|
}
|