void Imperative_IdentifierList(out ProtoCore.AST.ImperativeAST.ImperativeNode node) { node = null; if (isInClass && IsIdentList()) disableKwCheck = true; Imperative_NameReference(out node); disableKwCheck = false; while (la.kind == 6) { Get(); ProtoCore.AST.ImperativeAST.ImperativeNode rnode = null; Imperative_NameReference(out rnode); ProtoCore.AST.ImperativeAST.IdentifierListNode bnode = new ProtoCore.AST.ImperativeAST.IdentifierListNode(); bnode.LeftNode = node; bnode.Optr = Operator.dot; bnode.RightNode = rnode; NodeUtils.SetNodeLocation(bnode, bnode.LeftNode, bnode.RightNode); if (bnode.RightNode is ProtoCore.AST.ImperativeAST.FunctionCallNode) { // We want the entire "Point.Project()" to be highlighted, // not just "Project()". So if the RHS is a function call node, // then the identifier list should be extended to include both // LeftNode and RightNode (which is the entire 'bnode' here). NodeUtils.CopyNodeLocation(bnode.RightNode, bnode); } node = bnode; } }
// TODO Jun: move this function in a utils file private void TraverseAndAppendThisPtrArg(ProtoCore.AST.ImperativeAST.ImperativeNode node, ref ProtoCore.AST.ImperativeAST.ImperativeNode newIdentList) { if (node is ProtoCore.AST.ImperativeAST.BinaryExpressionNode) { TraverseAndAppendThisPtrArg((node as ProtoCore.AST.ImperativeAST.BinaryExpressionNode).LeftNode, ref newIdentList); TraverseAndAppendThisPtrArg((node as ProtoCore.AST.ImperativeAST.BinaryExpressionNode).RightNode, ref newIdentList); } else if (node is ProtoCore.AST.ImperativeAST.IdentifierListNode) { // Travere until the left most identifier ProtoCore.AST.ImperativeAST.IdentifierListNode binaryNode = node as ProtoCore.AST.ImperativeAST.IdentifierListNode; while ((binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode is ProtoCore.AST.ImperativeAST.IdentifierListNode) { binaryNode = (binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode as ProtoCore.AST.ImperativeAST.IdentifierListNode; } ProtoCore.AST.ImperativeAST.IdentifierNode identNode = null; if ((binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode is ProtoCore.AST.ImperativeAST.IdentifierNode) { identNode = (binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode as ProtoCore.AST.ImperativeAST.IdentifierNode; } Validity.Assert(identNode is ProtoCore.AST.ImperativeAST.IdentifierNode); string leftMostSymbolName = identNode.Name; // Is it a this pointer? if (leftMostSymbolName.Equals(ProtoCore.DSDefinitions.Keyword.This)) { // Then just replace it identNode.Name = identNode.Value = ProtoCore.DSASM.Constants.kThisPointerArgName; newIdentList = node; return; } // Is the left most symbol a member? SymbolNode symbolnode; bool isAccessible = false; bool isAllocated = VerifyAllocation(leftMostSymbolName, globalClassIndex, ProtoCore.DSASM.Constants.kGlobalScope, out symbolnode, out isAccessible); if (!isAllocated) { newIdentList = node; return; } ProtoCore.AST.ImperativeAST.IdentifierListNode identList = new ProtoCore.AST.ImperativeAST.IdentifierListNode(); ProtoCore.AST.ImperativeAST.IdentifierNode lhsThisArg = new ProtoCore.AST.ImperativeAST.IdentifierNode(); lhsThisArg.Name = ProtoCore.DSASM.Constants.kThisPointerArgName; lhsThisArg.Value = ProtoCore.DSASM.Constants.kThisPointerArgName; identList.LeftNode = lhsThisArg; identList.Optr = Operator.dot; identList.RightNode = identNode; // Update the last binary dot node with the new dot node binaryNode.LeftNode = identList; newIdentList = binaryNode; } else if (node is ProtoCore.AST.ImperativeAST.FunctionCallNode) { ProtoCore.AST.ImperativeAST.FunctionCallNode fCall = node as ProtoCore.AST.ImperativeAST.FunctionCallNode; for (int n = 0; n < fCall.FormalArguments.Count; ++n) { ProtoCore.AST.ImperativeAST.ImperativeNode argNode = fCall.FormalArguments[n]; TraverseAndAppendThisPtrArg(argNode, ref argNode); fCall.FormalArguments[n] = argNode; } newIdentList = fCall; } else if (node is ProtoCore.AST.ImperativeAST.IdentifierNode) { string identName = (node as ProtoCore.AST.ImperativeAST.IdentifierNode).Name; if (identName.Equals(ProtoCore.DSDefinitions.Keyword.Return)) { newIdentList = node; return; } if (ProtoCore.DSASM.Constants.kInvalidIndex == globalClassIndex) { newIdentList = node; return; } // Temp are not member vars if (ProtoCore.Utils.CoreUtils.IsAutoGeneratedVar(identName)) { newIdentList = node; return; } // Is it a member SymbolNode symbolnode; bool isAccessible = false; bool isAllocated = VerifyAllocation(identName, globalClassIndex, ProtoCore.DSASM.Constants.kGlobalScope, out symbolnode, out isAccessible); if (!isAllocated) { newIdentList = node; return; } ProtoCore.AST.ImperativeAST.IdentifierListNode identList = new ProtoCore.AST.ImperativeAST.IdentifierListNode(); ProtoCore.AST.ImperativeAST.IdentifierNode lhsThisArg = new ProtoCore.AST.ImperativeAST.IdentifierNode(); lhsThisArg.Name = ProtoCore.DSASM.Constants.kThisPointerArgName; lhsThisArg.Value = ProtoCore.DSASM.Constants.kThisPointerArgName; identList.LeftNode = lhsThisArg; identList.Optr = Operator.dot; identList.RightNode = node; newIdentList = identList; } else { newIdentList = node; } }
// TODO Jun: move this function in a utils file private void TraverseAndAppendThisPtrArg(ProtoCore.AST.ImperativeAST.ImperativeNode node, ref ProtoCore.AST.ImperativeAST.ImperativeNode newIdentList) { if (node is ProtoCore.AST.ImperativeAST.BinaryExpressionNode) { TraverseAndAppendThisPtrArg((node as ProtoCore.AST.ImperativeAST.BinaryExpressionNode).LeftNode, ref newIdentList); TraverseAndAppendThisPtrArg((node as ProtoCore.AST.ImperativeAST.BinaryExpressionNode).RightNode, ref newIdentList); } else if (node is ProtoCore.AST.ImperativeAST.IdentifierListNode) { // Travere until the left most identifier ProtoCore.AST.ImperativeAST.IdentifierListNode binaryNode = node as ProtoCore.AST.ImperativeAST.IdentifierListNode; while ((binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode is ProtoCore.AST.ImperativeAST.IdentifierListNode) { binaryNode = (binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode as ProtoCore.AST.ImperativeAST.IdentifierListNode; } ProtoCore.AST.ImperativeAST.IdentifierNode identNode = null; if ((binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode is ProtoCore.AST.ImperativeAST.IdentifierNode) { identNode = (binaryNode as ProtoCore.AST.ImperativeAST.IdentifierListNode).LeftNode as ProtoCore.AST.ImperativeAST.IdentifierNode; } Validity.Assert(identNode is ProtoCore.AST.ImperativeAST.IdentifierNode); string leftMostSymbolName = identNode.Name; // Is it a this pointer? if (leftMostSymbolName.Equals(ProtoCore.DSDefinitions.Kw.kw_this)) { // Then just replace it identNode.Name = identNode.Value = ProtoCore.DSASM.Constants.kThisPointerArgName; newIdentList = node; return; } // Is the left most symbol a member? SymbolNode symbolnode; bool isAccessible = false; bool isAllocated = VerifyAllocation(leftMostSymbolName, globalClassIndex, ProtoCore.DSASM.Constants.kGlobalScope, out symbolnode, out isAccessible); if (!isAllocated) { newIdentList = node; return; } ProtoCore.AST.ImperativeAST.IdentifierListNode identList = new ProtoCore.AST.ImperativeAST.IdentifierListNode(); ProtoCore.AST.ImperativeAST.IdentifierNode lhsThisArg = new ProtoCore.AST.ImperativeAST.IdentifierNode(); lhsThisArg.Name = ProtoCore.DSASM.Constants.kThisPointerArgName; lhsThisArg.Value = ProtoCore.DSASM.Constants.kThisPointerArgName; identList.LeftNode = lhsThisArg; identList.Optr = Operator.dot; identList.RightNode = identNode; // Update the last binary dot node with the new dot node binaryNode.LeftNode = identList; newIdentList = binaryNode; } else if (node is ProtoCore.AST.ImperativeAST.FunctionCallNode) { ProtoCore.AST.ImperativeAST.FunctionCallNode fCall = node as ProtoCore.AST.ImperativeAST.FunctionCallNode; for (int n = 0; n < fCall.FormalArguments.Count; ++n) { ProtoCore.AST.ImperativeAST.ImperativeNode argNode = fCall.FormalArguments[n]; TraverseAndAppendThisPtrArg(argNode, ref argNode); fCall.FormalArguments[n] = argNode; } newIdentList = fCall; } /* else if (node is ProtoCore.AST.ImperativeAST.FunctionDotCallNode) { ProtoCore.AST.ImperativeAST.FunctionDotCallNode dotCall = node as ProtoCore.AST.ImperativeAST.FunctionDotCallNode; string name = dotCall.DotCall.FormalArguments[0].Name; // TODO Jun: If its a constructor, leave it as it is. // After the first version of global instance functioni s implemented, 2nd phase would be to remove dotarg methods completely bool isConstructorCall = false; if (null != name) { isConstructorCall = ProtoCore.DSASM.Constants.kInvalidIndex != core.ClassTable.IndexOf(name); } ProtoCore.AST.ImperativeAST.FunctionCallNode fCall = (node as ProtoCore.AST.ImperativeAST.FunctionDotCallNode).FunctionCall; if (isConstructorCall) { newIdentList = node; } else { for (int n = 0; n < fCall.FormalArguments.Count; ++n) { ProtoCore.AST.ImperativeAST.ImperativeNode argNode = fCall.FormalArguments[n]; TraverseAndAppendThisPtrArg(argNode, ref argNode); fCall.FormalArguments[n] = argNode; } newIdentList = fCall; } } */ else if (node is ProtoCore.AST.ImperativeAST.IdentifierNode) { string identName = (node as ProtoCore.AST.ImperativeAST.IdentifierNode).Name; if (identName.Equals(ProtoCore.DSDefinitions.Kw.kw_return)) { newIdentList = node; return; } if (ProtoCore.DSASM.Constants.kInvalidIndex == globalClassIndex) { newIdentList = node; return; } // Temp are not member vars if (ProtoCore.Utils.CoreUtils.IsAutoGeneratedVar(identName)) { newIdentList = node; return; } // Is it a member SymbolNode symbolnode; bool isAccessible = false; bool isAllocated = VerifyAllocation(identName, globalClassIndex, ProtoCore.DSASM.Constants.kGlobalScope, out symbolnode, out isAccessible); if (!isAllocated) { newIdentList = node; return; } ProtoCore.AST.ImperativeAST.IdentifierListNode identList = new ProtoCore.AST.ImperativeAST.IdentifierListNode(); ProtoCore.AST.ImperativeAST.IdentifierNode lhsThisArg = new ProtoCore.AST.ImperativeAST.IdentifierNode(); lhsThisArg.Name = ProtoCore.DSASM.Constants.kThisPointerArgName; lhsThisArg.Value = ProtoCore.DSASM.Constants.kThisPointerArgName; identList.LeftNode = lhsThisArg; identList.Optr = Operator.dot; identList.RightNode = node; newIdentList = identList; } else { newIdentList = node; } }