/// <summary> /// Handles identifier. Get LocalBuilder or creates it. /// </summary> /// <param name="node">SyntaxTree node of identifier.</param> /// <returns>LocalBUilder instance that represents the identifier.</returns> protected LocalBuilder handleIdentifier(DTreeNode <string> node) { int type = 0; string s = LexemTypeHelper.parse(ref type, node.Value); LocalBuilder lBuilder; if (!locals.TryGetValue(s, out lBuilder)) { if (node.Nodes.Count == 0) { // ERROR! TODO } lBuilder = ilg.DeclareLocal(ILHelper.getILType(LexemTypeHelper.getParsedValue(node.Nodes[0].Value))); locals.Add(s, lBuilder); } return(lBuilder); }
/// <summary> /// Gets return type of the method. /// </summary> /// <param name="node">SyntaxTree node of the method's name.</param> /// <param name="num">Possible position in SyntaxTree of return type. /// It's because return type can be array and consists of 2 nodes.</param> /// <returns>Return type of the method.</returns> protected Type getRetType(DTreeNode <string> node, int num) { Type type; if (LexemTypeHelper.getParsedValue(node.Nodes[num].Value) == "[]") { switch (LexemTypeHelper.getParsedValue(node.Nodes[num - 1].Value)) { case "int": type = typeof(int[]); break; case "double": type = typeof(int[]); break; case "String": type = typeof(int[]); break; default: type = null; break; } } else { type = ILHelper.getILType(LexemTypeHelper.getParsedValue(node.Nodes[num].Value)); } return(type); }