protected override void FixRuleProblem(ParseNode node) { var states = node.States[0].States; if(states.Count!=2) return; var functionNode = node.GetParentFunctionDeclaration(); var parentFunctionDeclaration = functionNode.States; if (parentFunctionDeclaration[0].Token != TokenKind.TypeName) return; var functionTypeName = parentFunctionDeclaration[0].Content; if (functionTypeName == "void") return; states.InsertRange(1, new[] { TokenKind.OpenParen.BuildTokenFromId(), TokenKind.CloseParen.BuildTokenFromId(), }); switch (functionTypeName) { case TypeNames.Int: states.Insert(2, TokenKind.Int.BuildTokenFromId("0")); break; case TypeNames.Double: states.Insert(2, TokenKind.Float.BuildTokenFromId("0.0")); break; default: throw new InvalidDataException("Invalid return type"); } states.Remap(); }
protected override void FixLogic(ParseNode node) { var parentStaticDeclaration = node.Parent; var parentRule = parentStaticDeclaration.Rule; if (parentRule != RuleKind.Static) return; var getFunctionNode = node.GetParentFunctionDeclaration(); if(getFunctionNode==null) return; var siblingInstructions = parentStaticDeclaration.Parent.Children; siblingInstructions.RemoveAt(siblingInstructions.IndexOf(parentStaticDeclaration)); var functionName = GetFunctionName(getFunctionNode); var renameTable = new RenameTable(functionName); renameTable.ScanNames(parentStaticDeclaration); renameTable.RenameInTree(parentStaticDeclaration); renameTable.RenameInTree(getFunctionNode); var functionChildren = getFunctionNode.Parent.Children; var functionPosInProgram = functionChildren.IndexOf(getFunctionNode); var staticStates = parentStaticDeclaration.States.MappedNodes; functionChildren.Insert(functionPosInProgram, staticStates[1]); }