Esempio n. 1
0
        public static List<Error> ResoloveBody(Node root)
        {
            var errors = new List<Error>();

            foreach (var st in root.GetSpecifiedChildren<Body>().First().Statements)
            {
                errors.AddRange(StatementResolver.Resolve(st));
            }

            return errors;
        }
Esempio n. 2
0
        public static List<Error> ResolveVariableType(Node root)
        {
            var errors = new List<Error>();

            foreach (var var in root.GetSpecifiedChildren<Variable>())
            {
                errors.AddRange(ResolveType(var.Type, var));
            }

            return errors;
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
 private static void EmitLocalVariable(Node node)
 {
     var v =
         node.GetSpecifiedChildren<Variable>()
             .Where(x => x.VarSemantics == VarType.Variable);
     //  .Select(par => MakeString(par.Type) + " " + par.Name.Text)
     //              .ToList();
     var res = v.Select(var => MakeString(var.Type) + " " + var.Name.Text).ToList();
     var constr = (from re in v where re.Type.GetTypeInfo() == TypeInfo.Ref select re.Name.Text + " = new " + MakeString(re.Type) + "()").ToList();
     if (res.Count!=0)
         Source += string.Join(";\n", res) + ";\n";
     if (constr.Count != 0)
         Source += string.Join(";\n", constr) + ";\n";
 }
Esempio n. 5
0
 private static void EmitLocalParam(Node node)
 {
     var list =
         node.GetSpecifiedChildren<Variable>()
             .Where(x => x.VarSemantics == VarType.Parameter)
             .Select(par => MakeString(par.Type) + " " + par.Name.Text)
             .ToList();
     Source += string.Join(",", list);
 }