public Move(int _cost, int _power, Types.Type _type) { MoveID = new Guid(); Cost = _cost; Power = _power; Type = _type; }
/// <summary> /// Combines two types to create a new one /// </summary> /// <param name="right"></param> /// <returns></returns> public override Types.Type CombineType(Type right, BinaryExpression.OPERATOR Operator) { Types.Type retVal = null; if (Operator == BinaryExpression.OPERATOR.MULT) { if (FullName.CompareTo("Default.BaseTypes.Speed") == 0 && right.FullName.CompareTo("Default.BaseTypes.Time") == 0) { NameSpace nameSpace = EnclosingNameSpaceFinder.find(this); retVal = nameSpace.findTypeByName("Distance"); } } else { if (IsDouble()) { if (right == EFSSystem.DoubleType) { retVal = this; } } else { if (right == EFSSystem.IntegerType) { retVal = this; } } } return(retVal); }
// Token: 0x06000BB1 RID: 2993 RVA: 0x0001BBE6 File Offset: 0x00019DE6 public Builder SetType(Types.Type value) { PrepareBuilder(); result.HasType = true; result.type_ = value; return(this); }
/// <summary> /// Performs the semantic analysis of the statement /// </summary> /// <param name="instance">the reference instance on which this element should analysed</param> /// <returns>True if semantic analysis should be continued</returns> public override bool SemanticAnalysis(Utils.INamable instance) { bool retVal = base.SemanticAnalysis(instance); if (retVal) { ListExpression.SemanticAnalysis(instance); Types.Collection collectionType = ListExpression.GetExpressionType() as Types.Collection; if (collectionType != null) { IteratorVariable.Type = collectionType.Type; } Value.SemanticAnalysis(instance); Types.Type valueType = Value.GetExpressionType(); if (valueType != null) { if (!valueType.Match(collectionType.Type)) { AddError("Type of " + Value + " does not match collection type " + collectionType); } } else { AddError("Cannot determine type of " + Value); } if (Condition != null) { Condition.SemanticAnalysis(instance); } } return(retVal); }
Exp TranslateDeclaration(VariableDeclaration dec) { ExpressionType init = TranslateExpression(dec.Init); Types.Type type = null; if (dec.Type == null) { if (init.Type.CoerceTo(Types.Type._nil)) { Error.Report(dec.Init.Pos, "Unknown type cannot be initialized with 'nil'"); return(null); } else { type = init.Type; } } else { type = TranslateType(dec.Type).Actual; if (!init.Type.CoerceTo(type)) { Error.Report(dec.Init.Pos, "Type mismatch in variable initialization"); return(null); } } VariableEntry var = new VariableEntry(Level.AllocLocal(dec.Escape), type); Env.ValueEnvironment[dec.Name] = var; return(Translate.TranslateAssignExp(Translate.TranslateSimpleVar(var.Access, Level), init.Exp)); }
public void Visit(TypeMap type) { if (id < 0) { throw new Exception("invalie Variable.Id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + bufname + ".WriteInt(Zeze.ByteBuffer.MAP | " + id + " << Zeze.ByteBuffer.TAG_SHIFT);"); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " var _state_ = _os_.BeginWriteSegment();"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(keytype) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(valuetype) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + varname + ".size);"); string tmpvarname = Program.GenUniqVarName(); sw.WriteLine(prefix + " for (let " + tmpvarname + " of " + varname + ".entries())"); sw.WriteLine(prefix + " {"); keytype.Accept(new Encode("" + tmpvarname + "[0]", -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Encode("" + tmpvarname + "[1]", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndWriteSegment(_state_); "); sw.WriteLine(prefix + "}"); }
void Visitor.Visit(TypeMap type) { if (id < 0) { throw new Exception("invalid variable.id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + "case (Zeze.ByteBuffer.MAP | " + id + " << Zeze.ByteBuffer.TAG_SHIFT):"); sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " var _state_ = _os_.BeginReadSegment();"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip key typetag"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip value typetag"); sw.WriteLine(prefix + " " + varname + ".clear();"); sw.WriteLine(prefix + " for (var size = _os_.ReadInt(); size > 0; --size)"); sw.WriteLine(prefix + " {"); string vartmpkey = Program.GenUniqVarName(); string vartmpvalue = Program.GenUniqVarName(); keytype.Accept(new Define(vartmpkey, sw, prefix + " ")); keytype.Accept(new Decode(vartmpkey, -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Define(vartmpvalue, sw, prefix + " ")); valuetype.Accept(new Decode(vartmpvalue, -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".set(" + vartmpkey + ", " + vartmpvalue + ");"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " break;"); }
private void CheckActualAgainstFormal(Dictionary <string, Expression> actuals, Expression expression, Parameter parameter) { actuals[parameter.Name] = expression; expression.checkExpression(); Types.Type argumentType = expression.GetExpressionType(); if (argumentType == null) { AddError("Cannot evaluate argument type for argument " + expression.ToString()); } else { if (parameter.Type == null) { AddError("Cannot evaluate formal parameter type for " + parameter.Name); } else { if (!parameter.Type.Match(argumentType)) { AddError("Invalid argument " + expression.ToString() + " type, expected " + parameter.Type.FullName + ", actual " + argumentType.FullName); } } } }
public string nameCollectionImplement; // 容器内部类型。其他情况下为 null。 public static string GetName(Types.Type type) { var visitor = new TypeName(); type.Accept(visitor); return(visitor.name); }
/// <summary> /// Combines two types to create a new one /// </summary> /// <param name="right"></param> /// <param name="Operator"></param> /// <returns></returns> public override Types.Type CombineType(Types.Type right, Interpreter.BinaryExpression.OPERATOR Operator) { Types.Type retVal = null; Function function = right as Function; if (function != null) { if (this.ReturnType == function.ReturnType) { if (this.FormalParameters.Count >= function.FormalParameters.Count) { retVal = this; } else { retVal = function; } } else { AddError("Cannot combine types " + this.ReturnType.Name + " and " + function.ReturnType.Name); } } else if (right.IsDouble()) { retVal = this; } else { AddError("Cannot combine types " + this.ReturnType.Name + " and " + right.Name); } return(retVal); }
/// <summary> /// Checks the statement for semantical errors /// </summary> public override void CheckStatement() { Value.checkExpression(); Types.Collection targetListType = ListExpression.GetExpressionType() as Types.Collection; if (targetListType != null) { Types.Type elementType = Value.GetExpressionType(); if (elementType != targetListType.Type) { Root.AddError("Inserted element type does not corresponds to list type"); } Condition.checkExpression(); Types.BoolType conditionType = Condition.GetExpressionType() as Types.BoolType; if (conditionType == null) { Root.AddError("Condition does not evaluates to boolean"); } } else { Root.AddError("Cannot determine collection type of " + ListExpression); } }
ExpressionType TranslateExpression(ArrayExpression e) { Types.Type type = Env.TypeEnvironment[e.Type] as Types.Type; if (type == null) { Error.Report(e.Pos, "Undefined array type"); return(new ExpressionType(null, Types.Type._unknown)); } type = type.Actual; if (!(type is Types.ARRAY)) { Error.Report(e.Pos, "Array type required"); return(new ExpressionType(null, Types.Type._unknown)); } ExpressionType size = TranslateExpression(e.Size); CheckInteger(e.Size.Pos, size); ExpressionType init = TranslateExpression(e.Init); if (!init.Type.CoerceTo((type as Types.ARRAY).Element.Actual)) { Error.Report(e.Init.Pos, "Incorrect initialized type"); return(new ExpressionType(null, Types.Type._unknown)); } if (init.Type.CoerceTo(Types.Type._int)) { return(new ExpressionType(Translate.TranslateArrayExp(Level, init.Exp, size.Exp), type)); } else { return(new ExpressionType(Translate.TranslateMultiArrayExp(Level, init.Exp, size.Exp), type)); } }
public FunctionEntry(Level level, Label label, Types.RECORD formals, Types.Type result) { Level = level; Label = label; Formals = formals; Result = result; }
public static string GetName(Types.Type type) { TypeTagName v = new TypeTagName(); type.Accept(v); return(v.Name); }
void Visitor.Visit(TypeSet type) { if (id < 0) { throw new Exception("invalid variable.id"); } sw.WriteLine(prefix + "case (Zeze.ByteBuffer.SET | " + id + " << Zeze.ByteBuffer.TAG_SHIFT):"); Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " var _state_ = _os_.BeginReadSegment();"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip collection.value typetag"); sw.WriteLine(prefix + " " + varname + ".clear();"); sw.WriteLine(prefix + " for (var _size_ = _os_.ReadInt(); _size_ > 0; --_size_)"); sw.WriteLine(prefix + " {"); string vartmpname = Program.GenUniqVarName(); valuetype.Accept(new Define(vartmpname, sw, prefix + " ")); valuetype.Accept(new Decode(vartmpname, -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".add(" + vartmpname + ");"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " break;"); }
private void WriteProperty(Types.Type type, bool checkNull = false) { sw.WriteLine(prefix + "public " + TypeName.GetName(type) + " " + var.NameUpper1); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " get"); sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " if (false == this.IsManaged)"); sw.WriteLine(prefix + " return " + var.NamePrivate + ";"); sw.WriteLine(prefix + " var txn = Zeze.Transaction.Transaction.Current;"); sw.WriteLine(prefix + " if (txn == null) return " + var.NamePrivate + ";"); sw.WriteLine(prefix + " txn.VerifyRecordAccessed(this, true);"); sw.WriteLine(prefix + " var log = (Log_" + var.NamePrivate + ")txn.GetLog(this.ObjectId + " + var.Id + ");"); sw.WriteLine(prefix + " return log != null ? log.Value : " + var.NamePrivate + ";"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " set"); sw.WriteLine(prefix + " {"); if (checkNull) { sw.WriteLine(prefix + " if (null == value) throw new System.ArgumentNullException();"); } sw.WriteLine(prefix + " if (false == this.IsManaged)"); sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " " + var.NamePrivate + " = value;"); sw.WriteLine(prefix + " return;"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " var txn = Zeze.Transaction.Transaction.Current;"); sw.WriteLine(prefix + " txn.VerifyRecordAccessed(this);"); sw.WriteLine(prefix + " var log = (Log_" + var.NamePrivate + ")txn.GetLog(this.ObjectId + " + var.Id + ");"); sw.WriteLine(prefix + " if (log == null && " + var.NamePrivate + ".Equals(value)) return;"); sw.WriteLine(prefix + " if (log != null && log.Value.Equals(value)) return;"); sw.WriteLine(prefix + " txn.PutLog(new Log_" + var.NamePrivate + "(this, value));"); // sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + "}"); sw.WriteLine(); }
void Visitor.Visit(TypeMap type) { if (id < 0) { throw new Exception("invalid variable.id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + "case (ByteBuffer.MAP | " + id + " << ByteBuffer.TAG_SHIFT):"); sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " _os_.BeginReadSegment(out var _state_);"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip key typetag"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip value typetag"); sw.WriteLine(prefix + " " + varname + ".Clear();"); sw.WriteLine(prefix + " for (int size = _os_.ReadInt(); size > 0; --size)"); sw.WriteLine(prefix + " {"); keytype.Accept(new Define("_k_", sw, prefix + " ")); keytype.Accept(new Decode("_k_", -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Define("_v_", sw, prefix + " ")); valuetype.Accept(new Decode("_v_", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".Add(_k_, _v_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " break;"); }
public static TypeMeta Get(Types.Variable var, Types.Type type) { TypeMeta v = new TypeMeta(var); type.Accept(v); return(v); }
public Types.Type GetTLType() { if (this.type == null) { this.type = new Types.Type(this.ClassName, this.PackageName, TypeCategory.Class); } return(this.type); }
Exp TranslateDeclaration(FunctionDeclaration dec) { List <SymbolTable.Symbol> list = new List <SymbolTable.Symbol>(); for (FunctionDeclaration d = dec; d != null; d = d.Next) { if (Env.ValueEnvironment[d.Name] != null && Env.ValueEnvironment[d.Name] is StandardFunctionEntry) { Error.Report(d.Pos, "Function in standard libaray cannot be redefined"); } else if (list.Contains(d.Name)) { Error.Report(d.Pos, "Function cannot be redefined in a sequence"); } else { list.Add(d.Name); Types.Type result = d.Result == null ? Types.Type._void : TranslateType(d.Result).Actual; Types.RECORD formals = TranslateTypeFields(d.Param); Label label = new Label(d.Name + "_" + Count++.ToString()); Translate.Level level = new Translate.Level(Level, label, BoolList.BuildFromFieldList(d.Param)); Env.ValueEnvironment[d.Name] = new FunctionEntry(level, label, formals, result); } } for (FunctionDeclaration d = dec; d != null; d = d.Next) { FunctionEntry function = Env.ValueEnvironment[d.Name] as FunctionEntry; Env.ValueEnvironment.BeginScope(); Env.LoopEnvironment.BeginScope(); Translate.Level backup = Level; Level = function.Level; Translate.AccessList al = Level.Formals.Tail; for (FieldList field = d.Param; field != null; field = field.Tail, al = al.Tail) { Types.Type type = Env.TypeEnvironment[field.Type] as Types.Type; if (type == null) { Error.Report(field.Pos, "Undefined type '" + field.Name + "'"); } else { Translate.Access access = new Translate.Access(Level, al.Head.Acc); Env.ValueEnvironment[field.Name] = new VariableEntry(access, type.Actual); } } ExpressionType et = TranslateExpression(d.Body); Translate.ProcessEntryExit(Level, et.Exp, !(et.Type.CoerceTo(Types.Type._void))); if (!et.Type.CoerceTo((Env.ValueEnvironment[d.Name] as FunctionEntry).Result)) { Error.Report(d.Result != null ? d.Result.Pos : d.Body.Pos, "Type mismatched for function return value"); } Env.ValueEnvironment.EndScope(); Env.LoopEnvironment.EndScope(); Level = backup; } return(Translate.TranslateNoOp()); }
/// <summary> /// Checks the expression and appends errors to the root tree node when inconsistencies are found /// </summary> public override void checkExpression() { base.checkExpression(); Types.Type listExpressionType = ListExpression.GetExpressionType(); if (!(listExpressionType is Types.Collection)) { AddError("List expression " + ListExpression.ToString() + " should hold a collection"); } }
/// <summary> /// Evaluates the current input as a integer /// </summary> /// <returns></returns> public NumberExpression EvaluateInt() { NumberExpression retVal = null; int backup = Index; int len = 0; bool digitFound = false; Types.Type type = EFSSystem.IntegerType; if (Index < Buffer.Length && Buffer[Index] == '-') { len += 1; } while (Index + len < Buffer.Length && Char.IsDigit(Buffer[Index + len])) { digitFound = true; len = len + 1; } if (len > 0 && Index + len < Buffer.Length && Buffer[Index + len] == '.') { type = EFSSystem.DoubleType; len = len + 1; while (Index + len < Buffer.Length && Char.IsDigit(Buffer[Index + len])) { len = len + 1; } } if (Index + len < Buffer.Length && Buffer[Index + len] == 'E') { type = EFSSystem.DoubleType; len = len + 1; while (Index + len < Buffer.Length && Char.IsDigit(Buffer[Index + len])) { len = len + 1; } } if (digitFound) { string str = new String(Buffer, Index, len); retVal = new NumberExpression(Root, str, type); Index += len; } if (retVal == null) { Index = backup; } return(retVal); }
private void WriteLogValue(Types.Type type) { string valueName = TypeName.GetName(type); sw.WriteLine(prefix + "private sealed class Log_" + var.NamePrivate + " : Zeze.Transaction.Log<" + bean.Name + ", " + valueName + ">"); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " public Log_" + var.NamePrivate + "(" + bean.Name + " self, " + valueName + " value) : base(self, value) { }"); sw.WriteLine(prefix + " public override long LogKey => this.Bean.ObjectId + " + var.Id + ";"); sw.WriteLine(prefix + " public override void Commit() { this.BeanTyped." + var.NamePrivate + " = this.Value; }"); sw.WriteLine(prefix + "}"); }
public static Type Resolve(Types.Type type) { if (type is CompositeType) { return((type as CompositeType).OperatorAccess.ReturnType); } else { return(type); } }
private string GetBeanTypeId(Types.Type type) { if (null == type) { return("0"); } if (false == type.IsNormalBean) { throw new Exception("is not a normal bean"); } return(((Types.Bean)type).TypeId.ToString()); }
public Trainer(string favouritePokemon, Types.Type favouriteType, Pokemon[] pokemonParty, List <Pokemon> caughtPokemon, string name, int age, Creatures.Gender gender, double weight, double height) { this.favouritePokemon = favouritePokemon; this.favouriteType = favouriteType; this.pokemonParty = new Pokemon[6]; this.caughtPokemon = new List <Pokemon>(); this.name = name; this.age = age; this.gender = gender; this.weight = weight; this.height = height; }
private string GetFullName(Types.Type type) { if (type.IsBean) { if (type.IsKeyable) { return((type as Types.BeanKey).FullName); } return((type as Types.Bean).FullName); } return(type.Name); }
public Question(Id identifier, Types.Type type, Label label, Expression computation, PositionInText positionInText) : base(positionInText) { this.Identifier = identifier; this.type = type; this.Label = label; this.Computation = computation; }
public Monster(int _size, Specie _specie, Types.Type _type, int _defaultAtt, int _defaultDef, int _defaultSpd, int _defaultMagAtt, int _defaultMagDef, int _rarity) { MonsterID = new Guid(); Size = _size; Species = _specie; Type = _type; DefaultAtt = _defaultAtt; DefaultDef = _defaultDef; DefaultMagAtt = _defaultMagAtt; DefaultMagDef = _defaultMagDef; DefaultSpd = _defaultSpd; Rarity = _rarity; }
public override FormObject VisitQuestion(QLMainParser.QuestionContext context) { string identifier = context.id().GetText(); PositionInText IdPosition = new PositionInText(context.id()); PositionInText position = new PositionInText(context); Types.Type typeName = context.type().Accept(new TypeVisitor()); Expression computation = context.computed() != null?context.computed().expression().Accept(new ExpressionVisitor()) : null; return(new Question(new Id(identifier, IdPosition), typeName, MakeLabel(context.label()), computation, position)); }
public VariableEntry(Access access, Types.Type type) { Access = access; Type = type; }
public ExpressionType(Exp exp, Types.Type type) { Exp = exp; Type = type; }