/// <summary> /// Reads a typeof 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 TypeofExpression GetTypeofExpression(Reference<ICodePart> parentReference, bool unsafeCode) { Param.AssertNotNull(parentReference, "parentReference"); Param.Ignore(unsafeCode); Reference<ICodePart> expressionReference = new Reference<ICodePart>(); // Get the typeof keyword. Node<CsToken> firstTokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.Typeof, SymbolType.Typeof, 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 representing the type. LiteralExpression typeTokenExpression = this.GetTypeTokenExpression(expressionReference, unsafeCode, true); if (typeTokenExpression == null) { throw this.CreateSyntaxException(); } // 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. TypeofExpression expression = new TypeofExpression(partialTokens, typeTokenExpression); expressionReference.Target = expression; return expression; }
/// <summary> /// The save. /// </summary> /// <param name="typeofExpression"> /// The typeof expression. /// </param> private void Save(TypeofExpression typeofExpression) { this.cppWriter.Write("TypeName("); this.Save(new TypeResolver(typeofExpression.Type, this), this.cppWriter, SavingOptions.RemovePointer); this.cppWriter.Write("::typeid)"); }