コード例 #1
0
        private string GetIlType(TypeDescriptor desc, AbstractNode typeSpec)
        {
            // either the return type is a primitive (can get from the signature)
            PrimitiveTypeIntDescriptor intDesc =
                desc as PrimitiveTypeIntDescriptor;
            NumberTypeDescriptor numDesc = desc as NumberTypeDescriptor;

            if (intDesc != null || numDesc != null)
            {
                return("int32");
            }
            PrimitiveTypeStringDescriptor stringDesc =
                desc as PrimitiveTypeStringDescriptor;
            LiteralTypeDescriptor litDesc = desc as LiteralTypeDescriptor;

            if (stringDesc != null || litDesc != null)
            {
                return("string");
            }
            PrimitiveTypeBooleanDescriptor boolDesc =
                desc as PrimitiveTypeBooleanDescriptor;

            if (boolDesc != null)
            {
                return("bool");
            }
            PrimitiveTypeVoidDescriptor voidDesc =
                desc as PrimitiveTypeVoidDescriptor;

            if (voidDesc != null)
            {
                return("void");
            }

            // or it is a qualified name (can extract from the node)
            QualifiedName qName = typeSpec as QualifiedName;

            if (qName != null)
            {
                return(qName.GetStringName());
            }

            // or it is an error
            ErrorDescriptor err = desc as ErrorDescriptor;

            if (err != null)
            {
                return(err.Message);
            }

            return("");
        }
コード例 #2
0
        private string GetIlType(TypeDescriptor desc)
        {
            // either the return type is a primitive (can get from the signature)
            PrimitiveTypeIntDescriptor intDesc =
                desc as PrimitiveTypeIntDescriptor;
            NumberTypeDescriptor numDesc = desc as NumberTypeDescriptor;

            if (intDesc != null || numDesc != null)
            {
                return("int32");
            }
            PrimitiveTypeStringDescriptor stringDesc =
                desc as PrimitiveTypeStringDescriptor;
            LiteralTypeDescriptor litDesc = desc as LiteralTypeDescriptor;

            if (stringDesc != null || litDesc != null)
            {
                return("string");
            }
            PrimitiveTypeBooleanDescriptor boolDesc =
                desc as PrimitiveTypeBooleanDescriptor;

            if (boolDesc != null)
            {
                return("bool");
            }
            PrimitiveTypeVoidDescriptor voidDesc =
                desc as PrimitiveTypeVoidDescriptor;

            if (voidDesc != null)
            {
                return("void");
            }

            // or it is an error
            ErrorDescriptor err = desc as ErrorDescriptor;

            if (err != null)
            {
                return(err.Message);
            }

            return("");
        }
コード例 #3
0
 public PrimitiveTypeVoid()
 {
     TypeDescriptor = new PrimitiveTypeVoidDescriptor();
 }
コード例 #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);
        }