public OperatorInfo(int tokenType, OperatorKind kind, int precedence, bool isBuiltIn) { TokenType = tokenType; Kind = kind; Precedence = precedence; IsBuiltIn = isBuiltIn; }
public ShiftExpression(uint start, uint end, OperatorKind kind, ExpressionNode left, Token op, ExpressionNode right) : base(start, end) { ShiftOperator = kind; Left = left; Operator = op; Right = right; }
private static ExprBinaryOperator ProcessPredicateWithFullPath(Match match) { string fullPath = match.Groups["fullPath"].Value; if (string.IsNullOrEmpty(fullPath)) { throw new ApplicationException("fullPath must not be null or empty."); } PathExpr pathExpr = ToPathExpr(fullPath); string standardExprOperator = match.Groups["predicate_path_operator"].Value; OperatorKind operatorKind = new OperatorKind(OperatorKind.GetOperatorKind(standardExprOperator)); string predicateCriteria = match.Groups["predicate_criteria"].Value; if (string.IsNullOrEmpty(predicateCriteria)) { throw new ApplicationException("predicateCriteria must not be null or empty."); } object criteriaValue = null; string type = GetCriteriaType(match, out criteriaValue); ExprLeaf rightOperand = new ExprLeaf(criteriaValue, type, "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(pathExpr, rightOperand, type, operatorKind, false); return(binaryOperator); }
public OperatorDefinition(int precedence, bool leftToRight, OperatorKind kind, ExpressionCreatorInfix handler) { this.precedence = precedence; this.leftToRight = leftToRight; this.kind = kind; this.handler = handler; }
private static ExprBinaryOperator ProcessStandardPredicateExpr(Match match) { string standardExpr = match.Groups["predicate_expre"].Value; if (string.IsNullOrEmpty(standardExpr)) { throw new ApplicationException("standardExpr must not be null or empty."); } string path = match.Groups["predicate_path"].Value; if (string.IsNullOrEmpty(path)) { throw new ApplicationException("predicate_path must not be null or empty"); } ExprLeaf lefOperand = new ExprLeaf(path, "String", "Path"); string standardExprOperator = match.Groups["predicate_path_operator"].Value; OperatorKind operatorKind = new OperatorKind(OperatorKind.GetOperatorKind(standardExprOperator)); // default value object criteriaValue = null; string type = GetCriteriaType(match, out criteriaValue); ExprLeaf rightOperand = new ExprLeaf(criteriaValue, type, "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(lefOperand, rightOperand, type, operatorKind, false); return(binaryOperator); }
public void AddOperator(ParserToken token, OperatorKind kind) { string op = ExpressionPrecedence.operatorName(kind, token.Keyword); if (!precedence.precedence.ContainsKey(op)) throw new Exception("Unknown operator: "+op); list.Add(new Opera_nd_tor(precedence.precedence[op], token)); }
public OperatorInfo(char literal, OperatorKind kind, int precedence, bool isBuiltIn) { Literal = literal; Kind = kind; Precedence = precedence; IsBuiltIn = isBuiltIn; }
public AugAssignStatement(uint start, uint end, OperatorKind kind, ExpressionNode left, Token op, ExpressionNode right) : base(start, end) { Kind = kind; Left = left; Operator = op; Right = right; }
private static ExprBinaryOperator ProcessMatchesExpr(Match match) { string matches = match.Groups["matchesExpr"].Value; if (string.IsNullOrEmpty(matches)) { throw new ApplicationException("matches must not be null or empty."); } string leftPath = match.Groups["predicate_path"].Value; ExprLeaf leftOperand = null; if (string.IsNullOrEmpty(leftPath)) { leftOperand = new ExprLeaf("/archetype_node_id", "String", "path"); } else { leftOperand = new ExprLeaf(leftPath, "String", "path"); } OperatorKind operatorKind = new OperatorKind(OperatorKind.op_matches); string pattern = match.Groups["regex_pattern"].Value; if (string.IsNullOrEmpty(pattern)) { throw new ApplicationException("pattern must not be null or empty."); } ExprLeaf rightOperand = new ExprLeaf(pattern, "String", "pattern"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, rightOperand.Type, operatorKind, false); return(binaryOperator); }
private static OperatorSymbol StringBinary(OperatorKind kind) => new OperatorSymbol(kind, new Signature(ScalarTypes.Bool, new Parameter("left", ParameterTypeKind.StringOrDynamic), new Parameter("right", ScalarTypes.String)), new Signature(ScalarTypes.Bool, new Parameter("left", ParameterTypeKind.StringOrDynamic, ArgumentKind.Star), new Parameter("right", ScalarTypes.String)));
// Constructor for raise statement public FlowStatement(uint start, uint end, OperatorKind kind, Token op, ExpressionNode left, Token op2, ExpressionNode right) : base(start, end) { Kind = kind; Operator = op; Left = left; Operator2 = op2; Right = right; }
/// <summary>Attempts to add a new user defined operator</summary> /// <param name="token">Symbol for the operator</param> /// <param name="kind"><see cref="OperatorKind"/> value to define the behavior of the operator</param> /// <param name="precedence">precedence level for the operator</param> /// <returns><see langword="true"/> if the operator was added and <see langword="false"/> if not</returns> /// <remarks> /// This can add or replace user defined operators, however attempts to replace a built-in operator /// will not replace the operator and will simply return <see langword="false"/>. /// </remarks> public bool TryAddOperator(string token, OperatorKind kind, int precedence) { if (!Lexer.TokenTypeMap.TryGetValue(token, out int tokenType)) { return(false); } return(TryAddOperator(tokenType, kind, precedence)); }
public OperatorToken(string op) { this.id = TokenKind.OPERATOR; int index = Array.IndexOf(OperatorTable, op); System.Diagnostics.Debug.Assert(index >= 0); this.op = (OperatorKind)index; }
public BinaryExpression(Scope parentScope, OperatorKind op, Expression leftSide, Expression rightSide) : base(parentScope) { if (op == OperatorKind.Unknown) { throw new CompilerException("implementation failure"); } this.op = op; this.left = leftSide; this.right = rightSide; }
public OperatorSymbol(OperatorKind kind, IEnumerable <Signature> signatures) : base(kind.ToString()) { this.OperatorKind = kind; this.Signatures = signatures.ToReadOnly(); foreach (var signature in this.Signatures) { signature.Symbol = this; } }
/// <summary> /// Gets the built-in operator symbol for the corresponding argument types. /// </summary> public OperatorSymbol GetOperator(OperatorKind kind) { if (this.operatorMap == null) { this.operatorMap = this.Operators.ToDictionary(o => o.OperatorKind); } if (this.operatorMap.TryGetValue(kind, out var op)) { return(op); } return(null); }
public static OperatorKind OperatorOfMethodName(Name name) { Debug.Assert(name != null); for (OperatorKind i = OperatorKind.OP_NONE; i < OperatorKind.OP_LAST; i = (i + 1)) { if (HasMethodName(i) && (name == NameManager.GetPredefinedName(GetMethodName(i)))) { return(i); } } return(OperatorKind.OP_NONE); }
/// <summary> /// Determines whether the specified method is an operator overload and saves the operator kind into the <paramref name="operatorKind"/> out parameter. /// </summary> /// <seealso cref="OperatorKind"/> public static bool IsOperator(this MethodReference methodReference, out OperatorKind operatorKind) { var kind = methodReference.GetOperatorKind(); if (kind.HasValue) { operatorKind = kind.Value; return(true); } else { operatorKind = (OperatorKind)(-1); return(false); } }
internal static string operatorName(OperatorKind kind, string name) { switch (kind) { case OperatorKind.Prefix: return name + "_prefix"; case OperatorKind.Infix: return name + "_infix"; case OperatorKind.Postfix: return name + "_postfix"; default: { Require.NotCalled(); return null; } } }
private static ExprBinaryOperator ProcessBoolExpr(Match match) { string boolExprString = match.Groups["genericExpr"].Value; if (string.IsNullOrEmpty(boolExprString)) { throw new ApplicationException("boolExprString must not be null or empty."); } ExprBinaryOperator boolExpr = null; string leftOperandString = match.Groups["leftSimpleExpr"].Value; if (string.IsNullOrEmpty(leftOperandString)) { throw new ApplicationException("leftOperandString must not be null or empty."); } ExprOperator leftOperand = ToExprOperator(leftOperandString); do { if (boolExpr != null) { leftOperand = boolExpr; } string boolOperatorStr = match.Groups["predicate_bool_operator"].Value; OperatorKind boolOperator = new OperatorKind(OperatorKind.GetOperatorKind(boolOperatorStr)); string rightOperandStr = match.Groups["rightSimpleExpr"].Value; if (string.IsNullOrEmpty(rightOperandStr)) { throw new ApplicationException("rightOperandStr must not be null or empty."); } ExprOperator rightOperand = ToExprOperator(rightOperandStr); boolExpr = new ExprBinaryOperator(leftOperand, rightOperand, "Boolean", boolOperator, false); match = match.NextMatch(); } while (match.Success); DesignByContract.Check.Ensure(boolExpr != null, "boolExpr must not be null."); return(boolExpr); }
/// <summary> /// Creates a declaration for a comparison operator overload. /// </summary> /// <param name="generator"> /// The <see cref="SyntaxGenerator"/> used to create the declaration. /// </param> /// <param name="operatorKind"> /// A value specifying which operator overload is to be declared. Must be one of /// Equality, Inequality, GreaterThan, GreaterThanOrEqual, LessThan, or LessThanOrEqual. /// </param> /// <param name="containingType"> /// A symbol specifying the type of the operands of the comparison operator. /// </param> /// <returns> /// A <see cref="SyntaxNode"/> representing the declaration. /// </returns> /// <remarks> /// A comparison operator is a public, static (Shared in VB) method with two operands, /// each of the containing type, and a return type of bool (Boolean in VB). /// </remarks> public static SyntaxNode ComparisonOperatorDeclaration(this SyntaxGenerator generator, OperatorKind operatorKind, INamedTypeSymbol containingType) { if (!s_comparisonOperators.Contains(operatorKind)) { throw new ArgumentException($"{operatorKind} is not a comparison operator", nameof(operatorKind)); } return generator.OperatorDeclaration( operatorKind, new SyntaxNode[] { generator.ParameterDeclaration("left", generator.TypeExpression(containingType)), generator.ParameterDeclaration("right", generator.TypeExpression(containingType)), }, generator.TypeExpression(SpecialType.System_Boolean), Accessibility.Public, DeclarationModifiers.Static, generator.DefaultMethodBody()); }
private static Parser slice <T>(OperatorKind kind, OperatorTable <T> .Operator[] ops, int begin, int end) { if (kind == OperatorKind.PREFIX || kind == OperatorKind.POSTFIX) { Parser <Map <T, T> >[] ps = new Parser <Map <T, T> > [end - begin]; for (int i = 0; i < ps.Length; i++) { ps[i] = ops[i + begin].Op as Parser <Map <T, T> >; } return(Parsers.Plus(ps)); } else { Parser <Map <T, T, T> >[] ps = new Parser <Map <T, T, T> > [end - begin]; for (int i = 0; i < ps.Length; i++) { ps[i] = ops[i + begin].Op as Parser <Map <T, T, T> >; } return(Parsers.Plus(ps)); } }
/// <summary> /// Creates a declaration for a comparison operator overload. /// </summary> /// <param name="generator"> /// The <see cref="SyntaxGenerator"/> used to create the declaration. /// </param> /// <param name="operatorKind"> /// A value specifying which operator overload is to be declared. Must be one of /// Equality, Inequality, GreaterThan, GreaterThanOrEqual, LessThan, or LessThanOrEqual. /// </param> /// <param name="containingType"> /// A symbol specifying the type of the operands of the comparison operator. /// </param> /// <param name="compilation">The compilation</param> /// <returns> /// A <see cref="SyntaxNode"/> representing the declaration. /// </returns> /// <remarks> /// A comparison operator is a public, static (Shared in VB) method with two operands, /// each of the containing type, and a return type of bool (Boolean in VB). /// </remarks> public static SyntaxNode ComparisonOperatorDeclaration( this SyntaxGenerator generator, OperatorKind operatorKind, INamedTypeSymbol containingType, Compilation compilation) { if (!s_comparisonOperators.Contains(operatorKind)) { throw new ArgumentException($"{operatorKind} is not a comparison operator", nameof(operatorKind)); } return(generator.OperatorDeclaration( operatorKind, new[] { generator.ParameterDeclaration("left", generator.TypeExpression(containingType)), generator.ParameterDeclaration("right", generator.TypeExpression(containingType)), }, generator.TypeExpression(SpecialType.System_Boolean), Accessibility.Public, DeclarationModifiers.Static, generator.DefaultMethodBody(compilation))); }
/// <summary> Creates a Parser object based on information described by OperatorTable.</summary> /// <param name="term">parser for the terminals. /// </param> /// <param name="table">the operator table. /// </param> /// <returns> the expression parser. /// </returns> public static Parser <T> BuildExpressionParser <T>(Parser <T> term, OperatorTable <T> table) { OperatorTable <T> .Operator[] ops = table.Operators; if (ops.Length == 0) { return(term); } int begin = 0; int prec = ops[0].Precedence; OperatorKind kind = ops[0].Kind; int end = 0; Parser <T> ret = term; for (int i = 1; i < ops.Length; i++) { OperatorTable <T> .Operator op = ops[i]; end = i; if (op.Precedence == prec && op.Kind == kind) { continue; } else { end = i; Parser p = slice <T>(kind, ops, begin, end); ret = build(p, kind, ret); begin = i; prec = ops[i].Precedence; kind = ops[i].Kind; } } if (end != ops.Length) { end = ops.Length; kind = ops[begin].Kind; Parser p = slice <T>(kind, ops, begin, end); ret = build(p, kind, ret); } return(ret); }
private static Parser <T> build <T>(Parser op, OperatorKind kind, Parser <T> operand) { switch (kind) { case OperatorKind.PREFIX: return(Parsers.Prefix(op as Parser <Map <T, T> >, operand)); case OperatorKind.POSTFIX: return(Parsers.Postfix(operand, op as Parser <Map <T, T> >)); case OperatorKind.LASSOC: return(Parsers.Infixl(op as Parser <Map <T, T, T> >, operand)); case OperatorKind.RASSOC: return(Parsers.Infixr(op as Parser <Map <T, T, T> >, operand)); case OperatorKind.NASSOC: return(Parsers.Infixn(op as Parser <Map <T, T, T> >, operand)); default: return(operand); } }
private static OPINFO GetInfo(OperatorKind op) { //Debug.Assert(IsValid(op)); return s_rgOpInfo[op]; }
public static ExpressionKind GetExpressionKind(OperatorKind op) { //Debug.Assert(IsValid(op)); return(GetInfo(op).expressionKind); }
public EXPR BindStandardUnaryOperator(OperatorKind op, EXPR pArgument) { RETAILVERIFY(pArgument != null); ExpressionKind ek; UnaOpKind unaryOpKind; EXPRFLAG flags; if (pArgument.type == null || !CalculateExprAndUnaryOpKinds( op, Context.CheckedNormal, out ek/*out*/, out unaryOpKind/*out*/, out flags/*out*/)) { return BadOperatorTypesError(ExpressionKind.EK_UNARYOP, pArgument, null); } UnaOpMask unaryOpMask = (UnaOpMask)(1 << (int)unaryOpKind); CType type = pArgument.type; List<UnaOpFullSig> pSignatures = new List<UnaOpFullSig>(); EXPR pResult = null; UnaryOperatorSignatureFindResult eResultOfSignatureFind = PopulateSignatureList(pArgument, unaryOpKind, unaryOpMask, ek, flags, pSignatures, out pResult); // nBestSignature is a 0-based index. int nBestSignature = pSignatures.Count - 1; if (eResultOfSignatureFind == UnaryOperatorSignatureFindResult.Return) { Debug.Assert(pResult != null); return pResult; } else if (eResultOfSignatureFind != UnaryOperatorSignatureFindResult.Match) { // If we didn't find a best match while populating, try to find while doing // applicability testing. if (!FindApplicableSignatures( pArgument, unaryOpMask, pSignatures)) { if (pSignatures.Count == 0) { return BadOperatorTypesError(ek, pArgument, null); } nBestSignature = 0; // If we couldn't find exactly one, then we need to do some betterness testing. if (pSignatures.Count != 1) { // Determine which is best. for (int iuofs = 1; iuofs < pSignatures.Count; iuofs++) { if (nBestSignature < 0) { nBestSignature = iuofs; } else { int nT = WhichUofsIsBetter(pSignatures[nBestSignature], pSignatures[iuofs], type); if (nT == 0) { nBestSignature = -1; } else if (nT > 0) { nBestSignature = iuofs; } } } if (nBestSignature < 0) { // Ambiguous. return ambiguousOperatorError(ek, pArgument, null); } // Verify that our answer works. for (int iuofs = 0; iuofs < pSignatures.Count; iuofs++) { if (iuofs == nBestSignature) { continue; } if (WhichUofsIsBetter(pSignatures[nBestSignature], pSignatures[iuofs], type) >= 0) { return ambiguousOperatorError(ek, pArgument, null); } } } } else { nBestSignature = pSignatures.Count - 1; } } RETAILVERIFY(nBestSignature < pSignatures.Count); UnaOpFullSig uofs = pSignatures[nBestSignature]; if (uofs.pfn == null) { if (unaryOpKind == UnaOpKind.IncDec) { return BindIncOp(ek, flags, pArgument, uofs); } return BadOperatorTypesError(ek, pArgument, null); } if (uofs.isLifted()) { return BindLiftedStandardUnop(ek, flags, pArgument, uofs); } // Try the conversion - if it fails, do a cast without user defined casts. EXPR arg = tryConvert(pArgument, uofs.GetType()); if (arg == null) { arg = mustCast(pArgument, uofs.GetType(), CONVERTTYPE.NOUDC); } return uofs.pfn(ek, flags, arg); }
///////////////////////////////////////////////////////////////////////////////// // Bind a standard unary operator. Takes care of user defined operators, predefined operators // and lifting over nullable. private static bool CalculateExprAndUnaryOpKinds( OperatorKind op, bool bChecked, out /*out*/ ExpressionKind ek, out /*out*/ UnaOpKind uok, out /*out*/ EXPRFLAG flags) { flags = 0; ek = 0; uok = 0; switch (op) { case OperatorKind.OP_UPLUS: uok = UnaOpKind.Plus; ek = ExpressionKind.EK_UPLUS; break; case OperatorKind.OP_NEG: if (bChecked) { flags |= EXPRFLAG.EXF_CHECKOVERFLOW; } uok = UnaOpKind.Minus; ek = ExpressionKind.EK_NEG; break; case OperatorKind.OP_BITNOT: uok = UnaOpKind.Tilde; ek = ExpressionKind.EK_BITNOT; break; case OperatorKind.OP_LOGNOT: uok = UnaOpKind.Bang; ek = ExpressionKind.EK_LOGNOT; break; case OperatorKind.OP_POSTINC: flags |= EXPRFLAG.EXF_ISPOSTOP; if (bChecked) { flags |= EXPRFLAG.EXF_CHECKOVERFLOW; } uok = UnaOpKind.IncDec; ek = ExpressionKind.EK_ADD; break; case OperatorKind.OP_PREINC: if (bChecked) { flags |= EXPRFLAG.EXF_CHECKOVERFLOW; } uok = UnaOpKind.IncDec; ek = ExpressionKind.EK_ADD; break; case OperatorKind.OP_POSTDEC: flags |= EXPRFLAG.EXF_ISPOSTOP; if (bChecked) { flags |= EXPRFLAG.EXF_CHECKOVERFLOW; } uok = UnaOpKind.IncDec; ek = ExpressionKind.EK_SUB; break; case OperatorKind.OP_PREDEC: if (bChecked) { flags |= EXPRFLAG.EXF_CHECKOVERFLOW; } uok = UnaOpKind.IncDec; ek = ExpressionKind.EK_SUB; break; default: VSFAIL("Bad op"); return false; } return true; }
private static bool HasMethodName(OperatorKind op) { //Debug.Assert(IsValid(op)); return(GetMethodName(op) != PredefinedName.PN_COUNT); }
public static bool HasDisplayName(OperatorKind op) { //Debug.Assert(IsValid(op)); return(GetInfo(op).iToken != TokenKind.Unknown); }
public static ExpressionKind GetExpressionKind(OperatorKind op) { //Debug.Assert(IsValid(op)); return GetInfo(op).expressionKind; }
public static string GetDisplayName(OperatorKind op) { Debug.Assert(HasDisplayName(op)); return TokenFacts.GetText(GetInfo(op).iToken); }
public static bool HasDisplayName(OperatorKind op) { //Debug.Assert(IsValid(op)); return GetInfo(op).iToken != TokenKind.Unknown; }
public static Name GetMethodName(NameManager namemgr, OperatorKind op) { Debug.Assert(HasMethodName(op)); return namemgr.GetPredefName(GetMethodName(op)); }
public static PredefinedName GetMethodName(OperatorKind op) { //Debug.Assert(IsValid(op)); return GetInfo(op).methodName; }
private static PredefinedName GetMethodName(OperatorKind op) { //Debug.Assert(IsValid(op)); return(GetInfo(op).methodName); }
private static SyntaxNode ComparisonOperatorDeclaration(this SyntaxGenerator generator, OperatorKind operatorKind, INamedTypeSymbol containingType, params SyntaxNode[] statements) { return generator.OperatorDeclaration( operatorKind, new[] { generator.ParameterDeclaration(LeftIdentifierName, generator.TypeExpression(containingType)), generator.ParameterDeclaration(RightIdentifierName, generator.TypeExpression(containingType)) }, generator.TypeExpression(SpecialType.System_Boolean), Accessibility.Public, DeclarationModifiers.Static, statements); }
public static string GetDisplayName(OperatorKind op) { Debug.Assert(HasDisplayName(op)); return(TokenFacts.GetText(GetInfo(op).iToken)); }
public TotemOperatorAttribute(OperatorKind kind) { _op = kind; }
private static OPINFO GetInfo(OperatorKind op) { //Debug.Assert(IsValid(op)); return(s_rgOpInfo[op]); }
public static bool HasMethodName(OperatorKind op) { //Debug.Assert(IsValid(op)); return GetMethodName(op) != PredefinedName.PN_COUNT; }