1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ES2PANDA_COMPILER_CHECKER_TYPES_ETS_FLOAT_TYPE_H 17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_FLOAT_TYPE_H 18 19 #include "checker/types/type.h" 20 21 namespace ark::es2panda::checker { 22 class FloatType : public Type { 23 public: 24 using UType = float; 25 FloatType()26 FloatType() : Type(TypeFlag::FLOAT) {} FloatType(UType value)27 explicit FloatType(UType value) : Type(TypeFlag::FLOAT | TypeFlag::CONSTANT), value_(value) {} 28 GetValue()29 UType GetValue() const 30 { 31 return value_; 32 } 33 34 void Identical(TypeRelation *relation, Type *other) override; 35 void AssignmentTarget(TypeRelation *relation, Type *source) override; 36 bool AssignmentSource([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *target) override; 37 void Cast(TypeRelation *relation, Type *target) override; 38 Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; 39 ToString(std::stringstream & ss,bool precise)40 void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override 41 { 42 ss << "float"; 43 } 44 ToAssemblerType(std::stringstream & ss)45 void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override 46 { 47 ss << compiler::Signatures::PRIMITIVE_FLOAT; 48 } 49 ToDebugInfoType(std::stringstream & ss)50 void ToDebugInfoType(std::stringstream &ss) const override 51 { 52 ss << compiler::Signatures::TYPE_DESCRIPTOR_FLOAT; 53 } 54 ResolveConditionExpr()55 std::tuple<bool, bool> ResolveConditionExpr() const override 56 { 57 // isNan = !(value_ == value_) 58 return {IsConstantType(), (value_ != 0) && (value_ == value_)}; 59 } 60 61 private: 62 UType value_ {0.0}; 63 }; 64 } // namespace ark::es2panda::checker 65 66 #endif 67