use of com.google.api.expr.v1alpha1.Reference in project dishevelled-bio by heuermh.
the class TraversePaths method call.
@Override
public Integer call() throws Exception {
BufferedReader reader = null;
PrintWriter writer = null;
try {
reader = reader(inputGfa1File);
writer = writer(outputGfa1File);
final PrintWriter w = writer;
Gfa1Reader.stream(reader, new Gfa1Listener() {
@Override
public boolean record(final Gfa1Record gfa1Record) {
Gfa1Writer.write(gfa1Record, w);
if (gfa1Record instanceof Path) {
Path path = (Path) gfa1Record;
int size = path.getSegments().size();
Reference source = null;
Reference target = null;
String overlap = null;
for (int i = 0; i < size; i++) {
target = path.getSegments().get(i);
if (i > 0) {
overlap = (path.getOverlaps() != null && path.getOverlaps().size() > i) ? path.getOverlaps().get(i - 1) : null;
}
if (source != null) {
Traversal traversal = new Traversal(path.getName(), i - 1, source, target, overlap, EMPTY_ANNOTATIONS);
Gfa1Writer.write(traversal, w);
}
source = target;
}
}
return true;
}
});
return 0;
} finally {
try {
reader.close();
} catch (Exception e) {
// ignore
}
try {
writer.close();
} catch (Exception e) {
// ignore
}
}
}
use of com.google.api.expr.v1alpha1.Reference 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);
}
use of com.google.api.expr.v1alpha1.Reference in project cel-java by projectnessie.
the class Checker method resolveOverload.
OverloadResolution resolveOverload(Location loc, Decl fn, Expr.Builder target, List<Expr.Builder> args) {
List<Type> argTypes = new ArrayList<>();
if (target != null) {
Type argType = getType(target);
if (argType == null) {
throw new ErrException("Could not resolve type for target '%s'", target);
}
argTypes.add(argType);
}
for (int i = 0; i < args.size(); i++) {
Expr.Builder arg = args.get(i);
Type argType = getType(arg);
if (argType == null) {
throw new ErrException("Could not resolve type for argument %d '%s'", i, arg);
}
argTypes.add(argType);
}
Type resultType = null;
Reference checkedRef = null;
for (Overload overload : fn.getFunction().getOverloadsList()) {
if ((target == null && overload.getIsInstanceFunction()) || (target != null && !overload.getIsInstanceFunction())) {
// not a compatible call style.
continue;
}
Type overloadType = Decls.newFunctionType(overload.getResultType(), overload.getParamsList());
if (overload.getTypeParamsCount() > 0) {
// Instantiate overload's type with fresh type variables.
Mapping substitutions = newMapping();
for (String typePar : overload.getTypeParamsList()) {
substitutions.add(Decls.newTypeParamType(typePar), newTypeVar());
}
overloadType = substitute(substitutions, overloadType, false);
}
List<Type> candidateArgTypes = overloadType.getFunction().getArgTypesList();
if (isAssignableList(argTypes, candidateArgTypes)) {
if (checkedRef == null) {
checkedRef = newFunctionReference(Collections.singletonList(overload.getOverloadId()));
} else {
checkedRef = checkedRef.toBuilder().addOverloadId(overload.getOverloadId()).build();
}
// First matching overload, determines result type.
Type fnResultType = substitute(mappings, overloadType.getFunction().getResultType(), false);
if (resultType == null) {
resultType = fnResultType;
} else if (!isDyn(resultType) && !fnResultType.equals(resultType)) {
resultType = Decls.Dyn;
}
}
}
if (resultType == null) {
errors.noMatchingOverload(loc, fn.getName(), argTypes, target != null);
// resultType = Decls.Error;
return null;
}
return newResolution(checkedRef, resultType);
}
use of com.google.api.expr.v1alpha1.Reference in project cel-java by projectnessie.
the class CheckerEnv method lookupIdent.
/**
* LookupIdent returns a Decl proto for typeName as an identifier in the Env. Returns nil if no
* such identifier is found in the Env.
*/
public Decl lookupIdent(String name) {
for (String candidate : container.resolveCandidateNames(name)) {
Decl ident = declarations.findIdent(candidate);
if (ident != null) {
return ident;
}
// Next try to import the name as a reference to a message type. If found,
// the declaration is added to the outest (global) scope of the
// environment, so next time we can access it faster.
Type t = provider.findType(candidate);
if (t != null) {
Decl decl = Decls.newVar(candidate, t);
declarations.addIdent(decl);
return decl;
}
// Next try to import this as an enum value by splitting the name in a type prefix and
// the enum inside.
Val enumValue = provider.enumValue(candidate);
if (enumValue.type() != ErrType) {
Decl decl = Decls.newIdent(candidate, Decls.Int, Constant.newBuilder().setInt64Value(enumValue.intValue()).build());
declarations.addIdent(decl);
return decl;
}
}
return null;
}
use of com.google.api.expr.v1alpha1.Reference in project xtext-core by eclipse.
the class Bug311337TestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == Bug311337Package.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case Bug311337Package.CHILD:
sequence_Child(context, (Child) semanticObject);
return;
case Bug311337Package.DEFINITION:
sequence_Definition(context, (Definition) semanticObject);
return;
case Bug311337Package.MODEL:
sequence_Model(context, (Model) semanticObject);
return;
case Bug311337Package.NESTED_REF:
sequence_Reference(context, (NestedRef) semanticObject);
return;
case Bug311337Package.REFERENCE:
sequence_Reference(context, (Reference) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations