Ejemplo n.º 1
0
        public static void Resolve(this expr e, block scope)
        {
            if (e is constant)
            {
                return;
            }
            var v = e as variable;

            if (v != null)
            {
                var d = scope.Lookup(v.id);
                v.Untyped.AddAnnotation(
                    new DeclAnnotation {
                    reference = d
                });
                return;
            }
            var b = e as block;

            if (b != null)
            {
                b.Untyped.AddAnnotation(
                    new BlockAnnotation {
                    reference = scope
                });
                foreach (expr x in b.expr)
                {
                    x.Resolve(b);
                }
                return;
            }
            var a = e as assign;

            if (a != null)
            {
                var d = scope.Lookup(a.id);
                a.Untyped.AddAnnotation(
                    new DeclAnnotation {
                    reference = d
                });
                a.rhs.Resolve(scope);
                return;
            }
        }
Ejemplo n.º 2
0
        // Look up variables
        static decl Lookup(this block scope, string id)
        {
            decl local =
                (from d in scope.decl
                 where d.id == id
                 select d).FirstOrDefault();

            if (local != null)
            {
                return(local);
            }
            block up = null;

            try {
                up = scope.Untyped.Annotation <BlockAnnotation>().reference;
            }
            catch (Exception) {
                // Undeclared variable
                throw new InvalidOperationException();
            }
            return(up.Lookup(id));
        }