[Impl] 增加 prettyType,返回TypeInfo的FString, StructInstance自动输出父类TypeInfo
This commit is contained in:
@@ -107,7 +107,7 @@ namespace Fig
|
|||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format(
|
std::format(
|
||||||
"Type `List` indices must be `Int`, got '{}'",
|
"Type `List` indices must be `Int`, got '{}'",
|
||||||
index->getTypeInfo().toString().toBasicString()),
|
prettyType(index).toBasicString()),
|
||||||
ie->index);
|
ie->index);
|
||||||
}
|
}
|
||||||
List &list = base.get()->as<List>();
|
List &list = base.get()->as<List>();
|
||||||
@@ -142,7 +142,7 @@ namespace Fig
|
|||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format(
|
std::format(
|
||||||
"Type `String` indices must be `Int`, got '{}'",
|
"Type `String` indices must be `Int`, got '{}'",
|
||||||
index->getTypeInfo().toString().toBasicString()),
|
prettyType(index).toBasicString()),
|
||||||
ie->index);
|
ie->index);
|
||||||
}
|
}
|
||||||
FString &string = base.get()->as<ValueType::StringClass>();
|
FString &string = base.get()->as<ValueType::StringClass>();
|
||||||
@@ -390,7 +390,7 @@ namespace Fig
|
|||||||
throw EvaluatorError(
|
throw EvaluatorError(
|
||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format("Condition must be boolean, got '{}'",
|
std::format("Condition must be boolean, got '{}'",
|
||||||
condVal->getTypeInfo().toString().toBasicString()),
|
prettyType(condVal).toBasicString()),
|
||||||
te->condition);
|
te->condition);
|
||||||
}
|
}
|
||||||
ValueType::BoolClass cond = condVal->as<ValueType::BoolClass>();
|
ValueType::BoolClass cond = condVal->as<ValueType::BoolClass>();
|
||||||
@@ -477,7 +477,7 @@ namespace Fig
|
|||||||
std::format("In function '{}', default parameter '{}' has type '{}', which does not match the expected type '{}'",
|
std::format("In function '{}', default parameter '{}' has type '{}', which does not match the expected type '{}'",
|
||||||
fnName.toBasicString(),
|
fnName.toBasicString(),
|
||||||
fnParas.defParas[defParamIndex].first.toBasicString(),
|
fnParas.defParas[defParamIndex].first.toBasicString(),
|
||||||
defaultVal->getTypeInfo().toString().toBasicString(),
|
prettyType(defaultVal).toBasicString(),
|
||||||
expectedType.toString().toBasicString()),
|
expectedType.toString().toBasicString()),
|
||||||
fnArgs.argv[i]);
|
fnArgs.argv[i]);
|
||||||
}
|
}
|
||||||
@@ -560,7 +560,7 @@ namespace Fig
|
|||||||
std::format("Function '{}' expects return type '{}', but got type '{}'",
|
std::format("Function '{}' expects return type '{}', but got type '{}'",
|
||||||
fnName.toBasicString(),
|
fnName.toBasicString(),
|
||||||
fnStruct.retType.toString().toBasicString(),
|
fnStruct.retType.toString().toBasicString(),
|
||||||
retVal->getTypeInfo().toString().toBasicString()),
|
prettyType(retVal).toBasicString()),
|
||||||
fnStruct.body);
|
fnStruct.body);
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
@@ -750,7 +750,7 @@ namespace Fig
|
|||||||
initExpr->structName.toBasicString(),
|
initExpr->structName.toBasicString(),
|
||||||
fieldName.toBasicString(),
|
fieldName.toBasicString(),
|
||||||
expectedType.toString().toBasicString(),
|
expectedType.toString().toBasicString(),
|
||||||
defaultVal->getTypeInfo().toString().toBasicString()),
|
prettyType(defaultVal).toBasicString()),
|
||||||
initExpr);
|
initExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,7 +767,7 @@ namespace Fig
|
|||||||
initExpr->structName.toBasicString(),
|
initExpr->structName.toBasicString(),
|
||||||
fieldName.toBasicString(),
|
fieldName.toBasicString(),
|
||||||
expectedType.toString().toBasicString(),
|
expectedType.toString().toBasicString(),
|
||||||
argVal->getTypeInfo().toString().toBasicString()),
|
prettyType(argVal).toBasicString()),
|
||||||
initExpr);
|
initExpr);
|
||||||
}
|
}
|
||||||
instanceCtx->def(fieldName, expectedType, field.am, argVal);
|
instanceCtx->def(fieldName, expectedType, field.am, argVal);
|
||||||
@@ -806,7 +806,7 @@ namespace Fig
|
|||||||
initExpr->structName.toBasicString(),
|
initExpr->structName.toBasicString(),
|
||||||
fieldName.toBasicString(),
|
fieldName.toBasicString(),
|
||||||
expectedType.toString().toBasicString(),
|
expectedType.toString().toBasicString(),
|
||||||
defaultVal->getTypeInfo().toString().toBasicString()),
|
prettyType(defaultVal).toBasicString()),
|
||||||
initExpr);
|
initExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,7 +823,7 @@ namespace Fig
|
|||||||
initExpr->structName.toBasicString(),
|
initExpr->structName.toBasicString(),
|
||||||
fieldName.toBasicString(),
|
fieldName.toBasicString(),
|
||||||
field.type.toString().toBasicString(),
|
field.type.toString().toBasicString(),
|
||||||
argVal->getTypeInfo().toString().toBasicString()),
|
prettyType(argVal).toBasicString()),
|
||||||
initExpr);
|
initExpr);
|
||||||
}
|
}
|
||||||
instanceCtx->def(fieldName, field.type, field.am, argVal);
|
instanceCtx->def(fieldName, field.type, field.am, argVal);
|
||||||
@@ -926,7 +926,7 @@ namespace Fig
|
|||||||
"Variable `{}` expects init-value type `{}`, but got '{}'",
|
"Variable `{}` expects init-value type `{}`, but got '{}'",
|
||||||
varDef->name.toBasicString(),
|
varDef->name.toBasicString(),
|
||||||
declaredTypeName.toBasicString(),
|
declaredTypeName.toBasicString(),
|
||||||
value->getTypeInfo().toString().toBasicString()),
|
prettyType(value).toBasicString()),
|
||||||
varDef->expr);
|
varDef->expr);
|
||||||
}
|
}
|
||||||
else if (value == nullptr)
|
else if (value == nullptr)
|
||||||
@@ -1040,7 +1040,7 @@ namespace Fig
|
|||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format(
|
std::format(
|
||||||
"Condition must be boolean, but got '{}'",
|
"Condition must be boolean, but got '{}'",
|
||||||
condVal->getTypeInfo().toString().toBasicString()),
|
prettyType(condVal).toBasicString()),
|
||||||
ifSt->condition);
|
ifSt->condition);
|
||||||
}
|
}
|
||||||
if (condVal->as<ValueType::BoolClass>())
|
if (condVal->as<ValueType::BoolClass>())
|
||||||
@@ -1057,7 +1057,7 @@ namespace Fig
|
|||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format(
|
std::format(
|
||||||
"Condition must be boolean, but got '{}'",
|
"Condition must be boolean, but got '{}'",
|
||||||
condVal->getTypeInfo().toString().toBasicString()),
|
prettyType(condVal).toBasicString()),
|
||||||
ifSt->condition);
|
ifSt->condition);
|
||||||
}
|
}
|
||||||
if (elifCondVal->as<ValueType::BoolClass>())
|
if (elifCondVal->as<ValueType::BoolClass>())
|
||||||
@@ -1082,7 +1082,7 @@ namespace Fig
|
|||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format(
|
std::format(
|
||||||
"Condition must be boolean, but got '{}'",
|
"Condition must be boolean, but got '{}'",
|
||||||
condVal->getTypeInfo().toString().toBasicString()),
|
prettyType(condVal).toBasicString()),
|
||||||
whileSt->condition);
|
whileSt->condition);
|
||||||
}
|
}
|
||||||
if (!condVal->as<ValueType::BoolClass>())
|
if (!condVal->as<ValueType::BoolClass>())
|
||||||
@@ -1128,7 +1128,7 @@ namespace Fig
|
|||||||
u8"TypeError",
|
u8"TypeError",
|
||||||
std::format(
|
std::format(
|
||||||
"Condition must be boolean, but got '{}'",
|
"Condition must be boolean, but got '{}'",
|
||||||
condVal->getTypeInfo().toString().toBasicString()),
|
prettyType(condVal).toBasicString()),
|
||||||
forSt->condition);
|
forSt->condition);
|
||||||
}
|
}
|
||||||
if (!condVal->as<ValueType::BoolClass>())
|
if (!condVal->as<ValueType::BoolClass>())
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Fig
|
|||||||
return id == other.id;
|
return id == other.id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeInfoHash
|
class TypeInfoHash
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -69,6 +69,14 @@ namespace Fig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString prettyType(ObjectPtr obj)
|
||||||
|
{
|
||||||
|
auto t = obj->getTypeInfo();
|
||||||
|
if (t == ValueType::StructInstance)
|
||||||
|
return obj->as<StructInstance>().parentType.toString();
|
||||||
|
return t.toString();
|
||||||
|
}
|
||||||
|
|
||||||
const TypeInfo ValueType::Any(FString(u8"Any"), true); // id: 1
|
const TypeInfo ValueType::Any(FString(u8"Any"), true); // id: 1
|
||||||
const TypeInfo ValueType::Null(FString(u8"Null"), true); // id: 2
|
const TypeInfo ValueType::Null(FString(u8"Null"), true); // id: 2
|
||||||
const TypeInfo ValueType::Int(FString(u8"Int"), true); // id: 3
|
const TypeInfo ValueType::Int(FString(u8"Int"), true); // id: 3
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ namespace Fig
|
|||||||
using ObjectPtr = std::shared_ptr<Object>;
|
using ObjectPtr = std::shared_ptr<Object>;
|
||||||
using List = std::vector<ObjectPtr>;
|
using List = std::vector<ObjectPtr>;
|
||||||
|
|
||||||
|
FString prettyType(ObjectPtr obj);
|
||||||
|
|
||||||
struct ValueKey
|
struct ValueKey
|
||||||
{
|
{
|
||||||
ObjectPtr value;
|
ObjectPtr value;
|
||||||
|
|||||||
Reference in New Issue
Block a user