cf410675cf
Original-commit: flang-compiler/f18@3839c65cd5 Reviewed-on: https://github.com/flang-compiler/f18/pull/111 Tree-same-pre-rewrite: false
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
// 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"
|
|
#include "testing.h"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
using namespace Fortran::evaluate;
|
|
|
|
template<typename A> std::string Dump(const A &x) {
|
|
std::stringstream ss;
|
|
x.Dump(ss);
|
|
return ss.str();
|
|
}
|
|
|
|
int main() {
|
|
TEST(DefaultIntegerExpr::Result::Dump() == "Integer(4)");
|
|
MATCH("666", Dump(DefaultIntegerExpr{666}));
|
|
MATCH("(-1)", Dump(-DefaultIntegerExpr{1}));
|
|
auto ex1{DefaultIntegerExpr{2} + DefaultIntegerExpr{3} * -DefaultIntegerExpr{4}};
|
|
MATCH("(2+(3*(-4)))", Dump(ex1));
|
|
Fortran::parser::CharBlock src;
|
|
ex1.Fold(src, nullptr);
|
|
MATCH("-10", Dump(ex1));
|
|
MATCH("(6.LE.7)", Dump(DefaultIntegerExpr{6} <= DefaultIntegerExpr{7}));
|
|
DefaultIntegerExpr a{1};
|
|
DefaultIntegerExpr b{2};
|
|
MATCH("(1/2)", Dump(a / b));
|
|
MATCH("1", Dump(a));
|
|
a = b;
|
|
MATCH("2", Dump(a));
|
|
MATCH("2", Dump(b));
|
|
return testing::Complete();
|
|
}
|