Example #1
0
        // 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;
            }
        }
Example #2
0
	void Imperative_functioncall(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {
		Expect(1);
		ProtoCore.AST.ImperativeAST.IdentifierNode function = new ProtoCore.AST.ImperativeAST.IdentifierNode() { Value = t.val, Name = t.val }; 
		NodeUtils.SetNodeLocation(function, t); 
		List<ProtoCore.AST.ImperativeAST.ImperativeNode> arglist = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>(); 
		Expect(12);
		if (StartOf(4)) {
			ProtoCore.AST.ImperativeAST.ImperativeNode argNode; 
			Imperative_expr(out argNode);
			arglist.Add(argNode); 
			while (la.kind == 52) {
				Get();
				Imperative_expr(out argNode);
				arglist.Add(argNode); 
			}
		}
		Expect(13);
		ProtoCore.AST.ImperativeAST.FunctionCallNode funcNode = new ProtoCore.AST.ImperativeAST.FunctionCallNode(); 
		funcNode.Function = function;
		funcNode.FormalArguments = arglist;
		NodeUtils.SetNodeStartLocation(funcNode, function);
		NodeUtils.SetNodeEndLocation(funcNode, t);
		node = funcNode; 
		
	}
Example #3
0
 ProtoCore.AST.ImperativeAST.IdentifierNode BuildImperativeIdentifier(string name, ProtoCore.PrimitiveType type = ProtoCore.PrimitiveType.kTypeVar)
 {
     var ident = new ProtoCore.AST.ImperativeAST.IdentifierNode();
     ident.Name = ident.Value = name;
     ident.datatype = TypeSystem.BuildPrimitiveTypeObject(type, 0);
     return ident;
 }
Example #4
0
	void Imperative_decoratedIdentifier(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {
		node = null; 
		if (IsLocallyTypedVariable()) {
			Expect(1);
			if (IsKeyWord(t.val, true))
			{
			   errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
			}
			var typedVar = new ProtoCore.AST.ImperativeAST.TypedIdentifierNode();
			typedVar.Name = typedVar.Value = t.val;
			NodeUtils.SetNodeLocation(typedVar, t);
			
			Expect(47);
			Expect(40);
			typedVar.IsLocal = true;
			
			Expect(1);
			int type = core.TypeSystem.GetType(t.val); 
			if (type == ProtoCore.DSASM.Constants.kInvalidIndex)
			{
			   var unknownType = new ProtoCore.Type();
			   unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex;
			   unknownType.Name = t.val; 
			   typedVar.DataType = unknownType;
			}
			else
			{
			   typedVar.DataType = core.TypeSystem.BuildTypeObject(type, 0);
			}
			
			if (la.kind == 10) {
				var datatype = typedVar.DataType; 
				Get();
				Expect(11);
				datatype.rank = 1; 
				if (la.kind == 10 || la.kind == 24) {
					if (la.kind == 24) {
						Get();
						Expect(10);
						Expect(11);
						datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; 
					} else {
						while (la.kind == 10) {
							Get();
							Expect(11);
							datatype.rank++; 
						}
					}
				}
				typedVar.DataType = datatype; 
			}
			node = typedVar; 
		} else if (IsLocalVariable()) {
			Expect(1);
			if (IsKeyWord(t.val, true))
			{
			   errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
			}
			var identNode = new ProtoCore.AST.ImperativeAST.IdentifierNode();
			identNode.Name = identNode.Value = t.val;
			NodeUtils.SetNodeLocation(identNode, t);
			
			Expect(47);
			Expect(40);
			identNode.IsLocal = true;
			
			node = identNode; 
		} else if (IsTypedVariable()) {
			Expect(1);
			if (IsKeyWord(t.val, true))
			{
			   errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
			}
			var typedVar = new ProtoCore.AST.ImperativeAST.TypedIdentifierNode();
			typedVar.Name = typedVar.Value = t.val;
			NodeUtils.SetNodeLocation(typedVar, t);
			
			Expect(47);
			Expect(1);
			int type = core.TypeSystem.GetType(t.val); 
			if (type == ProtoCore.DSASM.Constants.kInvalidIndex)
			{
			   var unknownType = new ProtoCore.Type();
			   unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex;
			   unknownType.Name = t.val; 
			   typedVar.DataType = unknownType;
			}
			else
			{
			   typedVar.DataType = core.TypeSystem.BuildTypeObject(type, 0);
			}
			
			if (la.kind == 10) {
				var datatype = typedVar.DataType; 
				Get();
				Expect(11);
				datatype.rank = 1; 
				if (la.kind == 10 || la.kind == 24) {
					if (la.kind == 24) {
						Get();
						Expect(10);
						Expect(11);
						datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; 
					} else {
						while (la.kind == 10) {
							Get();
							Expect(11);
							datatype.rank++; 
						}
					}
				}
				typedVar.DataType = datatype; 
			}
			node = typedVar; 
		} else if (la.kind == 1 || la.kind == 12 || la.kind == 45) {
			Imperative_IdentifierList(out node);
		} else SynErr(113);
	}
Example #5
0
        // 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;
            }
        }