本文整理汇总了C#中ExpressionPrecedence类的典型用法代码示例。如果您正苦于以下问题:C# ExpressionPrecedence类的具体用法?C# ExpressionPrecedence怎么用?C# ExpressionPrecedence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionPrecedence类属于命名空间,在下文中一共展示了ExpressionPrecedence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOperatorRightHandExpression
private Expression GetOperatorRightHandExpression(ExpressionPrecedence precedence, bool unsafeCode)
{
Expression nextExpression = this.GetNextExpression(precedence, unsafeCode);
if (nextExpression == null)
{
throw this.CreateSyntaxException();
}
return nextExpression;
}
示例2: IsCastExpression
private bool IsCastExpression(ExpressionPrecedence previousPrecedence, bool unsafeCode)
{
Param.Ignore(previousPrecedence);
Param.Ignore(unsafeCode);
bool cast = false;
// The first symbol must be an opening parenthesis.
int index = this.GetNextCodeSymbolIndex(1);
if (index != -1)
{
Symbol symbol = this.symbols.Peek(index);
if (symbol.SymbolType == SymbolType.OpenParenthesis)
{
// The inner expression must have a type signature.
if (this.HasTypeSignature(index + 1, unsafeCode, out index))
{
if (index != -1)
{
symbol = this.symbols.Peek(index);
if (symbol.SymbolType == SymbolType.Other)
{
index = this.AdvanceToEndOfName(index);
}
// The next character must be a closing parenthesis or this is not a cast.
if (index != -1)
{
index = this.GetNextCodeSymbolIndex(index + 1);
if (index != -1)
{
symbol = this.symbols.Peek(index);
if (symbol.SymbolType == SymbolType.CloseParenthesis)
{
// This looks like it might be a cast, but a cast can only appear in front
// of the following types of symbols.
index = this.GetNextCodeSymbolIndex(index + 1);
if (index != -1)
{
Symbol nextSymbol = this.symbols.Peek(index);
SymbolType symbolType = nextSymbol.SymbolType;
if (symbolType == SymbolType.Other)
{
// This could be an expression like:
// from type in x where (type.IsClass) select type;
if (previousPrecedence != ExpressionPrecedence.Query ||
(nextSymbol.Text != "where" &&
nextSymbol.Text != "select" &&
nextSymbol.Text != "group" &&
nextSymbol.Text != "into" &&
nextSymbol.Text != "orderby" &&
nextSymbol.Text != "join" &&
nextSymbol.Text != "let" &&
nextSymbol.Text != "equals" &&
nextSymbol.Text != "by" &&
nextSymbol.Text != "on"))
{
cast = true;
}
}
else if (symbolType == SymbolType.OpenParenthesis ||
symbolType == SymbolType.Number ||
symbolType == SymbolType.Tilde ||
symbolType == SymbolType.Not ||
symbolType == SymbolType.New ||
symbolType == SymbolType.Sizeof ||
symbolType == SymbolType.Typeof ||
symbolType == SymbolType.Default ||
symbolType == SymbolType.Checked ||
symbolType == SymbolType.Unchecked ||
symbolType == SymbolType.This ||
symbolType == SymbolType.Base ||
symbolType == SymbolType.Null ||
symbolType == SymbolType.True ||
symbolType == SymbolType.False ||
symbolType == SymbolType.Plus ||
symbolType == SymbolType.Minus ||
symbolType == SymbolType.String ||
symbolType == SymbolType.Delegate)
{
cast = true;
}
else if (symbolType == SymbolType.Increment ||
symbolType == SymbolType.Decrement)
{
// This could be a cast if the symbol following the cast is an "other" or an opening parenthesis. For instance:
// object x = (object)++y;
// object x = (object)++(y);
// object x = (object)++this.y;
// However this is not a cast when:
// object x = (x)++;
int next = this.GetNextCodeSymbolIndex(index + 1);
if (next != -1)
{
SymbolType nextSymbolType = this.symbols.Peek(next).SymbolType;
if (nextSymbolType == SymbolType.Other ||
nextSymbolType == SymbolType.This ||
nextSymbolType == SymbolType.Base ||
nextSymbolType == SymbolType.OpenParenthesis)
{
//.........这里部分代码省略.........
示例3: GetAsExpression
/// <summary>
/// Reads an as expression.
/// </summary>
/// <param name="leftHandSide">The expression on the left hand side of the operator.</param>
/// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
/// <param name="parentReference">The parent code unit.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the expression.</returns>
private AsExpression GetAsExpression(
Expression leftHandSide, ExpressionPrecedence previousPrecedence, Reference<ICodePart> parentReference, bool unsafeCode)
{
Param.AssertNotNull(leftHandSide, "leftHandSide");
Param.Ignore(previousPrecedence);
Param.AssertNotNull(parentReference, "parentReference");
Param.Ignore(unsafeCode);
AsExpression expression = null;
// Check the previous precedence to see if we are allowed to gather up the as expression.
if (CheckPrecedence(previousPrecedence, ExpressionPrecedence.Relational))
{
var expressionReference = new Reference<ICodePart>();
// Make sure the left hand side has at least one token.
Debug.Assert(leftHandSide.Tokens.First != null, "The left hand side should not be empty");
// Get the as symbol.
this.tokens.Add(this.GetToken(CsTokenType.As, SymbolType.As, parentReference, expressionReference));
// The next token must be the type.
this.GetNextSymbol(SymbolType.Other, expressionReference);
// Get the expression representing the type.
LiteralExpression rightHandSide = this.GetTypeTokenExpression(expressionReference, unsafeCode, true);
if (rightHandSide == null || rightHandSide.Tokens.First == null)
{
throw this.CreateSyntaxException();
}
// Create the partial token list for the expression.
CsTokenList partialTokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
// Create and return the expression.
expression = new AsExpression(partialTokens, leftHandSide, rightHandSide);
expressionReference.Target = expression;
}
return expression;
}
示例4: GetOperatorRightHandExpression
/// <summary>
/// Reads and returns the right-hand expression of an operator expression.
/// </summary>
/// <param name="precedence">The precendence of this operator expression.</param>
/// <param name="parentReference">The parent code unit.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the expression.</returns>
private Expression GetOperatorRightHandExpression(ExpressionPrecedence precedence, Reference<ICodePart> parentReference, bool unsafeCode)
{
Param.AssertNotNull(precedence, "precedence");
Param.AssertNotNull(parentReference, "parentReference");
Param.Ignore(unsafeCode);
// Get the right hand expression.
Expression rightHandSide = this.GetNextExpression(precedence, parentReference, unsafeCode);
if (rightHandSide == null)
{
throw this.CreateSyntaxException();
}
// Make sure the right hand side has at least one token.
Debug.Assert(rightHandSide.Tokens.First != null, "The right-hand side should not be empty.");
return rightHandSide;
}
示例5: GetUnsafeTypeExpression
/// <summary>
/// Reads an unsafe type expression.
/// </summary>
/// <param name="type">The type expression.</param>
/// <param name="previousPrecedence">The precedence of the previous expression.</param>
/// <param name="parentReference">The parent code unit.</param>
/// <returns>Returns the expression.</returns>
private UnsafeAccessExpression GetUnsafeTypeExpression(Expression type, ExpressionPrecedence previousPrecedence, Reference<ICodePart> parentReference)
{
Param.Ignore(type);
Param.AssertNotNull(previousPrecedence, "previousPrecedence");
Param.AssertNotNull(parentReference, "parentReference");
UnsafeAccessExpression expression = null;
if (CheckPrecedence(previousPrecedence, ExpressionPrecedence.Unary))
{
// Get the operator symbol.
Symbol symbol = this.GetNextSymbol(parentReference);
var expressionReference = new Reference<ICodePart>();
OperatorType operatorType;
UnsafeAccessExpression.Operator unsafeOperatorType;
if (symbol.SymbolType == SymbolType.LogicalAnd)
{
operatorType = OperatorType.AddressOf;
unsafeOperatorType = UnsafeAccessExpression.Operator.AddressOf;
}
else if (symbol.SymbolType == SymbolType.Multiplication)
{
operatorType = OperatorType.Dereference;
unsafeOperatorType = UnsafeAccessExpression.Operator.Dereference;
}
else
{
Debug.Fail("Unexpected operator type.");
throw new InvalidOperationException();
}
// Create a token for the operator symbol.
this.symbols.Advance();
OperatorSymbol token = new OperatorSymbol(
symbol.Text,
OperatorCategory.Reference,
operatorType,
symbol.Location,
expressionReference,
this.symbols.Generated);
this.tokens.Add(token);
// Create the partial token list for the expression.
CsTokenList partialTokens = new CsTokenList(this.tokens, type.Tokens.First, this.tokens.Last);
// Create and return the expression.
expression = new UnsafeAccessExpression(partialTokens, unsafeOperatorType, type);
expressionReference.Target = expression;
}
return expression;
}
示例6: GetNextExpression
/// <summary>
/// Reads the next expression from the file and returns it.
/// </summary>
/// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
/// <param name="parentReference">Reference to the parent code part.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the expression.</returns>
private Expression GetNextExpression(ExpressionPrecedence previousPrecedence, Reference<ICodePart> parentReference, bool unsafeCode)
{
Param.Ignore(previousPrecedence);
Param.AssertNotNull(parentReference, "parentReference");
Param.Ignore(unsafeCode);
return this.GetNextExpression(previousPrecedence, parentReference, unsafeCode, false, false);
}
示例7: GetNullCoalescingExpression
/// <summary>
/// Reads a null coalescing expression.
/// </summary>
/// <param name="leftHandSide">The expression on the left hand side of the operator.</param>
/// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
/// <param name="parentReference">The parent code unit.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the expression.</returns>
private NullCoalescingExpression GetNullCoalescingExpression(
Expression leftHandSide, ExpressionPrecedence previousPrecedence, Reference<ICodePart> parentReference, bool unsafeCode)
{
Param.AssertNotNull(leftHandSide, "leftHandSide");
Param.Ignore(previousPrecedence);
Param.AssertNotNull(parentReference, "parentReference");
Param.Ignore(unsafeCode);
NullCoalescingExpression expression = null;
var expressionReference = new Reference<ICodePart>();
// Read the details of the expression.
OperatorSymbol operatorToken = this.PeekOperatorToken(parentReference, expressionReference);
Debug.Assert(operatorToken.SymbolType == OperatorType.NullCoalescingSymbol, "Expected a null-coalescing symbol");
// Check the precedence of the operators to make sure we can gather this statement now.
ExpressionPrecedence precedence = GetOperatorPrecedence(operatorToken.SymbolType);
if (CheckPrecedence(previousPrecedence, precedence))
{
// Add the operator token to the document and advance the symbol manager up to it.
this.symbols.Advance();
this.tokens.Add(operatorToken);
// Get the expression on the right-hand side of the operator.
Expression rightHandSide = this.GetOperatorRightHandExpression(precedence, expressionReference, unsafeCode);
// Create the partial token list for the expression.
CsTokenList partialTokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
// Create and return the expression.
expression = new NullCoalescingExpression(partialTokens, leftHandSide, rightHandSide);
expressionReference.Target = expression;
}
return expression;
}
示例8: GetNextExpression
/// <summary>
/// Reads the next expression from the file and returns it.
/// </summary>
/// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the expression.</returns>
private Expression GetNextExpression(ExpressionPrecedence previousPrecedence, bool unsafeCode)
{
Param.Ignore(previousPrecedence);
Param.Ignore(unsafeCode);
return this.GetNextExpression(previousPrecedence, unsafeCode, false, false);
}
示例9: GetArithmeticExpression
/// <summary>
/// Reads an arithmetic expression.
/// </summary>
/// <param name="leftHandSide">The expression on the left hand side of the operator.</param>
/// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the expression.</returns>
private ArithmeticExpression GetArithmeticExpression(
Expression leftHandSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
{
Param.AssertNotNull(leftHandSide, "leftHandSide");
Param.Ignore(previousPrecedence);
Param.Ignore(unsafeCode);
ArithmeticExpression expression = null;
// Read the details of the expression.
OperatorSymbol operatorToken = this.PeekOperatorToken();
Debug.Assert(
operatorToken.Category == OperatorCategory.Arithmetic || operatorToken.Category == OperatorCategory.Shift,
"Expected an arithmetic or shift operator");
// Check the precedence of the operators to make sure we can gather this statement now.
ExpressionPrecedence precedence = this.GetOperatorPrecedence(operatorToken.SymbolType);
if (this.CheckPrecedence(previousPrecedence, precedence))
{
// Add the operator token to the document and advance the symbol manager up to it.
this.symbols.Advance();
this.tokens.Add(operatorToken);
// Get the expression on the right-hand side of the operator.
Expression rightHandSide = this.GetOperatorRightHandExpression(precedence, unsafeCode);
// Create the partial token list for the expression.
CsTokenList partialTokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
// Get the expression operator type.
ArithmeticExpression.Operator type;
switch (operatorToken.SymbolType)
{
case OperatorType.Plus:
type = ArithmeticExpression.Operator.Addition;
break;
case OperatorType.Minus:
type = ArithmeticExpression.Operator.Subtraction;
break;
case OperatorType.Multiplication:
type = ArithmeticExpression.Operator.Multiplication;
break;
case OperatorType.Division:
type = ArithmeticExpression.Operator.Division;
break;
case OperatorType.Mod:
type = ArithmeticExpression.Operator.Mod;
break;
case OperatorType.LeftShift:
type = ArithmeticExpression.Operator.LeftShift;
break;
case OperatorType.RightShift:
type = ArithmeticExpression.Operator.RightShift;
break;
default:
Debug.Fail("Unexpected operator type");
throw new InvalidOperationException();
}
// Create and return the expression.
expression = new ArithmeticExpression(partialTokens, type, leftHandSide, rightHandSide);
}
return expression;
}
示例10: GetUnsafeTypeExpression
private UnsafeAccessExpression GetUnsafeTypeExpression(Expression type, ExpressionPrecedence previousPrecedence)
{
UnsafeAccessExpression expression = null;
OperatorType addressOf;
UnsafeAccessExpression.Operator dereference;
if (!CheckPrecedence(previousPrecedence, ExpressionPrecedence.Unary))
{
return expression;
}
Symbol nextSymbol = this.GetNextSymbol();
if (nextSymbol.SymbolType == SymbolType.LogicalAnd)
{
addressOf = OperatorType.AddressOf;
dereference = UnsafeAccessExpression.Operator.AddressOf;
}
else
{
if (nextSymbol.SymbolType != SymbolType.Multiplication)
{
throw new InvalidOperationException();
}
addressOf = OperatorType.Dereference;
dereference = UnsafeAccessExpression.Operator.Dereference;
}
this.symbols.Advance();
OperatorSymbol item = new OperatorSymbol(nextSymbol.Text, OperatorCategory.Reference, addressOf, nextSymbol.Location, this.symbols.Generated);
this.tokens.Add(item);
return new UnsafeAccessExpression(new CsTokenList(this.tokens, type.Tokens.First, this.tokens.Last), dereference, type);
}
示例11: GetVariableDeclarationExpression
private VariableDeclarationExpression GetVariableDeclarationExpression(Expression type, ExpressionPrecedence previousPrecedence, bool unsafeCode)
{
VariableDeclarationExpression expression = null;
Symbol symbol;
if (!CheckPrecedence(previousPrecedence, ExpressionPrecedence.None))
{
return expression;
}
LiteralExpression expression2 = null;
if (type.ExpressionType == ExpressionType.Literal)
{
expression2 = type as LiteralExpression;
if (!(expression2.Token is TypeToken))
{
expression2 = null;
}
}
if (expression2 == null)
{
expression2 = this.ConvertTypeExpression(type);
}
List<VariableDeclaratorExpression> list = new List<VariableDeclaratorExpression>();
Label_0042:
symbol = this.GetNextSymbol(SymbolType.Other);
LiteralExpression literalExpression = this.GetLiteralExpression(unsafeCode);
if ((literalExpression == null) || (literalExpression.Tokens.First == null))
{
throw new SyntaxException(this.document.SourceCode, symbol.LineNumber);
}
Expression initializer = null;
if (this.GetNextSymbol().SymbolType == SymbolType.Equals)
{
this.tokens.Add(this.GetOperatorToken(OperatorType.Equals));
if (this.GetNextSymbol().SymbolType == SymbolType.OpenCurlyBracket)
{
initializer = this.GetArrayInitializerExpression(unsafeCode);
}
else
{
initializer = this.GetNextExpression(ExpressionPrecedence.None, unsafeCode);
}
}
CsTokenList tokens = new CsTokenList(this.tokens, literalExpression.Tokens.First, this.tokens.Last);
list.Add(new VariableDeclaratorExpression(tokens, literalExpression, initializer));
if (this.GetNextSymbol().SymbolType == SymbolType.Comma)
{
this.tokens.Add(this.GetToken(CsTokenType.Comma, SymbolType.Comma));
goto Label_0042;
}
return new VariableDeclarationExpression(new CsTokenList(this.tokens, type.Tokens.First, this.tokens.Last), expression2, list.ToArray());
}
示例12: GetRelationalExpression
private RelationalExpression GetRelationalExpression(Expression leftHandSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
{
RelationalExpression expression = null;
RelationalExpression.Operator equalTo;
OperatorSymbol item = this.PeekOperatorToken();
ExpressionPrecedence operatorPrecedence = GetOperatorPrecedence(item.SymbolType);
if (!CheckPrecedence(previousPrecedence, operatorPrecedence))
{
return expression;
}
this.symbols.Advance();
this.tokens.Add(item);
Expression operatorRightHandExpression = this.GetOperatorRightHandExpression(operatorPrecedence, unsafeCode);
CsTokenList tokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
switch (item.SymbolType)
{
case OperatorType.ConditionalEquals:
equalTo = RelationalExpression.Operator.EqualTo;
break;
case OperatorType.NotEquals:
equalTo = RelationalExpression.Operator.NotEqualTo;
break;
case OperatorType.LessThan:
equalTo = RelationalExpression.Operator.LessThan;
break;
case OperatorType.GreaterThan:
equalTo = RelationalExpression.Operator.GreaterThan;
break;
case OperatorType.LessThanOrEquals:
equalTo = RelationalExpression.Operator.LessThanOrEqualTo;
break;
case OperatorType.GreaterThanOrEquals:
equalTo = RelationalExpression.Operator.GreaterThanOrEqualTo;
break;
default:
throw new InvalidOperationException();
}
return new RelationalExpression(tokens, equalTo, leftHandSide, operatorRightHandExpression);
}
示例13: CheckPrecedence
private static bool CheckPrecedence(ExpressionPrecedence previousPrecedence, ExpressionPrecedence nextPrecedence)
{
if (((previousPrecedence != ExpressionPrecedence.None) || (nextPrecedence != ExpressionPrecedence.None)) && ((previousPrecedence != ExpressionPrecedence.Conditional) || (nextPrecedence != ExpressionPrecedence.Conditional)))
{
return (previousPrecedence > nextPrecedence);
}
return true;
}
示例14: GetPrimaryIncrementExpression
private IncrementExpression GetPrimaryIncrementExpression(Expression leftHandSide, ExpressionPrecedence previousPrecedence)
{
IncrementExpression expression = null;
if (CheckPrecedence(previousPrecedence, ExpressionPrecedence.Primary))
{
this.tokens.Add(this.GetOperatorToken(OperatorType.Increment));
CsTokenList tokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
expression = new IncrementExpression(tokens, leftHandSide, IncrementExpression.IncrementType.Postfix);
}
return expression;
}
示例15: GetMemberAccessExpression
/// <summary>
/// Reads a member access expression.
/// </summary>
/// <param name="leftSide">The left side of the expression.</param>
/// <param name="previousPrecedence">The precedence of the previous expression.</param>
/// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
/// <returns>Returns the expression.</returns>
private MemberAccessExpression GetMemberAccessExpression(
Expression leftSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
{
Param.AssertNotNull(leftSide, "leftSide");
Param.Ignore(previousPrecedence);
Param.Ignore(unsafeCode);
MemberAccessExpression expression = null;
OperatorType operatorType;
MemberAccessExpression.Operator expressionOperatorType;
ExpressionPrecedence precedence;
var expressionReference = new Reference<ICodePart>();
// The next symbol must one of the member access types.
Symbol symbol = this.GetNextSymbol(expressionReference);
if (symbol.SymbolType == SymbolType.Dot)
{
operatorType = OperatorType.MemberAccess;
expressionOperatorType = MemberAccessExpression.Operator.Dot;
precedence = ExpressionPrecedence.Primary;
}
else if (symbol.SymbolType == SymbolType.Pointer)
{
operatorType = OperatorType.Pointer;
expressionOperatorType = MemberAccessExpression.Operator.Pointer;
precedence = ExpressionPrecedence.Primary;
}
else if (symbol.SymbolType == SymbolType.QualifiedAlias)
{
operatorType = OperatorType.QualifiedAlias;
expressionOperatorType = MemberAccessExpression.Operator.QualifiedAlias;
precedence = ExpressionPrecedence.Global;
}
else
{
Debug.Fail("Unexpected operator type");
throw new InvalidOperationException();
}
// Check the precedence. A member access has primary precedence.
if (CheckPrecedence(previousPrecedence, precedence))
{
// Add this to the document.
this.tokens.Add(this.GetOperatorToken(operatorType, expressionReference));
// Get the member being accessed. This must be a literal.
LiteralExpression member = this.GetLiteralExpression(expressionReference, unsafeCode);
if (member == null)
{
throw this.CreateSyntaxException();
}
// Create the token list.
CsTokenList partialTokens = new CsTokenList(this.tokens, leftSide.Tokens.First, this.tokens.Last);
// Create the expression.
expression = new MemberAccessExpression(partialTokens, expressionOperatorType, leftSide, member);
expressionReference.Target = expression;
}
return expression;
}