public static TypeArray New(TypeBase type, NodeBase count) { var ret = new TypeArray(); ret.Type = type; ret.count = count; return ret; }
public static VarDeclare Array(BlockBase parent, string name, TypeBase type, NodeBase count) { var ret = New(parent, name, null); ret.doneInferType = true; ret.type = TypeArray.New(type, count); return ret; }
public static TypeDelegate New( BlockBase parent, CallType callType, TypeBase retType, VarDeclare[] args) { var ret = new TypeDelegate(); ret.init(callType, retType, args); ret.Parent = parent; return ret; }
public static Define GetStruct(TypeBase t) { if (t == null) return null; if (t is TypeStruct) return (t as TypeStruct).GetStruct(); else return GetStruct(t.Type); }
public static TypeBase Cast(TypeBase t1, TypeBase t2) { if (t1 == null) return t2; if (t2 == null) return t1; var c1 = t1.Cast(t2); if (c1 != null) return c1; return t2.Cast(t1); }
public static TypePointer New(TypeBase type) { var ret = new TypePointer(); ret.Type = type; ret.conds["greater"] = CondPair.New(Cc.A, Cc.NA); ret.conds["greater-equal"] = CondPair.New(Cc.AE, Cc.NAE); ret.conds["less"] = CondPair.New(Cc.B, Cc.NB); ret.conds["less-equal"] = CondPair.New(Cc.BE, Cc.NBE); return ret; }
// cast public override TypeBase Cast(TypeBase type) { if (type is TypeSByte) return this; else if (type is TypeInt) return TypeInt.Instance; else if (type is TypeUInt) return TypeUInt.Instance; else if (type is TypeShort) return TypeShort.Instance; else if (type is TypeUShort) return TypeUShort.Instance; return null; }
protected void init(CallType callType, TypeBase retType, VarDeclare[] args) { CallType = callType; RetType = retType; var list = new ArrayList(); if (args == null) HasParams = true; else for (int i = 0; i < args.Length; i++) { var arg = args[i]; if (arg is ArgPtr) HasParams = true; else list.Add(arg); } var ret = new VarDeclare[list.Count]; for (int i = 0; i < ret.Length; i++) ret[i] = list[i] as VarDeclare; this.Args = ret; }
protected void init1(BlockBase parent, string name, TypeBase type) { Parent = parent; this.name = name; init2(); AddToParent(); if (type != null) { doneInferType = true; this.type = type; } }
protected virtual void init2() { if (type == null) type = TypeVar.Instance; IsMember = Parent is Define; if (Parent.Parent == null) IsStatic = true; }
public static TypeReference New(TypeBase type, bool isArray) { var ret = new TypeReference(); ret.Type = type; ret.isArray = isArray; return ret; }
public static new Arg New(BlockBase parent, string name, TypeBase type) { var ret = new Arg(); ret.init1(parent, name, type); return ret; }
// cast public override TypeBase Cast(TypeBase type) { if (type is TypePointer && type.Type is TypeChar) return type; return base.Cast(type); }
// cast public override TypeBase Cast(TypeBase type) { if (IsArray && type.Name == "var:object") return type; else if (type is TypeVar) return type; else if (type is TypeString && IsArray && Type is TypeChar) return type; else if (type is TypePointer && IsArray) { if (Type is TypeIntBase) { if (Type == type.Type) return type; } else if (Type.Cast(type.Type) != null) return type; } if (!(type is TypeReference)) return null; else if (Type is TypeReference && type.Type is TypeReference) { var c = Type.Cast(type.Type); if (c == null) return null; return Types.ToVarType(c); } else return base.Cast(type); }
// cast public override TypeBase Cast(TypeBase type) { return this; }
public static void Init() { type = null; }
public void AddDtorCodes(TypeBase t) { Add(I386.Push(Reg32.ESP)); t.AddDestructor(this); Add(I386.AddR(Reg32.ESP, Val32.New(8))); }
public void SetReturnType(TypeBase type) { doneInferReturnType = true; this.returnType = type; }
public static VarDeclare New(BlockBase parent, string name, TypeBase type) { var ret = new VarDeclare(); ret.init1(parent, name, type); return ret; }
public static TypeArray NewInt(TypeBase type, int count) { return New(type, IntValue.New(count)); }
// cast public virtual TypeBase Cast(TypeBase type) { var tr1 = this as TypeReference; var tr2 = type as TypeReference; if (tr1 == null && tr2 != null && tr2.UseGC) return null; var t1 = Type; var t2 = type.Type; if (t1 == t2) return type; var ts1 = t1 as TypeStruct; var ts2 = t2 as TypeStruct; if (ts1 == null || ts2 == null) return null; var st1 = ts1.GetStruct(); var st2 = ts2.GetStruct(); if (st1 == null || st2 == null) return null; if (st1 == st2 || st1.CanUpCast(st2)) return type; return null; }
// cast public override TypeBase Cast(TypeBase type) { if (type is TypeVar) return type; if (!(type is TypePointer)) return null; return base.Cast(type); }
public static TypeBase ToVarType(TypeBase t) { if (t == null) return TypeVar.Instance; else if (t is TypeStruct) { if (t.Name == "string") return TypeString.Instance; else return TypeReference.New(t, false); } else if (t is TypeArray) return TypePointer.New(t.Type); else if (t is TypeConstString) return TypeString.Instance; else return t; }
public Val32 GetTypeObject(TypeBase type) { var tr = type as TypeReference; if (tr != null) { var tt = type.Type; if (!tr.IsArray) return GetTypeObject(tt); var tts = tt as TypeStruct; Function dtor = null; string name = tt.Name; Val32 targetType = Val32.New(0); if (tt is TypeReference) { dtor = OpModule.Root.GetFunction(New.DereferencePtr); var at = tt.Type as TypeStruct; if (at != null) { name = at.Name; targetType = GetTypeObjectD(at.GetStruct()); } } else if (tts != null) { name = tts.Name; targetType = GetTypeObjectD(tts.GetStruct()); } return GetTypeObjectV(name + "[]", dtor, tt.Size, targetType); } var ts = type as TypeStruct; if (ts != null) { var st = ts.GetStruct(); return GetTypeObjectD(st); } return GetTypeObjectV(type.Name, null, type.Size, Val32.New(0)); }
// cast public override TypeBase Cast(TypeBase type) { if (type is TypeInt || type is TypeUShort || type is TypeByte) return this; return null; }
public void AddOperatorCodes(TypeBase tb, string op, Addr32 dest, NodeBase arg, bool pushf) { arg.AddCodesV(this, "mov", null); var cleanup = NeedsDtor(arg); if (cleanup) { Add(I386.Push(Reg32.EAX)); if (dest.Register == Reg32.ESP) dest = Addr32.NewRO(dest.Register, dest.Disp + 4); } tb.AddOpCodes(op, this, dest); if (cleanup) { if (pushf) { Add(I386.Pop(Reg32.EAX)); Add(I386.Pushf()); Add(I386.Push(Reg32.EAX)); } AddDtorCodes(arg.Type); if (pushf) Add(I386.Popf()); } }
// cast public override TypeBase Cast(TypeBase type) { if (type is TypeStruct) { if (GetStruct().CanUpCast((type as TypeStruct).GetStruct())) return type; return null; } else if (type is TypeReference) { if (Cast(type.Type) != null) return type; return null; } else if (type is TypeVar) return type; else return null; }