• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java NullLiteralNode类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.checkerframework.dataflow.cfg.node.NullLiteralNode的典型用法代码示例。如果您正苦于以下问题:Java NullLiteralNode类的具体用法?Java NullLiteralNode怎么用?Java NullLiteralNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

NullLiteralNode类属于org.checkerframework.dataflow.cfg.node包,在下文中一共展示了NullLiteralNode类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: visitNullLiteral

点赞 2

import org.checkerframework.dataflow.cfg.node.NullLiteralNode; //导入依赖的package包/类
@Override
public final TransferResult<Nullness, LocalStore<Nullness>> visitNullLiteral(
    NullLiteralNode node, TransferInput<Nullness, LocalStore<Nullness>> input) {
  ReadableLocalVariableUpdates updates = new ReadableLocalVariableUpdates();
  Nullness result = visitNullLiteral();
  return updateRegularStore(result, input, updates);
}
 

开发者ID:google,
项目名称:error-prone,
代码行数:8,
代码来源:AbstractNullnessPropagationTransfer.java

示例2: visitAssignment

点赞 2

import org.checkerframework.dataflow.cfg.node.NullLiteralNode; //导入依赖的package包/类
@Override
public TransferResult<AffinePointerValue, AffinePointerStore>
       visitAssignment(AssignmentNode n, TransferInput<AffinePointerValue, AffinePointerStore> in) {
	
	//TODO: Do we want to do anything before looking at this node?
	//We may want to:
	//* Observe that borrowed things are no longer borrowed (since we can't do this elsewhere right now)
	//* Make things into errors, such as assignment to borrowed variable
	
	TransferResult<AffinePointerValue, AffinePointerStore> result = super.visitAssignment(n, in);

	//The type system doesn't prevent assignments to @Unusable things, so we need to stop this explicitly.
	//We need to make sure to do this before we reset BORROWED/SHARED things to their "correct" annotations.
	if (hasAnnotation(result, n.getTarget(), UNUSABLE) && hasAnnotation(result, n.getExpression(), UNUSABLE)) {
		checker.report(Result.failure("cannot.assign.to.unusable",n.getExpression()), n.getExpression().getTree());
	}
	
	//Prevent Checker from being too "helpful" and changing the types of @Shared or @Borrowed values.
	//We will still use hasAnnotationWithoutFlow to be completely sure we get the right answers
	//for the borrow analysis, but this should help improve subtyping errors.
	
	if (hasAnnotationWithoutFlow(n.getTarget(), BORROWED)) {
		changeAnnotation(result, n.getTarget(), BORROWED);
	} else if (hasAnnotationWithoutFlow(n.getTarget(), SHARED)) {
		changeAnnotation(result, n.getTarget(), SHARED);
	}
	
	//Prevent Checker from being too "helpful" as usual...
	if (hasAnnotation(result, n.getTarget(), BOTTOM)) {
		if (hasAnnotationWithoutFlow(n.getTarget(), AFFINE)) {
			changeAnnotation(result, n.getTarget(), AFFINE);
		} else if (hasAnnotationWithoutFlow(n.getTarget(), NONAFFINE)) {
			changeAnnotation(result, n.getTarget(), NONAFFINE);
		}
	}
	
	//Update borrows if LHS is a borrow. Otherwise make sure the RHS is not currently borrowed.
	if (hasAnnotationWithoutFlow(n.getTarget(), BORROWED) || hasAnnotationWithoutFlow(n.getTarget(), SHARED)) {
		if (n.getExpression() instanceof LocalVariableNode) {
			if (!LifetimePoset.compareLT(getVariableLifetime(n.getTarget()), getVariableLifetime(n.getExpression()))) {
				checker.report(Result.failure("bad.lifetime.relationship", n.getTarget(), n.getExpression()), n.getTree());
			}
			
			boolean mutableBorrow = hasAnnotationWithoutFlow(n.getTarget(), BORROWED);
						
			if (hasAnnotationWithoutFlow(n.getExpression(), SHARED)) {
				//This should only happen if n.getTarget() is also SHARED.
				if (mutableBorrow) {
					checker.report(Result.failure("cannot.borrow.shared.with.borrowed", n.getTarget(), n.getExpression()), n.getExpression().getTree());
				} else if (!borrowTracker.addBorrowToShared(elementOf(n.getExpression()), elementOf(n.getTarget()))) {
					System.out.println(n + " This should never print and is a bug with the checker.");
				}
			} else {
				if (!borrowTracker.addBorrowToNonShared(
						elementOf(n.getExpression()),
						elementOf(n.getTarget()),
						mutableBorrow)) {
					checker.report(Result.failure(mutableBorrow ? "cannot.borrow.borrowed" : "cannot.share.borrowed", n.getExpression()),
							n.getExpression().getTree());
				}
			}
		} else if (n.getExpression() instanceof NullLiteralNode) {
			borrowTracker.removeBorrow(elementOf(n.getTarget()));
		} else {
			checker.report(Result.failure("unrecognized.borrow.target", n.getTarget(), n.getExpression()), n.getExpression().getTree());
		}
	} else {
		//The LHS was not a borrow. The RHS should not be borrowed, since if it is then it's unusable right now.
		if (borrowTracker.isBorrowed(elementOf(n.getExpression()))) {
			checker.report(Result.failure("use.of.borrowed.variable", n.getExpression()), n.getExpression().getTree());
			
			//Invalidate RHS if it has type @Affine
		} else if (n.getExpression() instanceof LocalVariableNode || n.getExpression() instanceof FieldAccessNode) {
			if (hasAnnotation(result, n.getExpression(), AFFINE)) {
				changeAnnotation(result, n.getExpression(), UNUSABLE);
			}
		}
	}
	
	return result;
}
 

