public void Evaluate(AnalysisEnvironment environment) { if (IsEvaluated) { return; } this.IsEvaluated = true; this.GetIdentifer(this, environment); }
public void Evaluate(AnalysisEnvironment environment) { if (IsEvaluated) { return; } // null types are the types with no fields and functions. this.FieldSymbols.Clear(); this.FieldTypes.Clear(); this.IsEvaluated = true; }
public override string GetIdentifer(TypeRecord caller, AnalysisEnvironment environment) { // the record index is set, which means the type is successfully registered and // is allocated with an index already. if (this.Symbol == "matrix" && (!this.IsFilledGeneric)) { return("matrix"); } if (ClrTypeRecordIndex != -1) { return("<" + ClrTypeRecordIndex + ">"); } Interop.AnonymousTypeRecord.RegistryCount++; this.ClrTypeRecordIndex = Interop.AnonymousTypeRecord.RegistryCount; Interop.AnonymousTypeRecord.IdentiferRegistry.Add(this.ClrTypeRecordIndex, "(undefined)"); string genericName = ""; if (this.Symbol.StartsWith("matrix(") || this.Symbol.Trim() == "matrix") { genericName = "matrix"; } else { genericName = "[" + this.clrType.FullName + "]"; } List <string> typeParams = new List <string>(); if (this.IsFilledGeneric && this.IsClrFilling) { foreach (var item in this.GenericParameters) { typeParams.Add("[" + item.FullName + "]"); } } else if (this.IsFilledGeneric) { foreach (var item in GenericTypeRecords) { typeParams.Add(item.GetIdentifer(this, environment)); } } typeParams.Sort(); this.Identifer = genericName + "(" + typeParams.JoinString(",") + ")"; Interop.AnonymousTypeRecord.IdentiferRegistry[ClrTypeRecordIndex] = this.Identifer; return("<" + this.ClrTypeRecordIndex + ">"); }
public void Evaluate(AnalysisEnvironment environment) { if (IsEvaluated) { return; } TypeRecord temp = this.Combination[0]; for (int i = 1; i < this.Combination.Count; i++) { temp = Combine(environment, temp, this.Combination[i]); } if (temp is AnyType) { this.Identifer = "any"; this.ClrTypeRecordIndex = -3; this.IsEvaluated = true; } else { foreach (var item in temp.FieldSymbols) { this.FieldSymbols.Add(item.Key, item.Value); } foreach (var item in temp.FieldTypes) { this.FieldTypes.Add(item); } foreach (var item in temp.MemberFunctions) { if (!this.MemberFunctions.ContainsKey(item.Key)) { this.MemberFunctions.Add(item.Key, item.Value); } } this.IsEvaluated = true; this.GetIdentifer(this, environment); } }
public TypeRecord Combine(AnalysisEnvironment environment, TypeRecord Target, TypeRecord Addition) { if (Target is IOperationType operation) { operation.Evaluate(environment); } if (Addition is IOperationType exclusion) { exclusion.Evaluate(environment); } if (Target.ClrTypeRecordIndex == -1) { Target.GetIdentifer(this, environment); } if (Addition.ClrTypeRecordIndex == -1) { Addition.GetIdentifer(this, environment); } if (Target is AnyType || Addition is AnyType) { return(new AnyType()); } TypeRecord typeRecord = new TypeRecord(); foreach (var item in Target.FieldSymbols) { typeRecord.FieldSymbols.Add(item.Key, item.Value); } foreach (var item in Target.FieldTypes) { typeRecord.FieldTypes.Add(item); } // foreach (var item in Target.MemberFunctions) { // typeRecord.MemberFunctions.Add(item.Key, item.Value); // } int counter = 0; foreach (var item in Addition.FieldSymbols) { if (!typeRecord.FieldSymbols.ContainsKey(item.Key)) { typeRecord.FieldSymbols.Add(item.Key, item.Value); typeRecord.FieldTypes.Add(Addition.FieldTypes[counter]); } counter++; } // foreach (var item in Addition.MemberFunctions) { // if (!typeRecord.MemberFunctions.ContainsKey(item.Key)) // typeRecord.MemberFunctions.Add(item.Key, item.Value); // } typeRecord.Symbol = "___autogen_class_" + Interop.AnonymousTypeRecord.RegistryCount; typeRecord.GetIdentifer(typeRecord, environment); environment.SetObject(typeRecord.Oid, typeRecord); return(typeRecord); }
public override string GetIdentifer(TypeRecord caller, AnalysisEnvironment environment) { this.Identifer = "any"; this.ClrTypeRecordIndex = -3; return("any"); }
public virtual string GetIdentifer(TypeRecord caller, AnalysisEnvironment environment) { // the record index is set, which means the type is successfully registered and // is allocated with an index already. if (ClrTypeRecordIndex != -1) { return("<" + ClrTypeRecordIndex + ">"); } Interop.AnonymousTypeRecord.RegistryCount++; this.ClrTypeRecordIndex = Interop.AnonymousTypeRecord.RegistryCount; Interop.AnonymousTypeRecord.IdentiferRegistry.Add(this.ClrTypeRecordIndex, "(undefined)"); int id = 0; List <string> fields = new List <string>(); foreach (var item in this.FieldSymbols) { if (environment.Objects[item.Value] is FunctionRecord func) { continue; } var field = (DataRecord)environment.Objects[item.Value]; string fieldIdentifer = ""; fieldIdentifer += field.Symbol + ":"; if (this.FieldTypes[id].Symbol != (caller?.Symbol ?? "")) { // the declaring type doesn't contains its parent type. thus, we can perform // iteration (if not cached in ClrTypeRecord.Registry). fieldIdentifer += this.FieldTypes[id].GetIdentifer(this, environment); } else { // the declaring type contains its parent type. this will cause recursion, and // is not allowed in compiletime. throw a warning message indicating that the // reference is automatically converted to a pointer. if (caller.ClrTypeRecordIndex == -1) { environment.Current.Diagnostics.AddFatal(Parser.SyntaxError.RecursiveAssertionFailed, new Parser.Token("")); } else { environment.Current.Diagnostics.AddWarning(Parser.SyntaxError.RecursiveToPointer, new Parser.Token("")); fieldIdentifer += "{" + caller.ClrTypeRecordIndex + "}"; } } fields.Add(fieldIdentifer); id++; } fields.Sort(); this.Identifer = "(" + fields.JoinString("|") + ")"; // register the identifer and index in the global class cache. Interop.AnonymousTypeRecord.IdentiferRegistry[ClrTypeRecordIndex] = this.Identifer; return("<" + this.ClrTypeRecordIndex + ">"); }
public void Evaluate(AnalysisEnvironment environment) { if (IsEvaluated) { return; } if (this.Target is IOperationType operation) { operation.Evaluate(environment); } if (this.Exclusion is IOperationType exclusion) { exclusion.Evaluate(environment); } if (this.Target.ClrTypeRecordIndex == -1) { this.Target.GetIdentifer(this, environment); } if (this.Exclusion.ClrTypeRecordIndex == -1) { this.Exclusion.GetIdentifer(this, environment); } if (this.Target is AnyType) { // excluded types are not allowed to evaluate if the target before evaluation is // 'any'. these types must be used in the type matching conditions. environment.Current.Diagnostics.AddFatal (Parser.SyntaxError.IllegalAny, this.Target.Declaration?.Tokens[0] ?? new Parser.Token("")); return; } if (this.Exclusion is AnyType) { this.FieldSymbols.Clear(); this.FieldTypes.Clear(); return; } foreach (var item in this.Target.FieldSymbols) { this.FieldSymbols.Add(item.Key, item.Value); } foreach (var item in this.Target.FieldTypes) { this.FieldTypes.Add(item); } int counter = 0; foreach (var item in this.Exclusion.FieldSymbols) { if (this.FieldSymbols.ContainsKey(item.Key)) { // we meet a conflicted field (in its name) and we want to determine whether the // type of the field is identical. the signal of identical is the ClrIndex var type = this.Exclusion.FieldTypes[counter]; var existing = this.FieldSymbols[item.Key]; if ((type.Identifer ?? type.Symbol) == (this.FieldTypes[counter].Identifer ?? this.FieldTypes[counter].Symbol)) { this.FieldSymbols.Remove(item.Key); this.FieldTypes.RemoveAt(existing.Item1); } } counter++; } this.IsEvaluated = true; this.GetIdentifer(this, environment); this.Symbol = "___autogen_class_" + this.ClrTypeRecordIndex; }
// this method is called later, when all the objects' names are registered as references public void Define(AnalysisEnvironment environment, FunctionDeclaration decl) { if (this is Interop.ClrFunctionRecord) { return; } this.Declaration = decl; // evaluate the type used for current function. including the return types and parameter types. // a function is complete only when: // (1) its return type can be described with available types. // (2) all of its parameter types can be described with available types. // (3) all of the locals can be described with available types. // (4) all the references to outside is within the availble definitions. // (1) return type evaluation this.ReturnType = environment.GetDirectTypeRecord(decl.ReturnType); if (this.ReturnType is Record.IOperationType op) { op.Evaluate(environment); } else { this.ReturnType.GetIdentifer(this.Parent, environment); } // (2) parameter evaluation this.ParameterModifer.Clear(); this.Parameters.Clear(); this.ParameterSymbol.Clear(); this.ParameterType.Clear(); foreach (var param in decl.Parameters) { DataRecord data = new DataRecord(); data.Definition = environment.GetDirectTypeRecord(param.Type); data.ExplicitType = param.Type; data.Expression = param.Default; data.Symbol = param.Identifer.Value; data.ClrTypeRecordIndex = data.Definition.ClrTypeRecordIndex; ParameterType.Add(data.Definition); ParameterSymbol.Add(data.Symbol, data.Oid); environment.SetObject(data.Oid, data); var modifers = Analysis.ParameterModifers.ByValue; foreach (var item in param.Modifers) { switch (item.Value.ToLower()) { case "readonly": modifers |= ParameterModifers.Readonly; break; case "extends": modifers |= ParameterModifers.Extends; break; case "byname": modifers = modifers & (~ParameterModifers.PassAttributes); modifers |= ParameterModifers.ByName; break; case "byref": case "byreference": modifers = modifers & (~ParameterModifers.PassAttributes); modifers |= ParameterModifers.ByReference; break; case "byval": case "byvalue": modifers = modifers & (~ParameterModifers.PassAttributes); modifers |= ParameterModifers.ByValue; break; case "cdom": case "currentdomain": modifers |= ParameterModifers.CurrentDomain; break; } } this.ParameterModifer.Add(modifers); this.Parameters.Add(param.Identifer.Value, data); data.ClrTypeRecordIndex = data.Definition.ClrTypeRecordIndex; } }