示例#1
0
        public IType checkAssignMember(Context context, String memberName, IType valueType)
        {
            INamed actual = context.getRegisteredValue <INamed>(name);

            if (actual == null)
            {
                throw new SyntaxError("Unknown variable:" + this.name);
            }
            IType thisType = actual.GetIType(context);

            if (thisType is DocumentType)
            {
                return(valueType);
            }
            else
            {
                if (thisType is CategoryType && !((CategoryType)thisType).Mutable)
                {
                    throw new SyntaxError("Not mutable:" + this.name);
                }
                IType requiredType = thisType.checkMember(context, memberName);
                if (requiredType != null && !requiredType.isAssignableFrom(context, valueType))
                {
                    throw new SyntaxError("Incompatible types:" + requiredType.GetTypeName() + " and " + valueType.GetTypeName());
                }
                return(valueType);
            }
        }
示例#2
0
        public IType check(Context context)
        {
            IType type = expression.check(context);

            if (type != TupleType.Instance)
            {
                throw new SyntaxError("Expecting a tuple expression, got " + type.GetTypeName());
            }
            foreach (String name in names)
            {
                INamed actual = context.getRegistered(name);
                if (actual == null)
                {
                    IType actualType = expression.check(context);
                    context.registerValue(new Variable(name, actualType));
                }
                else
                {
                    // need to check type compatibility
                    IType actualType = actual.GetIType(context);
                    IType newType    = expression.check(context);
                    actualType.checkAssignableFrom(context, newType);
                }
            }
            return(VoidType.Instance);
        }
示例#3
0
 public Context downcast(Context context, bool setValue)
 {
     if (oper == EqOp.IS_A)
     {
         String name = readLeftName();
         if (name != null)
         {
             INamed value      = context.getRegisteredValue <INamed>(name);
             IType  targetType = ((TypeExpression)right).getType().Resolve(context);
             IType  sourceType = value.GetIType(context);
             if (sourceType.IsMutable(context))
             {
                 targetType = targetType.AsMutable(context, true);
             }
             Context local = context.newChildContext();
             value = new LinkedVariable(targetType, value);
             local.registerValue(value, false);
             if (setValue)
             {
                 local.setValue(name, new LinkedValue(context, targetType));
             }
             context = local;
         }
     }
     return(context);
 }
示例#4
0
        public override IType check(Context context)
        {
            INamed named = context.getRegistered(name);

            if (named == null)
            {
                named = context.getRegisteredDeclaration <IDeclaration>(name);
            }
            if (named == null)
            {
                throw new SyntaxError("Unknown identifier:" + name);
            }
            else if (named is Variable) // local variable
            {
                return(named.GetIType(context));
            }
            else if (named is LinkedVariable)            // local variable
            {
                return(named.GetIType(context));
            }
            else if (named is IParameter) // named argument
            {
                return(named.GetIType(context));
            }
            else if (named is CategoryDeclaration) // any p with x
            {
                return(named.GetIType(context));
            }
            else if (named is AttributeDeclaration) // in category method
            {
                return(named.GetIType(context));
            }
            else if (named is MethodDeclarationMap)               // global method or closure
            {
                IEnumerator <IMethodDeclaration> decls = ((MethodDeclarationMap)named).Values.GetEnumerator();
                decls.MoveNext();
                return(new MethodType(decls.Current));
            }
            else
            {
                throw new SyntaxError(name + "  is not a value or method:" + named.GetType().Name);
            }
        }
示例#5
0
        public IType checkAssignItem(Context context, IType itemType, IType valueType)
        {
            INamed actual = context.getRegisteredValue <INamed>(name);

            if (actual == null)
            {
                throw new SyntaxError("Unknown variable:" + this.name);
            }
            IType parentType = actual.GetIType(context);

            return(parentType.checkItem(context, itemType));
        }
示例#6
0
        public IType checkAssignValue(Context context, IType valueType)
        {
            INamed actual = context.getRegisteredValue <INamed>(name);

            if (actual == null)
            {
                context.registerValue(new Variable(name, valueType));
            }
            else
            {
                // need to check type compatibility
                IType actualType = actual.GetIType(context);
                actualType.checkAssignableFrom(context, valueType);
                valueType = actualType;
            }
            return(valueType);
        }
示例#7
0
        IType check_instance(Context context)
        {
            INamed named = context.getRegisteredValue <INamed>(name);

            if (named == null)
            {
                return(null);
            }
            try
            {
                return(named.GetIType(context));
            }
            catch (SyntaxError)
            {
                return(null);
            }
        }
示例#8
0
        public IType check(Context context)
        {
            INamed actual = context.getRegisteredValue <INamed>(Parameter.GetName());

            if (actual == null)
            {
                IType actualType = getExpression().check(context);
                context.registerValue(new Variable(Parameter.GetName(), actualType));
            }
            else
            {
                // need to check type compatibility
                IType actualType = actual.GetIType(context);
                IType newType    = getExpression().check(context);
                actualType.checkAssignableFrom(context, newType);
            }
            return(VoidType.Instance);
        }
示例#9
0
        private IExpression resolveUnresolvedMethodReference(Context context, string name)
        {
            INamed named = context.getRegisteredValue <INamed>(name);

            if (named == null)
            {
                return(null);
            }
            IType type = named.GetIType(context).Resolve(context);

            if (type is MethodType)
            {
                MethodCall call = new MethodCall(new MethodSelector(name), arguments);
                call.setVariableName(name);
                return(call);
            }
            else
            {
                return(null);
            }
        }
示例#10
0
        public IMethodDeclaration findCandidateReference(bool checkInstance)
        {
            MethodSelector selector = methodCall.getSelector();

            if (selector.getParent() != null)
            {
                return(null);
            }
            if (checkInstance)
            {
                if (context.hasValue(selector.getName()))
                {
                    IValue value = context.getValue(selector.getName());
                    if (value is ClosureValue)
                    {
                        return(getClosureDeclaration(context, (ClosureValue)value));
                    }

                    else if (value is ArrowValue)
                    {
                        return(getArrowDeclaration((ArrowValue)value));
                    }
                }
            }
            else
            {
                INamed named = context.getInstance(selector.getName(), true);
                if (named == null)
                {
                    return(null);
                }
                IType type = named.GetIType(context).Resolve(context);
                if (type is MethodType)
                {
                    return(((MethodType)type).Method.AsReference());
                }
            }
            return(null);
        }
示例#11
0
        public IType checkResource(Context context)
        {
            IType type = expression.check(context);

            if (!(type is ResourceType))
            {
                throw new SyntaxError("Not a resource!");
            }
            INamed actual = context.getRegisteredValue <INamed>(name);

            if (actual == null)
            {
                context.registerValue(new Variable(name, type));
            }
            else
            {
                // need to check type compatibility
                IType actualType = actual.GetIType(context);
                actualType.checkAssignableFrom(context, type);
            }
            return(VoidType.Instance);
        }