public override void Execute(ParserStateValues state, string trimmedLine) { if (trimmedLine.StartsWith(".class", StringComparison.Ordinal)) { state.State = ParserState.ClassDeclaration; state.AddLine = true; state.ClassDeclaration = trimmedLine; } else if (trimmedLine.StartsWith(".method", StringComparison.Ordinal)) { ExportedClass exportedClass; if (state.ClassNames.Count == 0 || !this.Parser.Exports.ClassesByName.TryGetValue(state.ClassNames.Peek(), out exportedClass)) { return; } state.Method.Reset(); state.Method.Declaration = trimmedLine; state.AddLine = false; state.State = ParserState.MethodDeclaration; } else { if (!trimmedLine.StartsWith("} // end of class", StringComparison.Ordinal)) { return; } state.ClassNames.Pop(); state.State = state.ClassNames.Count > 0 ? ParserState.Class : ParserState.Normal; } }
private static string GetClassName(ParserStateValues state) { bool hadClassName = false; StringBuilder classNameBuilder = new StringBuilder(state.ClassDeclaration.Length); IlParsingUtils.ParseIlSnippet(state.ClassDeclaration, ParsingDirection.Forward, (Func <IlParsingUtils.IlSnippetLocation, bool>)(s => { if (s.WithinString) { hadClassName = true; if (s.CurrentChar != '\'') { classNameBuilder.Append(s.CurrentChar); } } else if (hadClassName) { if (s.CurrentChar == '.' || s.CurrentChar == '/') { classNameBuilder.Append(s.CurrentChar); } else if (s.CurrentChar != '\'') { return(false); } } return(true); }), (Action <IlParsingUtils.IlSnippetFinalizaton>)null); return(classNameBuilder.ToString()); }
public override void Execute(ParserStateValues state, string trimmedLine) { if (!trimmedLine.StartsWith("} // end of method", StringComparison.Ordinal)) { return; } state.State = ParserState.Class; }
private bool GetIsExport(ParserStateValues state, out ExportedClass exportedClass) { if (!this.ExtractMethodParts(state)) { exportedClass = (ExportedClass)null; return(false); } bool flag1 = this.Exports.ClassesByName.TryGetValue(state.ClassNames.Peek(), out exportedClass) && exportedClass != null; List <ExportedMethod> exportedMethodList1 = (List <ExportedMethod>)null; if (flag1 && exportedClass.HasGenericContext) { if (exportedClass.MethodsByName.TryGetValue(state.Method.Name, out exportedMethodList1)) { exportedMethodList1.ForEach((Action <ExportedMethod>)(method => this.Notify(2, DllExportLogginCodes.ExportInGenericType, Resources.The_type_1_cannot_export_the_method_2_as_0_because_it_is_generic_or_is_nested_within_a_generic_type, (object)method.ExportName, (object)method.ExportedClass.FullTypeName, (object)method.MemberName))); } return(false); } bool flag2 = flag1 && exportedClass.MethodsByName.TryGetValue(state.Method.Name, out exportedMethodList1); if (flag1 && !flag2) { ExportedMethod duplicateExport = this.Exports.GetDuplicateExport(exportedClass.FullTypeName, state.Method.Name); this.ValidateExportNameAndLogError(duplicateExport, state); if (duplicateExport != null) { this.Notify(state, 1, DllExportLogginCodes.AmbigiguousExportName, Resources.Ambiguous_export_name_0_on_1_2_, (object)duplicateExport.ExportName, (object)duplicateExport.ExportedClass.FullTypeName, (object)duplicateExport.MemberName); } } else { List <ExportedMethod> exportedMethodList2; if ((exportedMethodList2 = exportedMethodList1 ?? exportedClass.NullSafeCall <ExportedClass, List <ExportedMethod> >((Func <ExportedClass, List <ExportedMethod> >)(i => i.Methods))) != null) { foreach (ExportedMethod exportedMethod in exportedMethodList2) { if (!exportedMethod.IsStatic) { flag2 = false; this.Notify(state, 2, DllExportLogginCodes.MethodIsNotStatic, Resources.The_method_1_2_is_not_static_export_name_0_, (object)exportedMethod.ExportName, (object)exportedMethod.ExportedClass.FullTypeName, (object)exportedMethod.MemberName); } if (exportedMethod.IsGeneric) { flag2 = false; this.Notify(state, 2, DllExportLogginCodes.ExportOnGenericMethod, Resources.The_method_1_2_is_generic_export_name_0_Generic_methods_cannot_be_exported_, (object)exportedMethod.ExportName, (object)exportedMethod.ExportedClass.FullTypeName, (object)exportedMethod.MemberName); } } } } return(flag2); }
public override void Execute(ParserStateValues state, string trimmedLine) { if (trimmedLine.StartsWith(".custom", StringComparison.Ordinal) || trimmedLine.StartsWith("// Code", StringComparison.Ordinal)) { ExportedClass exportedClass; if (this.Exports.ClassesByName.TryGetValue(state.ClassNames.Peek(), out exportedClass)) { ExportedMethod exportMethod = exportedClass.MethodsByName[state.Method.Name][0]; string declaration = state.Method.Declaration; StringBuilder stringBuilder = new StringBuilder(250); stringBuilder.Append(".method ").Append(state.Method.Attributes.NullSafeTrim()).Append(" "); stringBuilder.Append(state.Method.Result.NullSafeTrim()); stringBuilder.Append(" modopt(['mscorlib']'").Append(AssemblyExports.ConventionTypeNames[exportMethod.CallingConvention]).Append("') "); if (!string.IsNullOrEmpty(state.Method.ResultAttributes)) { stringBuilder.Append(" ").Append(state.Method.ResultAttributes); } stringBuilder.Append(" '").Append(state.Method.Name).Append("'").Append(state.Method.After.NullSafeTrim()); bool flag = this.ValidateExportNameAndLogError(exportMethod, state); if (flag) { state.Method.Declaration = stringBuilder.ToString(); } if (state.MethodPos != 0) { state.Result.Insert(state.MethodPos, state.Method.Declaration); } if (flag) { this.Notifier.Notify(-2, DllExportLogginCodes.OldDeclaration, "\t" + Resources.OldDeclaration_0_, (object)declaration); this.Notifier.Notify(-2, DllExportLogginCodes.NewDeclaration, "\t" + Resources.NewDeclaration_0_, (object)state.Method.Declaration); state.Result.Add(string.Format((IFormatProvider)CultureInfo.InvariantCulture, " .export [{0}] as '{1}'", (object)exportMethod.VTableOffset, (object)exportMethod.ExportName)); this.Notifier.Notify(-1, DllExportLogginCodes.AddingVtEntry, "\t" + Resources.AddingVtEntry_0_export_1_, (object)exportMethod.VTableOffset, (object)exportMethod.ExportName); } } else { state.AddLine = false; } state.State = ParserState.Method; } else { state.AddLine = false; } }
public override void Execute(ParserStateValues state, string trimmedLine) { if (trimmedLine.StartsWith("{")) { state.State = ParserState.Class; string str = ClassDeclarationParserAction.GetClassName(state); if (state.ClassNames.Count > 0) { str = state.ClassNames.Peek() + "/" + str; } state.ClassNames.Push(str); } else { state.ClassDeclaration = state.ClassDeclaration + " " + trimmedLine; state.AddLine = true; } }
private bool ExtractMethodParts(ParserStateValues state) { string methodName; string afterMethodName; string foundResult; string foundResultModifier; string foundMethodAttributes; if (!this.GetPartBeforeParameters(state.Method.Declaration, out methodName, out afterMethodName, out foundResult, out foundResultModifier, out foundMethodAttributes)) { return(false); } state.Method.After = afterMethodName; state.Method.Name = methodName; state.Method.Attributes = foundMethodAttributes; state.Method.Result = foundResult; state.Method.ResultAttributes = foundResultModifier; return(true); }
public override void Execute(ParserStateValues state, string trimmedLine) { if (trimmedLine.StartsWith(".custom instance void ", StringComparison.Ordinal) && trimmedLine.Contains(this.Parser.DllExportAttributeIlAsmFullName)) { state.AddLine = false; state.State = ParserState.DeleteExportAttribute; this.Notifier.Notify(-2, DllExportLogginCodes.RemovingDllExportAttribute, Resources.Removing_0_from_1_, (object)Utilities.DllExportAttributeFullName, (object)(state.ClassNames.Peek() + "." + state.Method.Name)); } else { if (!trimmedLine.StartsWith("// Code", StringComparison.Ordinal)) { return; } state.State = ParserState.Method; if (state.MethodPos == 0) { return; } state.Result.Insert(state.MethodPos, state.Method.Declaration); } }
public override void Execute(ParserStateValues state, string trimmedLine) { if (trimmedLine.StartsWith("{", StringComparison.Ordinal)) { ExportedClass exportedClass; if (this.GetIsExport(state, out exportedClass)) { this.Notify(-1, DllExportLogginCodes.MethodFound, string.Format(Resources.Found_method_0_1_, (object)exportedClass.FullTypeName, (object)state.Method.Declaration)); state.MethodPos = state.Result.Count; state.State = ParserState.MethodProperties; } else { state.Result.Add(state.Method.Declaration); state.State = ParserState.Method; state.MethodPos = 0; } } else { state.Method.Declaration = state.Method.Declaration + " " + trimmedLine; state.AddLine = false; } }
public override void Execute(ParserStateValues state, string trimmedLine) { if (trimmedLine.StartsWith(".corflags", StringComparison.Ordinal)) { state.Result.Add(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ".corflags 0x{0}", (object)Utilities.GetCoreFlagsForPlatform(state.Cpu).ToString("X8", (IFormatProvider)CultureInfo.InvariantCulture))); state.AddLine = false; } else if (trimmedLine.StartsWith(".class", StringComparison.Ordinal)) { state.State = ParserState.ClassDeclaration; state.AddLine = true; state.ClassDeclaration = trimmedLine; } else { string assemblyName; string aliasName; if (!this.IsExternalAssemblyReference(trimmedLine, out assemblyName, out aliasName)) { return; } state.RegisterMsCorelibAlias(assemblyName, aliasName); } }