use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.
the class ProtoTypeRegistry method register.
@Override
public void register(Object t) {
if (t instanceof Message) {
Set<FileDescriptor> fds = collectFileDescriptorSet((Message) t);
for (FileDescriptor fd : fds) {
registerDescriptor(fd);
}
registerMessage((Message) t);
} else if (t instanceof org.projectnessie.cel.common.types.ref.Type) {
registerType((org.projectnessie.cel.common.types.ref.Type) t);
} else {
throw new RuntimeException(String.format("unsupported type: %s", t.getClass().getName()));
}
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.
the class CELTest method Customtypes.
@Test
void Customtypes() {
Type exprType = Decls.newObjectType("google.api.expr.v1alpha1.Expr");
TypeRegistry reg = newEmptyRegistry();
Env e = newEnv(customTypeAdapter(reg), customTypeProvider(reg), container("google.api.expr.v1alpha1"), types(Expr.getDefaultInstance(), BoolT.BoolType, IntT.IntType, StringT.StringType), declarations(Decls.newVar("expr", exprType)));
AstIssuesTuple astIss = e.compile("expr == Expr{id: 2,\n" + "\t\t\tcall_expr: Expr.Call{\n" + "\t\t\t\tfunction: \"_==_\",\n" + "\t\t\t\targs: [\n" + "\t\t\t\t\tExpr{id: 1, ident_expr: Expr.Ident{ name: \"a\" }},\n" + "\t\t\t\t\tExpr{id: 3, ident_expr: Expr.Ident{ name: \"b\" }}]\n" + "\t\t\t}}");
assertThat(astIss.getAst().getResultType()).isEqualTo(Decls.Bool);
Program prg = e.program(astIss.getAst());
Object vars = mapOf("expr", Expr.newBuilder().setId(2).setCallExpr(Call.newBuilder().setFunction("_==_").addAllArgs(asList(Expr.newBuilder().setId(1).setIdentExpr(Ident.newBuilder().setName("a")).build(), Expr.newBuilder().setId(3).setIdentExpr(Ident.newBuilder().setName("b")).build()))).build());
EvalResult out = prg.eval(vars);
assertThat(out.getVal()).isSameAs(True);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.
the class CheckerEnvTest method overlappingOverload.
@Test
void overlappingOverload() {
CheckerEnv env = newStandardCheckerEnv(Container.defaultContainer, newRegistry());
Type paramA = Decls.newTypeParamType("A");
List<String> typeParamAList = singletonList("A");
Assertions.assertThatThrownBy(() -> env.add(Decls.newFunction(Overloads.TypeConvertDyn, Decls.newParameterizedOverload(Overloads.ToDyn, singletonList(paramA), Decls.Dyn, typeParamAList)))).hasMessage("overlapping overload for name 'dyn' (type '(type_param: \"A\") -> dyn' with overloadId: 'to_dyn' cannot be distinguished from '(type_param: \"A\") -> dyn' with overloadId: 'to_dyn')");
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.
the class Checker method checkCreateMap.
void checkCreateMap(Expr.Builder e) {
CreateStruct.Builder mapVal = e.getStructExprBuilder();
Type keyType = null;
Type valueType = null;
for (Entry.Builder ent : mapVal.getEntriesBuilderList()) {
Expr.Builder key = ent.getMapKeyBuilder();
check(key);
keyType = joinTypes(location(key), keyType, getType(key));
Expr.Builder val = ent.getValueBuilder();
check(val);
valueType = joinTypes(location(val), valueType, getType(val));
}
if (keyType == null) {
// If the map is empty, assign free type variables to typeKey and value type.
keyType = newTypeVar();
valueType = newTypeVar();
}
setType(e, Decls.newMapType(keyType, valueType));
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.
the class Checker method checkSelect.
void checkSelect(Expr.Builder e) {
Select.Builder sel = e.getSelectExprBuilder();
// Before traversing down the tree, try to interpret as qualified name.
String qname = Container.toQualifiedName(e.build());
if (qname != null) {
Decl ident = env.lookupIdent(qname);
if (ident != null) {
if (sel.getTestOnly()) {
errors.expressionDoesNotSelectField(location(e));
setType(e, Decls.Bool);
return;
}
// Rewrite the node to be a variable reference to the resolved fully-qualified
// variable name.
setType(e, ident.getIdent().getType());
setReference(e, newIdentReference(ident.getName(), ident.getIdent().getValue()));
String identName = ident.getName();
e.getIdentExprBuilder().setName(identName);
return;
}
}
// Interpret as field selection, first traversing down the operand.
check(sel.getOperandBuilder());
Type targetType = getType(sel.getOperandBuilder());
// Assume error type by default as most types do not support field selection.
Type resultType = Decls.Error;
switch(kindOf(targetType)) {
case kindMap:
// Maps yield their value type as the selection result type.
MapType mapType = targetType.getMapType();
resultType = mapType.getValueType();
break;
case kindObject:
// Objects yield their field type declaration as the selection result type, but only if
// the field is defined.
FieldType fieldType = lookupFieldType(location(e), targetType.getMessageType(), sel.getField());
if (fieldType != null) {
resultType = fieldType.type;
}
break;
case kindTypeParam:
// Set the operand type to DYN to prevent assignment to a potentionally incorrect type
// at a later point in type-checking. The isAssignable call will update the type
// substitutions for the type param under the covers.
isAssignable(Decls.Dyn, targetType);
// Also, set the result type to DYN.
resultType = Decls.Dyn;
break;
default:
// in order to allow forward progress on the check.
if (isDynOrError(targetType)) {
resultType = Decls.Dyn;
} else {
errors.typeDoesNotSupportFieldSelection(location(e), targetType);
}
break;
}
if (sel.getTestOnly()) {
resultType = Decls.Bool;
}
setType(e, resultType);
}
Aggregations