Exemplo n.º 1
0
        private void registerMethod(IMethodDeclaration method, Context context)
        {
            IDeclaration actual;

            if (method is SetterMethodDeclaration)
            {
                if (methodsMap.TryGetValue("setter:" + method.GetName(), out actual))
                {
                    throw new SyntaxError("Duplicate setter: \"" + method.GetName() + "\"");
                }
                methodsMap["setter:" + method.GetName()] = method;
            }
            else if (method is GetterMethodDeclaration)
            {
                if (methodsMap.TryGetValue("getter:" + method.GetName(), out actual))
                {
                    throw new SyntaxError("Duplicate getter: \"" + method.GetName() + "\"");
                }
                methodsMap["getter:" + method.GetName()] = method;
            }
            else
            {
                if (!methodsMap.TryGetValue(method.GetName(), out actual))
                {
                    actual = new MethodDeclarationMap(method.GetName());
                    methodsMap[method.GetName()] = (MethodDeclarationMap)actual;
                }
                ((MethodDeclarationMap)actual).register(method, context);
            }
        }
Exemplo n.º 2
0
        private static IType getTargetAtomicType(Context context, IType type)
        {
            IDeclaration decl = context.getRegisteredDeclaration <IDeclaration>(type.GetTypeName());

            if (decl == null)
            {
                throw new SyntaxError("Unknown identifier: " + type.GetTypeName());
            }
            else if (decl is MethodDeclarationMap)
            {
                MethodDeclarationMap map = (MethodDeclarationMap)decl;
                if (map.Count == 1)
                {
                    return(new MethodType(map.GetFirst()));
                }
                else
                {
                    throw new SyntaxError("Ambiguous identifier: " + type.GetTypeName());
                }
            }
            else
            {
                return(decl.GetIType(context));
            }
        }
Exemplo n.º 3
0
        public override ISet <IMethodDeclaration> GetMethodDeclarations(Context context)
        {
            HashSet <IMethodDeclaration> result = new HashSet <IMethodDeclaration>();

            foreach (IType type in types)
            {
                if (type is MethodType)
                {
                    MethodDeclarationMap decls = context.getRegisteredDeclaration <MethodDeclarationMap>(type.GetTypeName());
                    if (decls != null)
                    {
                        foreach (IMethodDeclaration decl in decls.Values)
                        {
                            result.Add(decl);
                        }
                    }
                }
            }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(base.GetMethodDeclarations(context));
            }
        }
Exemplo n.º 4
0
        public override MethodDeclarationMap getMemberMethods(Context context, String name)
        {
            registerMethods(context);
            MethodDeclarationMap result = new MethodDeclarationMap(name);

            registerMemberMethods(context, result);
            return(result);
        }
Exemplo n.º 5
0
 private void registerDerivedMemberMethods(Context context, MethodDeclarationMap result)
 {
     if (derivedFrom == null)
     {
         return;
     }
     foreach (String ancestor in derivedFrom)
     {
         registerAncestorMemberMethods(ancestor, context, result);
     }
 }
Exemplo n.º 6
0
 public override ISet <IMethodDeclaration> GetMethodDeclarations(Context context)
 {
     if (type is MethodType)
     {
         MethodDeclarationMap decls = context.getRegisteredDeclaration <MethodDeclarationMap>(type.GetTypeName());
         if (decls != null)
         {
             return(new HashSet <IMethodDeclaration>(decls.Values.Select(m => m.AsReference())));
         }
     }
     return(base.GetMethodDeclarations(context));
 }
Exemplo n.º 7
0
        private void registerAncestorMemberMethods(String ancestor, Context context, MethodDeclarationMap result)
        {
            IDeclaration actual = context.getRegisteredDeclaration <IDeclaration>(ancestor);

            if (actual == null || !(actual is ConcreteCategoryDeclaration))
            {
                return;
            }
            ConcreteCategoryDeclaration cd = (ConcreteCategoryDeclaration)actual;

            cd.registerMemberMethods(context, result);
        }
