/// <summary> /// Reads the next case-statement from the file and returns it. /// </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 statement. /// </returns> private SwitchCaseStatement ParseSwitchCaseStatement(Reference<ICodePart> parentReference, bool unsafeCode) { Param.AssertNotNull(parentReference, "parentReference"); Param.Ignore(unsafeCode); Reference<ICodePart> statementReference = new Reference<ICodePart>(); // Move past the case keyword. CsToken firstToken = this.GetToken(CsTokenType.Case, SymbolType.Case, parentReference, statementReference); Node<CsToken> firstTokenNode = this.tokens.InsertLast(firstToken); // Get the name. Symbol symbol = this.GetNextSymbol(statementReference); if (symbol.SymbolType != SymbolType.Other && symbol.SymbolType != SymbolType.String && symbol.SymbolType != SymbolType.Number && symbol.SymbolType != SymbolType.Null && symbol.SymbolType != SymbolType.OpenParenthesis && symbol.SymbolType != SymbolType.Minus && symbol.SymbolType != SymbolType.Plus && symbol.SymbolType != SymbolType.True && symbol.SymbolType != SymbolType.False && symbol.SymbolType != SymbolType.Sizeof && symbol.SymbolType != SymbolType.Typeof && symbol.SymbolType != SymbolType.Checked && symbol.SymbolType != SymbolType.Unchecked) { throw this.CreateSyntaxException(); } Expression identifier = this.GetNextExpression(ExpressionPrecedence.None, statementReference, unsafeCode); // Get the colon. this.tokens.Add(this.GetToken(CsTokenType.LabelColon, SymbolType.Colon, statementReference)); // Create the statement. SwitchCaseStatement caseStatement = new SwitchCaseStatement(identifier); // Get each of the sub-statements beneath this statement. while (true) { // Check the type of the next symbol. symbol = this.GetNextSymbol(statementReference); // Check if we've reached the end of the case statement. if (symbol.SymbolType == SymbolType.CloseCurlyBracket || symbol.SymbolType == SymbolType.Case || symbol.SymbolType == SymbolType.Default) { break; } // Read the next child statement. Statement statement = this.GetNextStatement(statementReference, unsafeCode, caseStatement.Variables); if (statement == null) { throw this.CreateSyntaxException(); } // Add it to the case statement. caseStatement.AddStatement(statement); } // Create the token list for the case statement. caseStatement.Tokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last); statementReference.Target = caseStatement; return caseStatement; }
/// <summary> /// The save. /// </summary> /// <param name="switchCaseStatement"> /// The switch case statement. /// </param> private void Save(SwitchCaseStatement switchCaseStatement) { this.cppWriter.Write("case "); @switch(switchCaseStatement.Identifier); this.cppWriter.WriteLine(":"); this.Save(switchCaseStatement, SaveICodeUnit.IfNotEmpty | SaveICodeUnit.NoBrackets); }