Ejemplo n.º 1
0
 public virtual bool IsSupertype(InternalType checkType)
 {
     /* This method should never return a value itself, but rather call the appropriate overload for the
      *  concrete type of checkType */
     dynamic realType = checkType;
     return this.IsSupertype(realType);
 }
 /// <summary>
 /// Takes a type and the index in the function of a parameter
 /// </summary>
 public ActualDescriptor(InternalType type, string modifier = null, string name = null)
     : base(type)
 {
     Type = type;
     Modifier = modifier;
     Name = name;
 }
 public MemberDescriptor(InternalType type, string name, ClassDescriptor cls)
     : base(type)
 {
     Modifiers = new List<string>();
     Name = name;
     ContainingClass = cls;
 }
Ejemplo n.º 4
0
        public ClassDescriptor AddClass(string name, InternalType t)
        {
            var cd = new ClassDescriptor(t, name, CurrentScope);

            CurrentScope.Descriptors.Add(name, cd);
            return(cd);
        }
Ejemplo n.º 5
0
 public ClassDescriptor(InternalType t, string name, Scope s) : base(t)
 {
     Methods = new List <MethodDescriptor>();
     Fields  = new List <MemberDescriptor>();
     Name    = name;
     Scope   = s;
 }
Ejemplo n.º 6
0
 public MemberDescriptor AddMember(string name, InternalType type, TypeClass containingClass)
 {
     var descriptor = new MemberDescriptor(type, name, containingClass.Descriptor);
     CurrentScope.Descriptors.Add(name, descriptor);
     containingClass.Descriptor.Fields.Add(descriptor);
     return descriptor;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Takes a type and the index in the function of a parameter
 /// </summary>
 public ActualDescriptor(InternalType type, string modifier = null, string name = null)
     : base(type)
 {
     Type     = type;
     Modifier = modifier;
     Name     = name;
 }
Ejemplo n.º 8
0
        public MemberDescriptor AddMember(string name, InternalType type, TypeClass containingClass)
        {
            var descriptor = new MemberDescriptor(type, name, containingClass.Descriptor);

            CurrentScope.Descriptors.Add(name, descriptor);
            containingClass.Descriptor.Fields.Add(descriptor);
            return(descriptor);
        }
Ejemplo n.º 9
0
        public virtual bool IsSupertype(InternalType checkType)
        {
            /* This method should never return a value itself, but rather call the appropriate overload for the
             *  concrete type of checkType */
            dynamic realType = checkType;

            return(this.IsSupertype(realType));
        }
 public ClassDescriptor(InternalType t, string name, Scope s)
     : base(t)
 {
     Methods = new List<MethodDescriptor>();
     Fields = new List<MemberDescriptor>();
     Name = name;
     Scope = s;
 }
 public MethodDescriptor(InternalType t, string name, ClassDescriptor cls)
     : base(t)
 {
     IsCompleted = false;
     Modifiers = new List<string>();
     Formals = new List<FormalDescriptor>();
     Name = name;
     ContainingClass = cls;
 }
Ejemplo n.º 12
0
 public MethodDescriptor(InternalType t, string name, ClassDescriptor cls)
     : base(t)
 {
     IsCompleted     = false;
     Modifiers       = new List <string>();
     Formals         = new List <FormalDescriptor>();
     Name            = name;
     ContainingClass = cls;
 }
 protected InternalMethod(string name, InternalType returnType, Dictionary<string, InternalType> formals)
 {
     Name = name;
     FuncInfo = new TypeFunction(name)
     {
         ReturnType = returnType,
         Formals = formals
     };
 }
Ejemplo n.º 14
0
        public MethodDescriptor AddMethod(string name, InternalType type, TypeClass containingClass, List<String> modifiers = null, bool isInternal = false)
        {
            var md = new MethodDescriptor(type, name, containingClass.Descriptor) {IsInternalMethod = isInternal};

            if (modifiers != null)
                md.Modifiers.AddRange(modifiers);

            CurrentScope.Descriptors.Add(name, md);
            containingClass.Descriptor.Methods.Add(md);
            return md;
        }
Ejemplo n.º 15
0
        public MethodDescriptor AddMethod(string name, InternalType type, TypeClass containingClass, List <String> modifiers = null, bool isInternal = false)
        {
            var md = new MethodDescriptor(type, name, containingClass.Descriptor)
            {
                IsInternalMethod = isInternal
            };

            if (modifiers != null)
            {
                md.Modifiers.AddRange(modifiers);
            }

            CurrentScope.Descriptors.Add(name, md);
            containingClass.Descriptor.Methods.Add(md);
            return(md);
        }
Ejemplo n.º 16
0
 private static string TypeToFriendlyName(InternalType t)
 {
     return t.IsClass ? ((TypeClass)t).ClassName : t.ToString();
 }
Ejemplo n.º 17
0
 private static InternalType Supertype(InternalType t1, InternalType t2)
 {
     return t1.IsSupertype(t2) ? t2 : t2.IsSupertype(t1) ? t1 : null;
 }
Ejemplo n.º 18
0
 public override void VisitStringLiteral(StringLiteral n)
 {
     n.InternalType = _lastSeenType = new TypeString();
 }
Ejemplo n.º 19
0
 public override void VisitRealLiteral(RealLiteral n)
 {
     n.InternalType = _lastSeenType = new TypeReal();
 }
Ejemplo n.º 20
0
 public override void VisitQualifier(Qualifier n)
 {
     n.Expression.Visit(this);
     switch(n.Type.ToLower())
     {
         case "date":
             _lastSeenType = n.InternalType = new TypeDate();
             break;
         case "real":
             _lastSeenType = n.InternalType = new TypeReal();
             break;
         case "integer":
             _lastSeenType = n.InternalType = new TypeInteger();
             break;
         case "string":
             _lastSeenType = n.InternalType = new TypeString();
             break;
         case "boolean":
             _lastSeenType = n.InternalType = new TypeBoolean();
             break;
         default:
             throw new Exception("Unknown type qualifier: (" + n.Type + ")");
     }
 }
Ejemplo n.º 21
0
 public override void VisitBooleanLiteral(BooleanLiteral n)
 {
     n.InternalType = _lastSeenType = new TypeBoolean();
 }
Ejemplo n.º 22
0
        public override void VisitIdentifier(Identifier n)
        {
            if (_mgr.HasSymbol(n.Id))
            {
                var d = _mgr.GetType(n.Id);
                n.Descriptor = d;
                n.InternalType = d.Type;

                _lastSeenType = d.Type;
            }
            else
            {
                ReportError(n.Location, "Identifier '{0}' has not been declared.", n.Id);
            }
        }
Ejemplo n.º 23
0
        public override void VisitDereferenceField(DereferenceField n)
        {
            //lvalue.identifier
            var lhs = CheckSubTree(n.Object);

            if(!(lhs is TypeClass))
            {
                var members = lhs.CilType.GetMembers();
                var thisProperty = members.FirstOrDefault(p => p.Name.Equals(n.Field, StringComparison.OrdinalIgnoreCase));

                if (thisProperty == null)
                    throw new Exception(string.Format("Attribute {0} not available on type {1} (object {2})", n.Field,
                                                      lhs.CilType, n.Object));

                switch(lhs.CilType.GetProperty("Days").PropertyType.Name)
                {
                    case "Int32":
                        n.InternalType = _lastSeenType = new TypeInteger();
                        break;
                    case "DateTime":
                        n.InternalType = _lastSeenType = new TypeDate();
                        break;
                    case "String":
                        n.InternalType = _lastSeenType = new TypeString();
                        break;
                    case "Double":
                        n.InternalType = _lastSeenType = new TypeReal();
                        break;
                    case "Boolean":
                        n.InternalType = _lastSeenType = new TypeBoolean();
                        break;
                }
            }
        }
Ejemplo n.º 24
0
 public void AddField(string name, InternalType type)
 {
     Fields.Add(name, type);
 }
Ejemplo n.º 25
0
 public void AddMethod(string name, InternalType type)
 {
     Methods.Add(name, type);
 }
Ejemplo n.º 26
0
 public MemberDescriptor(InternalType type, string name, ClassDescriptor cls) : base(type)
 {
     Modifiers       = new List <string>();
     Name            = name;
     ContainingClass = cls;
 }
Ejemplo n.º 27
0
 private InternalType CheckSubTree(Node root)
 {
     _lastSeenType = null;
     root.Visit(this);
     return _lastSeenType;
 }
Ejemplo n.º 28
0
 public override void VisitIncrement(Increment n)
 {
     _lastSeenType = n.InternalType = TypeCheckIncrementDecrement(n.Expression, "++", n.Location);
 }
Ejemplo n.º 29
0
        private void VisitBinaryArithmetic(BinaryExpression n)
        {
            var lhs = CheckSubTree(n.Left);
            var rhs = CheckSubTree(n.Right);

            if (lhs.IsNumeric && rhs.IsNumeric)
            {
                _lastSeenType = n.InternalType = Supertype(lhs, rhs);
            }
            else if(lhs.CilType == typeof(DateTime) && rhs.CilType == typeof(DateTime))
            {
                _lastSeenType = n.InternalType = new TypeSpan();
            }
            else
            {
                ReportError(n.Location, "Invalid operands for operation {0}. Got types '{1}' and '{2}'.", n.GetType().ToString(), TypeToFriendlyName(lhs), TypeToFriendlyName(rhs));
            }
        }
Ejemplo n.º 30
0
 public override void VisitIntegerLiteral(IntegerLiteral n)
 {
     n.InternalType = _lastSeenType = new TypeInteger();
 }
Ejemplo n.º 31
0
 public void AddMethod(string name, InternalType type)
 {
     Methods.Add(name, type);
 }
Ejemplo n.º 32
0
        public Type LookupCilType(InternalType type)
        {
            if (type is TypeClass)
            {
                var name = (type as TypeClass).ClassName;
                return TypeBuilderMap[name].Builder;
            }

            return type.CilType;
        }
Ejemplo n.º 33
0
 public void AddField(string name, InternalType type)
 {
     Fields.Add(name, type);
 }
Ejemplo n.º 34
0
 public ClassDescriptor AddClass(string name, InternalType t)
 {
     var cd = new ClassDescriptor(t, name, CurrentScope);
     CurrentScope.Descriptors.Add(name, cd);
     return cd;
 }