Merge branch 'midend' of gitee.com:lixuanwang/mysysy into midend

This commit is contained in:
Lixuanwang
2025-07-30 11:31:46 +08:00

View File

@ -359,12 +359,25 @@ public:
// Helper methods to access constant values with appropriate casting
int getInt() const {
assert(getType()->isInt() && "Calling getInt() on non-integer type");
return std::get<int>(getVal());
auto val = getVal();
if (std::holds_alternative<int>(val)) {
return std::get<int>(val);
} else if (std::holds_alternative<float>(val)) {
return static_cast<int>(std::get<float>(val));
}
// Handle other possible types if needed
return 0; // Default fallback
}
float getFloat() const {
assert(getType()->isFloat() && "Calling getFloat() on non-float type");
return std::get<float>(getVal());
auto val = getVal();
if (std::holds_alternative<float>(val)) {
return std::get<float>(val);
} else if (std::holds_alternative<int>(val)) {
return static_cast<float>(std::get<int>(val));
}
// Handle other possible types if needed
return 0.0f; // Default fallback
}
template<typename T>