internal static MethodSymbol CreateAndDefineMethod(string name, IType type, IMethodScope scope)
 {
     var sym = new MethodSymbol(name, type, scope);
     scope.Define(sym);
     return sym;
 }
        private void SetUpArrayBase()
        {
            var anyTypeSym = TypeSymbol.MakeScalarTypeSymbol(
                MiniJavaInfo.AnyType, _globalScope);
            _globalScope.Define(anyTypeSym);
            var arrayBaseSym = TypeSymbol.MakeArrayTypeSymbol(
                (ScalarType)anyTypeSym.Type, _globalScope);
            _globalScope.Define(arrayBaseSym);

            var intType = _globalScope.ResolveType(MiniJavaInfo.IntType).Type;
            var arrayBaseScope = (IMethodScope)arrayBaseSym.Scope;

            foreach (string methodName in MiniJavaInfo.ArrayMethodNames())
            {
                var methodSym = new MethodSymbol(methodName, intType, arrayBaseScope, false);
                arrayBaseScope.Define(methodSym);
            }
        }
            private void CheckForOverloading(MethodDeclaration node,
                TypeSymbol classSymbol, MethodSymbol superClassMethod)
            {
                var superClassMethodDeclaration = (MethodDeclaration)superClassMethod.Declaration;
                if (OverloadsSuperClassMethod(node, superClassMethodDeclaration))
                {
                    var msg = String.Format("Method {0} in class {1} overloads a method in class {2}. Overloading is not allowed.",
                        node.Name, classSymbol.Name, classSymbol.SuperClass.Name);
                    ReportError(ErrorTypes.InvalidOverride, msg, node);
                }

                // Subclass methods CANNOT have covariant return types with respect to overridden
                // superclass methods, though this is allowed in Java. This is because the .NET runtime
                // does not natively support them. (Reference link can be found in tests and docs.)
                if (node.Type != superClassMethodDeclaration.Type)
                {
                    var msg = String.Format(
                        "Method {0} in class {1} has a different return type from overridden method in class {2}.",
                        node.Name, classSymbol.Name, classSymbol.SuperClass.Name);
                    ReportError(ErrorTypes.InvalidOverride, msg, node);
                }
            }
 private void CheckReturnTypes(MethodDeclaration node, MethodSymbol method)
 {
     while (_returnTypes.Count > 0)
     {
         var returnType = _returnTypes.Pop();
         if (!returnType.IsAssignableTo(method.Type))
         {   // The type of object returned by the return statement
             // must match the method's declared return type.
             ReportError(ErrorTypes.TypeError,
                 String.Format("Cannot convert expression of type {0} to {1}.",
                 returnType.Name, method.Type.Name), node);
         }
     }
 }
示例#5
0
 public new bool Define(MethodSymbol sym)
 {
     return base.Define(sym);
 }