开发者ID:PPewt,
项目名称:affinechecker,
代码行数:82,
代码来源:AffinePointerTransfer.java

示例3: visitNullLiteral

点赞 2

import org.checkerframework.dataflow.cfg.node.NullLiteralNode; //导入依赖的package包/类
@Override
public TransferResult<Nullness, NullnessStore<Nullness>> visitNullLiteral(
    NullLiteralNode nullLiteralNode, TransferInput<Nullness, NullnessStore<Nullness>> input) {
  // let's be sane here and return null
  return new RegularTransferResult<>(Nullness.NULL, input.getRegularStore());
}
 

开发者ID:uber,
项目名称:NullAway,
代码行数:7,
代码来源:AccessPathNullnessPropagation.java

示例4: strengthenAnnotationOfEqualTo

点赞 2

import org.checkerframework.dataflow.cfg.node.NullLiteralNode; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>
 * Furthermore, this method refines the type to {@code NonNull} for the
 * appropriate branch if an expression is compared to the {@code null}
 * literal (listed as case 1 in the class description).
 */
@Override
protected TransferResult<NullnessValue, NullnessStore> strengthenAnnotationOfEqualTo(
        TransferResult<NullnessValue, NullnessStore> res, Node firstNode,
        Node secondNode, NullnessValue firstValue, NullnessValue secondValue,
        boolean notEqualTo) {
    res = super.strengthenAnnotationOfEqualTo(res, firstNode, secondNode,
            firstValue, secondValue, notEqualTo);
    if (firstNode instanceof NullLiteralNode) {
        NullnessStore thenStore = res.getThenStore();
        NullnessStore elseStore = res.getElseStore();

        List<Node> secondParts = splitAssignments(secondNode);
        for (Node secondPart : secondParts) {
            Receiver secondInternal = FlowExpressions.internalReprOf(
                    analysis.getTypeFactory(), secondPart);
            if (CFAbstractStore.canInsertReceiver(secondInternal)) {
                thenStore = thenStore == null ? res.getThenStore()
                        : thenStore;
                elseStore = elseStore == null ? res.getElseStore()
                        : elseStore;
                if (notEqualTo) {
                    thenStore.insertValue(secondInternal, NONNULL);
                } else {
                    elseStore.insertValue(secondInternal, NONNULL);
                }
            }
        }

        if (secondValue != null
                && (secondValue.getType().hasAnnotation(PolyNull.class) || secondValue
                        .getType().hasAnnotation(PolyAll.class))) {
            thenStore = thenStore == null ? res.getThenStore() : thenStore;
            elseStore = elseStore == null ? res.getElseStore() : elseStore;
            thenStore.setPolyNullNull(true);
        }

        if (thenStore != null) {
            return new ConditionalTransferResult<>(res.getResultValue(),
                    thenStore, elseStore);
        }
    }
    return res;
}
 

开发者ID:reprogrammer,
项目名称:checker-framework,
代码行数:52,
代码来源:NullnessTransfer.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)