Improve pkg/compiler/ast/ cyclomatic complexity
Part of pulumi/lumi#259.
This commit is contained in:
parent
9179d58eb1
commit
d1182dc54f
|
@ -303,14 +303,30 @@ const (
|
||||||
OpMinusMinus UnaryOperator = "--"
|
OpMinusMinus UnaryOperator = "--"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsPrefixUnaryOperator(op UnaryOperator) bool {
|
// PrefixUnaryOperators is a set containing all of the prefix unary operators.
|
||||||
return op == OpDereference || op == OpAddressof ||
|
var PrefixUnaryOperators = map[UnaryOperator]bool{
|
||||||
op == OpUnaryPlus || op == OpUnaryMinus ||
|
OpDereference: true,
|
||||||
op == OpLogicalNot || op == OpBitwiseNot
|
OpAddressof: true,
|
||||||
|
OpUnaryPlus: true,
|
||||||
|
OpUnaryMinus: true,
|
||||||
|
OpLogicalNot: true,
|
||||||
|
OpBitwiseNot: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPrefixUnaryOperator returns true if the given unary operator is a unary operator.
|
||||||
|
func IsPrefixUnaryOperator(op UnaryOperator) bool {
|
||||||
|
return PrefixUnaryOperators[op]
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrePostfixUnaryOperators is a set containing all of the unary operators that may be either pre- or postfix.
|
||||||
|
var PrePostfixUnaryOperators = map[UnaryOperator]bool{
|
||||||
|
OpPlusPlus: true,
|
||||||
|
OpMinusMinus: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPreOrPostfixUnaryOperator returns true if the given unary operator may be either pre- or postfix.
|
||||||
func IsPreOrPostfixUnaryOperator(op UnaryOperator) bool {
|
func IsPreOrPostfixUnaryOperator(op UnaryOperator) bool {
|
||||||
return op == OpPlusPlus || op == OpMinusMinus
|
return PrePostfixUnaryOperators[op]
|
||||||
}
|
}
|
||||||
|
|
||||||
// BinaryOperatorExpression is the usual C-like binary operator (assignment, logical, operator, or relational).
|
// BinaryOperatorExpression is the usual C-like binary operator (assignment, logical, operator, or relational).
|
||||||
|
@ -377,33 +393,80 @@ const (
|
||||||
OpNotEquals BinaryOperator = "!="
|
OpNotEquals BinaryOperator = "!="
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ArithmeticBinaryOperators is a set containing all of the arithmetic binary operators.
|
||||||
|
var ArithmeticBinaryOperators = map[BinaryOperator]bool{
|
||||||
|
OpAdd: true,
|
||||||
|
OpSubtract: true,
|
||||||
|
OpMultiply: true,
|
||||||
|
OpDivide: true,
|
||||||
|
OpRemainder: true,
|
||||||
|
OpExponentiate: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsArithmeticBinaryOperator returns true if the given binary operator is an arithmetic operator.
|
||||||
func IsArithmeticBinaryOperator(op BinaryOperator) bool {
|
func IsArithmeticBinaryOperator(op BinaryOperator) bool {
|
||||||
return op == OpAdd || op == OpSubtract ||
|
return ArithmeticBinaryOperators[op]
|
||||||
op == OpMultiply || op == OpDivide ||
|
|
||||||
op == OpRemainder || op == OpExponentiate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BitwiseBinaryOperators is a set containing all of the bitwise binary operators.
|
||||||
|
var BitwiseBinaryOperators = map[BinaryOperator]bool{
|
||||||
|
OpBitwiseShiftLeft: true,
|
||||||
|
OpBitwiseShiftRight: true,
|
||||||
|
OpBitwiseAnd: true,
|
||||||
|
OpBitwiseOr: true,
|
||||||
|
OpBitwiseXor: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBitwiseBinaryOperator returns true if the given binary operator is a bitwise operator.
|
||||||
func IsBitwiseBinaryOperator(op BinaryOperator) bool {
|
func IsBitwiseBinaryOperator(op BinaryOperator) bool {
|
||||||
return op == OpBitwiseShiftLeft || op == OpBitwiseShiftRight ||
|
return BitwiseBinaryOperators[op]
|
||||||
op == OpBitwiseAnd || op == OpBitwiseOr || op == OpBitwiseXor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssignmentBinaryOperators is a set containing all of the assignment binary operators.
|
||||||
|
var AssignmentBinaryOperators = map[BinaryOperator]bool{
|
||||||
|
OpAssign: true,
|
||||||
|
OpAssignSum: true,
|
||||||
|
OpAssignDifference: true,
|
||||||
|
OpAssignProduct: true,
|
||||||
|
OpAssignQuotient: true,
|
||||||
|
OpAssignRemainder: true,
|
||||||
|
OpAssignExponentiation: true,
|
||||||
|
OpAssignBitwiseShiftLeft: true,
|
||||||
|
OpAssignBitwiseShiftRight: true,
|
||||||
|
OpAssignBitwiseAnd: true,
|
||||||
|
OpAssignBitwiseOr: true,
|
||||||
|
OpAssignBitwiseXor: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAssignmentBinaryOperator returns true if the given binary operator is an assignment operator.
|
||||||
func IsAssignmentBinaryOperator(op BinaryOperator) bool {
|
func IsAssignmentBinaryOperator(op BinaryOperator) bool {
|
||||||
return op == OpAssign || op == OpAssignSum ||
|
return AssignmentBinaryOperators[op]
|
||||||
op == OpAssignDifference || op == OpAssignProduct ||
|
|
||||||
op == OpAssignQuotient || op == OpAssignRemainder || op == OpAssignExponentiation ||
|
|
||||||
op == OpAssignBitwiseShiftLeft || op == OpAssignBitwiseShiftRight ||
|
|
||||||
op == OpAssignBitwiseAnd || op == OpAssignBitwiseOr || op == OpAssignBitwiseXor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConditionalBinaryOperators is a set containing all of the conditional binary operators.
|
||||||
|
var ConditionalBinaryOperators = map[BinaryOperator]bool{
|
||||||
|
OpLogicalAnd: true,
|
||||||
|
OpLogicalOr: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConditionalBinaryOperator returns true if the given binary operator is a conditional operator.
|
||||||
func IsConditionalBinaryOperator(op BinaryOperator) bool {
|
func IsConditionalBinaryOperator(op BinaryOperator) bool {
|
||||||
return op == OpLogicalAnd || op == OpLogicalOr
|
return ConditionalBinaryOperators[op]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RelationalBinaryOperators is a set containing all of the relational binary operators.
|
||||||
|
var RelationalBinaryOperators = map[BinaryOperator]bool{
|
||||||
|
OpLt: true,
|
||||||
|
OpLtEquals: true,
|
||||||
|
OpGt: true,
|
||||||
|
OpGtEquals: true,
|
||||||
|
OpEquals: true,
|
||||||
|
OpNotEquals: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsRelationalBinaryOperator returns true if the given binary operator is a relational operator.
|
||||||
func IsRelationalBinaryOperator(op BinaryOperator) bool {
|
func IsRelationalBinaryOperator(op BinaryOperator) bool {
|
||||||
return op == OpLt || op == OpLtEquals ||
|
return RelationalBinaryOperators[op]
|
||||||
op == OpGt || op == OpGtEquals ||
|
|
||||||
op == OpEquals || op == OpNotEquals
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Type Testing */
|
/* Type Testing */
|
||||||
|
|
Loading…
Reference in a new issue