Beispiel #1
0
	void Associative_DecoratedIdentifier(out ProtoCore.AST.AssociativeAST.AssociativeNode 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.AssociativeAST.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.AssociativeAST.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.AssociativeAST.TypedIdentifierNode();
			typedVar.Name = typedVar.Value = t.val;
			NodeUtils.SetNodeLocation(typedVar, t);
			
			Expect(47);
			string strIdent = string.Empty;
			int type = ProtoCore.DSASM.Constants.kInvalidIndex;
			
			if (IsIdentList()) {
				TypedIdentifierList(out node);
				strIdent = node.ToString(); 
			} else if (la.kind == 1) {
				Get();
				strIdent = t.val; 
			} else SynErr(91);
			type = core.TypeSystem.GetType(strIdent);
			typedVar.TypeAlias = strIdent;
			if (type == ProtoCore.DSASM.Constants.kInvalidIndex)
			{
			var unknownType = new ProtoCore.Type();
			unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex;
			unknownType.Name = strIdent; 
			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) {
			Associative_IdentifierList(out node);
		} else SynErr(92);
	}
Beispiel #2
0
 /// <summary>
 /// Retrieves the string format of the identifier list from left to right, leaving out any symbols after the last identifier.
 /// Given: A.B()
 ///     Return: "A.B"
 /// Given: A.B.C()[0]
 ///     Return: "A.B.C"
 /// Given: A.B().C
 ///     Return: "A.B"
 /// Given: A.B[0].C
 ///     Return: "A.B[0].C"
 /// </summary>
 /// <param name="identList"></param>
 /// <returns></returns>
 public static string GetIdentifierStringUntilFirstParenthesis(ProtoCore.AST.AssociativeAST.IdentifierListNode identList)
 {
     Validity.Assert(null != identList);
     string identListString = identList.ToString();
     int removeIndex = identListString.IndexOf('(');
     if (removeIndex > 0)
     {
         identListString = identListString.Remove(removeIndex);
     }
     return identListString;
 }
Beispiel #3
0
        /// <summary>
        /// Traverses the identifierlist argument until class name resolution succeeds or fails.
        /// </summary>
        /// <param name="classTable"></param>
        /// <param name="identList"></param>
        /// <returns></returns>
        public static string[] GetResolvedClassName(ProtoCore.DSASM.ClassTable classTable, ProtoCore.AST.AssociativeAST.IdentifierListNode identList)
        {
            string identString = GetIdentifierStringUntilFirstParenthesis(identList);
            string[] classNames = classTable.GetAllMatchingClasses(ProtoCore.Utils.CoreUtils.GetIdentifierStringUntilFirstParenthesis(identList));

            // Failed to find the first time
            // Attempt to remove identifiers in the identifierlist until we find a class or not
            while (0 == classNames.Length)
            {
                // Move to the left node
                AssociativeNode leftNode = identList.LeftNode;
                if (leftNode is IdentifierListNode)
                {
                    identList = leftNode as IdentifierListNode;
                    string identListString = identList.ToString();
                    classNames = classTable.GetAllMatchingClasses(ProtoCore.Utils.CoreUtils.GetIdentifierStringUntilFirstParenthesis(identList));
                }
                else
                {
                    break;
                }
            }
            return classNames;
        }