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; }
public ClassDescriptor AddClass(string name, InternalType t) { var cd = new ClassDescriptor(t, name, CurrentScope); CurrentScope.Descriptors.Add(name, cd); return(cd); }
public ClassDescriptor(InternalType t, string name, Scope s) : base(t) { Methods = new List <MethodDescriptor>(); Fields = new List <MemberDescriptor>(); Name = name; Scope = s; }
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; }
/// <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 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); }
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; }
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 }; }
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; }
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); }
private static string TypeToFriendlyName(InternalType t) { return t.IsClass ? ((TypeClass)t).ClassName : t.ToString(); }
private static InternalType Supertype(InternalType t1, InternalType t2) { return t1.IsSupertype(t2) ? t2 : t2.IsSupertype(t1) ? t1 : null; }
public override void VisitStringLiteral(StringLiteral n) { n.InternalType = _lastSeenType = new TypeString(); }
public override void VisitRealLiteral(RealLiteral n) { n.InternalType = _lastSeenType = new TypeReal(); }
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 + ")"); } }
public override void VisitBooleanLiteral(BooleanLiteral n) { n.InternalType = _lastSeenType = new TypeBoolean(); }
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); } }
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; } } }
public void AddField(string name, InternalType type) { Fields.Add(name, type); }
public void AddMethod(string name, InternalType type) { Methods.Add(name, type); }
public MemberDescriptor(InternalType type, string name, ClassDescriptor cls) : base(type) { Modifiers = new List <string>(); Name = name; ContainingClass = cls; }
private InternalType CheckSubTree(Node root) { _lastSeenType = null; root.Visit(this); return _lastSeenType; }
public override void VisitIncrement(Increment n) { _lastSeenType = n.InternalType = TypeCheckIncrementDecrement(n.Expression, "++", n.Location); }
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)); } }
public override void VisitIntegerLiteral(IntegerLiteral n) { n.InternalType = _lastSeenType = new TypeInteger(); }
public void AddMethod(string name, InternalType type) { Methods.Add(name, type); }
public Type LookupCilType(InternalType type) { if (type is TypeClass) { var name = (type as TypeClass).ClassName; return TypeBuilderMap[name].Builder; } return type.CilType; }
public void AddField(string name, InternalType type) { Fields.Add(name, type); }
public ClassDescriptor AddClass(string name, InternalType t) { var cd = new ClassDescriptor(t, name, CurrentScope); CurrentScope.Descriptors.Add(name, cd); return cd; }