Пример #1
0
// generateNullComparisonOperator generates the expression for a null comparison operator.
func (eg *expressionGenerator) generateNullComparisonOperator(compareOp *codedom.BinaryOperationNode, context generationContext) esbuilder.ExpressionBuilder {
	return eg.generateShortCircuiter(
		compareOp.LeftExpr,
		codedom.LiteralValue("null", compareOp.BasisNode()),
		compareOp.RightExpr,
		context,

		func(resultName string, rightSide esbuilder.ExpressionBuilder) esbuilder.ExpressionBuilder {
			return esbuilder.Call(esbuilder.Snippet(string(codedom.NullableComparisonFunction)), esbuilder.Identifier(resultName), rightSide)
		})
}
Пример #2
0
// generateShortCircuitedBinaryOperator generates the expression source for a short circuiting binary operator.
func (eg *expressionGenerator) generateShortCircuitedBinaryOperator(binaryOp *codedom.BinaryOperationNode, context generationContext) esbuilder.ExpressionBuilder {
	compareValue := codedom.LiteralValue("false", binaryOp.BasisNode())
	if binaryOp.Operator == "&&" {
		compareValue = codedom.LiteralValue("true", binaryOp.BasisNode())
	}

	return eg.generateShortCircuiter(
		binaryOp.LeftExpr,
		compareValue,
		binaryOp.RightExpr,
		context,

		func(resultName string, rightSide esbuilder.ExpressionBuilder) esbuilder.ExpressionBuilder {
			return esbuilder.Binary(esbuilder.Identifier(resultName), binaryOp.Operator, rightSide)
		})
}