Example #1
0
        private bool ParametersMatch(SignatureDescriptor sig,
                                     List <TypeDescriptor> param)
        {
            Boolean matchFound = false;
            List <TypeDescriptor> sigParam;

            // check each signature type in sig
            while (sig != null && !matchFound)
            {
                matchFound = true;
                sigParam   = sig.ParameterTypes;

                //check current signature parameters against param
                if (PRINT_STATUS)
                {
                    Console.WriteLine("   Beginning signature comparison:");
                }
                if (sigParam.Count == param.Count)
                {
                    for (int i = 0; i < param.Count; i++)
                    {
                        if (PRINT_STATUS)
                        {
                            Console.Write("\tComparing " + GetSimpleName(sigParam[i]) +
                                          " & " + GetSimpleName(param[i]));
                        }
                        if (!TypesCompatible(sigParam[i], param[i]))
                        {
                            matchFound = false;
                        }
                    }
                }
                else
                {
                    matchFound = false;
                }
                if (PRINT_STATUS)
                {
                    Console.WriteLine(" Match? " + matchFound);
                }
                sig = sig.Next; // go to next signature type
            }
            return(matchFound);
        }
Example #2
0
 public MethodTypeDescriptor()
 {
     Signature = new SignatureDescriptor();
 }
Example #3
0
        private void VisitNode(MethodCall node)
        {
            AbstractNode methodReference = node.Child;
            AbstractNode argumentList    = methodReference.Sib; // may be null

            TypeDescriptor descriptor;

            QualifiedName qualifiedName = methodReference as QualifiedName;

            if (qualifiedName == null)
            {
                descriptor = new ErrorDescriptor
                                 ("Only Qualified Name supported for Method Call reference");
            }
            else
            {
                // get parameters from method call
                List <TypeDescriptor> argListTypes =
                    GetParameterTypes(argumentList as ArgumentList);

                // get parameters (signature) from declared method
                Attributes           attr             = Table.lookup(qualifiedName.GetStringName());
                MethodTypeDescriptor methodDescriptor =
                    attr.TypeDescriptor as MethodTypeDescriptor;

                if (methodDescriptor != null)
                {
                    SignatureDescriptor methodSignature = methodDescriptor.Signature;

                    if (methodSignature != null &&
                        ParametersMatch(methodSignature, argListTypes))
                    {
                        // method descriptor for only current signature
                        MethodTypeDescriptor temp = new MethodTypeDescriptor();
                        temp.ReturnType = methodDescriptor.ReturnType;
                        temp.Signature.ParameterTypes = argListTypes;
                        temp.Signature.Next           = null;
                        descriptor = temp;
                    }
                    else if (methodSignature == null)
                    {
                        descriptor = new ErrorDescriptor
                                         ("No signature found for method: " +
                                         qualifiedName.GetStringName());
                    }
                    else
                    {
                        descriptor = new ErrorDescriptor
                                         ("No method signature found matching: (" +
                                         String.Join(", ", argListTypes) + ")");
                    }
                }
                else
                {
                    descriptor = new ErrorDescriptor("Method not declared: " +
                                                     qualifiedName.GetStringName());
                }
                node.TypeDescriptor = descriptor;
                Attributes methodCallAttr = new Attr(descriptor);
                methodCallAttr.Kind = Kind.MethodType;
                node.AttributesRef  = methodCallAttr;
            }
        }
Example #4
0
        private void setBaseline()
        {
            ScopeTable currScopeTable = symbolTable.Pop();
            // Until given additional info, Java objects are placeholders
            Attr javaAttr = new Attr(new JavaObjectDescriptor());

            javaAttr.Kind = Kind.TypeAttributes;
            currScopeTable.Add("java", javaAttr);
            currScopeTable.Add("io", javaAttr);
            currScopeTable.Add("lang", javaAttr);
            currScopeTable.Add("System", javaAttr);
            currScopeTable.Add("out", javaAttr);
            currScopeTable.Add("print", javaAttr);
            currScopeTable.Add("outint", javaAttr);
            currScopeTable.Add("PrintStream", javaAttr);
            currScopeTable.Add("TestClasses", javaAttr);

            // primitive types
            PrimitiveAttributes primVoidAttrs =
                new PrimitiveAttributes(new PrimitiveTypeVoidDescriptor());

            currScopeTable.Add("VOID", primVoidAttrs);
            PrimitiveAttributes primIntAttrs =
                new PrimitiveAttributes(new PrimitiveTypeIntDescriptor());

            currScopeTable.Add("INT", primIntAttrs);
            PrimitiveAttributes primBooleanAttrs =
                new PrimitiveAttributes(new PrimitiveTypeBooleanDescriptor());

            currScopeTable.Add("BOOLEAN", primBooleanAttrs);

            // special names
            SpecialNameAttributes spNameThis = new SpecialNameAttributes
                                                   (SpecialNameEnums.THIS);

            currScopeTable.Add(spNameThis.Name, spNameThis);
            SpecialNameAttributes spNameNull = new SpecialNameAttributes(
                SpecialNameEnums.NULL);

            currScopeTable.Add(spNameNull.Name, spNameNull);

            // Write & WriteLine
            PrimitiveTypeVoidDescriptor returnType = new PrimitiveTypeVoidDescriptor();
            // no parameters
            SignatureDescriptor sigDescNone = new SignatureDescriptor();
            // integer parameter
            SignatureDescriptor sigDescInt = new SignatureDescriptor();

            sigDescInt.AddParameter(new PrimitiveTypeIntDescriptor());
            // boolean parameter
            SignatureDescriptor sigDescBoolean = new SignatureDescriptor();

            sigDescBoolean.AddParameter(new PrimitiveTypeBooleanDescriptor());
            // literal parameter (string)
            SignatureDescriptor sigDescLiteral = new SignatureDescriptor();

            sigDescLiteral.AddParameter(new LiteralTypeDescriptor());
            // chain signature type descriptors together (sigDescNode = first)
            sigDescNone.Next    = sigDescInt;
            sigDescInt.Next     = sigDescBoolean;
            sigDescBoolean.Next = sigDescLiteral;
            MethodTypeDescriptor methodTypeDescriptor = new MethodTypeDescriptor();

            methodTypeDescriptor.ReturnType = returnType;
            methodTypeDescriptor.Signature  = sigDescNone;
            Attr methodAttr = new Attr(methodTypeDescriptor);

            currScopeTable.Add("Write", methodAttr);
            currScopeTable.Add("WriteLine", methodAttr);

            // TODO: add additional baseline information

            symbolTable.Push(currScopeTable);
        }