Exemplo n.º 8
0
        private IMethodDeclaration getAbstractMethodDeclaration(Context context)
        {
            MethodDeclarationMap methods = context.getRegisteredDeclaration <MethodDeclarationMap>(type.GetTypeName());

            if (methods != null)
            {
                return(methods.Values.FirstOrDefault(decl => decl.isAbstract()));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 9
0
        private bool globalMethodExists(Context context, String name)
        {
            MethodDeclarationMap methods = context.getRegisteredDeclaration <MethodDeclarationMap>(name);

            if (methods == null)
            {
                return(false);
            }
            else
            {
                return(methods.ContainsKey(this.GetTypeName()));
            }
        }
Exemplo n.º 10
0
        private IDeclaration resolveUnresolvedMember(InstanceContext context, String name)
        {
            ConcreteCategoryDeclaration decl    = context.getRegisteredDeclaration <ConcreteCategoryDeclaration>(context.getInstanceType().GetTypeName());
            MethodDeclarationMap        methods = decl.getMemberMethods(context, name);

            if (methods != null && methods.Count > 0)
            {
                return(methods);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 11
0
        private IMethodDeclaration getDeclaration(Context context)
        {
            MethodDeclarationMap methods = context.getRegisteredDeclaration <MethodDeclarationMap>(name);

            if (methods != null)
            {
                IEnumerator <IMethodDeclaration> values = methods.Values.GetEnumerator();
                values.MoveNext();
                return(values.Current);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 12
0
        private void registerThisMemberMethods(Context context, MethodDeclarationMap result)
        {
            if (methodsMap == null)
            {
                return;
            }
            IDeclaration actual;

            if (!methodsMap.TryGetValue(result.GetName(), out actual))
            {
                return;
            }
            if (!(actual is MethodDeclarationMap))
            {
                throw new SyntaxError("Not a member method!");
            }
            foreach (IMethodDeclaration method in ((MethodDeclarationMap)actual).Values)
            {
                result.registerIfMissing(method, context);
            }
        }
Exemplo n.º 13
0
        public override IValue interpretReference(Context context)
        {
            // resolve parent to keep clarity
            IExpression parent   = resolveParent(context);
            IValue      instance = parent.interpret(context);

            if (instance == null || instance == NullValue.Instance)
            {
                throw new NullReferenceError();
            }
            else if (instance is IInstance)
            {
                CategoryDeclaration  category = ((IInstance)instance).getDeclaration();
                MethodDeclarationMap methods  = category.getMemberMethods(context, name);
                IMethodDeclaration   method   = methods.GetFirst();             // TODO check prototype
                return(new ClosureValue(context.newInstanceContext((IInstance)instance, true), new MethodType(method)));
            }
            else
            {
                throw new SyntaxError("Should never get here!");
            }
        }
Exemplo n.º 14
0
        private IMethodDeclaration getDeclaration(Context context)
        {
            IExpression expression = this.expression;

            if (expression is UnresolvedSelector)
            {
                IExpression parent = ((UnresolvedSelector)expression).getParent();
                if (parent != null)
                {
                    IType type = parent.check(context);
                    if (type is CategoryType)
                    {
                        expression = new UnresolvedIdentifier(((UnresolvedSelector)expression).getName(), Dialect.O);
                        context    = context.newInstanceContext((CategoryType)type, true);
                    }
                    else
                    {
                        return(null);                        // TODO report problem
                    }
                }
            }
            if (expression is UnresolvedIdentifier)
            {
                String name = ((UnresolvedIdentifier)expression).ToString();
                MethodDeclarationMap methods = context.getRegisteredDeclaration <MethodDeclarationMap>(name);
                if (methods != null)
                {
                    return(methods.GetFirst());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 15
0
        public void testBreakpoint()
        {
            debugResource("debug/stack.pec");
            thread.Start();
            waitBlocked();
            Assert.AreEqual(Status.SUSPENDED, debugger.getStatus());
            Assert.AreEqual(MAIN_LINE, debugger.getLine());
            MethodDeclarationMap             mdm = context.getRegisteredDeclaration <MethodDeclarationMap>("printLevel2");
            IEnumerator <IMethodDeclaration> emd = mdm.Values.GetEnumerator();

            emd.MoveNext();
            ConcreteMethodDeclaration cmd = (ConcreteMethodDeclaration)emd.Current;
            ISection section = cmd.getStatements()[0];

            Assert.AreEqual(LEVEL_2_LINE + 1, section.Start.Line);
            section.Breakpoint = true;
            debugger.resume();
            waitBlocked();
            Assert.AreEqual(Status.SUSPENDED, debugger.getStatus());
            Assert.AreEqual(LEVEL_2_LINE + 1, debugger.getLine());
            debugger.resume();
            thread.Join();
            Assert.AreEqual("test123-ok", Out.read());
        }
Exemplo n.º 16
0
 private void registerMemberMethods(Context context, MethodDeclarationMap result)
 {
     registerThisMemberMethods(context, result);
     registerDerivedMemberMethods(context, result);
 }