/// <summary> /// Reads a checked expression from the code. /// </summary> /// <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 CheckedExpression GetCheckedExpression(Reference<ICodePart> parentReference, bool unsafeCode) { Param.AssertNotNull(parentReference, "parentReference"); Param.Ignore(unsafeCode); Reference<ICodePart> expressionReference = new Reference<ICodePart>(); // Get the checked keyword. Node<CsToken> firstTokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.Checked, SymbolType.Checked, parentReference, expressionReference)); // The next symbol will be the opening parenthesis. Bracket openParenthesis = this.GetBracketToken(CsTokenType.OpenParenthesis, SymbolType.OpenParenthesis, expressionReference); Node<CsToken> openParenthesisNode = this.tokens.InsertLast(openParenthesis); // Get the inner expression. Expression innerExpression = this.GetNextExpression(ExpressionPrecedence.None, expressionReference, unsafeCode); // Get the closing parenthesis. Bracket closeParenthesis = this.GetBracketToken(CsTokenType.CloseParenthesis, SymbolType.CloseParenthesis, expressionReference); Node<CsToken> closeParenthesisNode = this.tokens.InsertLast(closeParenthesis); openParenthesis.MatchingBracketNode = closeParenthesisNode; closeParenthesis.MatchingBracketNode = openParenthesisNode; // Create the token list for the method invocation expression. CsTokenList partialTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last); // Create and return the expression. CheckedExpression expression = new CheckedExpression(partialTokens, innerExpression); expressionReference.Target = expression; return expression; }
/// <summary> /// The save. /// </summary> /// <param name="checkedExpression"> /// The checked expression. /// </param> private void Save(CheckedExpression checkedExpression) { this.cppWriter.Write("("); @switch(checkedExpression.InternalExpression); this.cppWriter.Write(")"); }