static void FixAmpersandAsRef(CleanupAstNodeStates states, int declarationStart) { var refToken = TokenKind.Ref.BuildTokenFromId(); var spaceToken = TokenKind.Space.BuildTokenFromId(" "); states.RemoveAt(declarationStart + 1); states.Insert(declarationStart, spaceToken); states.Insert(declarationStart, refToken); states.Remap(); }
void HandleMultipleParameters(ParseNode astNode, CleanupAstNodeStates states) { var typeNode = states[0]; var commaPositions = ComputeCommaPositions(states); var functionBlockNode = typeNode.GetParentFunctionBlockNode() ?? typeNode.GetRootNode(); ExtractArrayParameters(states, commaPositions, typeNode, functionBlockNode); astNode.RemoveFromParent(); _found = true; states.Remap(); }
public static void SetRequiredParen(CleanupAstNodeStates states) { var openSquarePos = states.MappedNodes.GeNextTokenKind(TokenKind.OpenSquared); var closeSquarePos = states.MappedNodes.GeNextTokenKind(TokenKind.CloseSquared); var commaPos = states.MappedNodes.GeNextTokenKind(TokenKind.Comma); if (openSquarePos + 1 == closeSquarePos || openSquarePos + 1 == commaPos) { states.Insert(openSquarePos + 1, TokenKind.Int.BuildTokenFromId("0")); states.Remap(); } if (commaPos + 1 == closeSquarePos) { states.Insert(commaPos + 1, TokenKind.Int.BuildTokenFromId("0")); states.Remap(); } var tokenData = states[0].GetTokenData(); var typeToken = tokenData.Clone(); var assignPos = states.GeNextTokenKind(TokenKind.Assign); if (assignPos > 0) { var openSquaredPos = states.GeNextTokenKind(TokenKind.OpenSquared); if (openSquaredPos > assignPos) return; } var nodesToBeAdded = new List<ParseNode> { TokenKind.Assign.BuildTokenFromId(), TokenKind.Space.BuildTokenFromId(" "), TokenKind.New.BuildTokenFromId(), TokenKind.Space.BuildTokenFromId(" "), typeToken.BuildTerminalNode(), }; states.InsertRange(2, nodesToBeAdded); var countSquared = states.Count(node => node.GetTokenKind() == TokenKind.Comma) + 1; var toAdd = BuildSquaresAndCommas(countSquared); states.InsertRange(1, toAdd); }
void FixArrayInParam(int pos, int endRange, CleanupAstNodeStates states) { var openParen = states.GeNextTokenKind(TokenKind.OpenSquared, pos); if (openParen == 0 || openParen > endRange) return; var closeParen = states.GeNextTokenKind(TokenKind.CloseSquared, openParen); var openNode = states[openParen]; var closeNode = states[closeParen]; states.RemoveAt(closeParen); states.RemoveAt(openParen); states.Insert(pos + 1, closeNode); states.Insert(pos + 1, openNode); states.Remap(); }
void FixArrayInParam(int pos, int endRange, CleanupAstNodeStates states) { var openParen = 0; for (var index = pos; index < endRange; index++) { var searchNode = states[index]; if (searchNode.GetTokenKind() == TokenKind.Operator && searchNode.GetTokenData().Content == "&") openParen = index; } if (openParen == 0) return; states.RemoveAt(openParen); states.Insert(pos, TokenKind.Space.BuildTokenFromId(" ")); states.Insert(pos, TokenKind.Ref.BuildTokenFromId()); states.Remap(); }