private static IEnumerable<Error> ResolveIdType(Node root, IToken token, out Node newRoot, out IType type) { var errors = new List<Error>(); newRoot = null; type = null; if ((!root.GetSubChildren<Variable>().Select(x => x.Name.Text).Contains(token.Text)) && (root.Name.Text != token.Text)) errors.Add(new Error(root.GetSourceIdentifier(), token, string.Format(ErrorMessages.VariableNotFound, token.Text))); else { if ((root.Name.Text == token.Text) && (root is Function)) { type = ((Function) root).ReturnType; return errors; } var var = new Variable(); try { var = root.GetSpecifiedChildren<Variable>().First(x => x.Name.Text == token.Text); } catch { errors.Add(new Error(root.GetSourceIdentifier(), token, string.Format(ErrorMessages.VariableNotFound, token.Text))); return errors; } type = var.Type; if (var.Type.GetTypeInfo() == TypeInfo.Ref) { newRoot = root.GetNearestParent<Program>() .GetSpecifiedChildren<Record>().First(x => x.Name.Text == var.Type.ToString()); } } return errors; }
private static void EmitRecVar(Variable var) { Source += "public " + MakeString(var.Type) + " " + var.Name.Text + ";\n"; }