public void Create_WhenCreatingAttributeWithNamedArgument_ShouldGenerateCorrectCode() { Assert.AreEqual("[Test(with:1,value:2)]", AttributeGenerator.Create(new Attribute("Test", new List <IArgument>() { new ValueArgument(1, namedArgument: "with"), new ValueArgument(2, namedArgument: "value") })).ToString()); }
/// <summary> /// Create the syntax for a property of a class. /// </summary> /// <param name="property">The property to create.</param> /// <returns>The declaration syntax for a property.</returns> public static PropertyDeclarationSyntax Create(Property property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } PropertyDeclarationSyntax propertyDeclaration; if (property is AutoProperty) { propertyDeclaration = CreateAutoProperty((AutoProperty)property); } else if (property is BodyProperty) { propertyDeclaration = CreateBodyProperty((BodyProperty)property); } else { throw new ArgumentException($"Unknown property type: {property.Type}, could not generate code."); } if (property.Modifiers != null) { propertyDeclaration = propertyDeclaration.WithModifiers(ModifierGenerator.Create(property.Modifiers.ToArray())); } if (property.Attributes != null) { propertyDeclaration = propertyDeclaration.WithAttributeLists(AttributeGenerator.Create(property.Attributes.ToArray())); } return(propertyDeclaration); }
/// <summary> /// Create the syntax for a class constructor. /// </summary> /// <param name="className">Name of the class.</param> /// <param name="body">The generated body of the constructor.</param> /// <param name="parameters">A list with parameters.</param> /// <param name="modifiers">A list with modifiers.</param> /// <param name="attributes">A list with attributes.</param> /// <returns>The declaration syntax for a constructor.</returns> public static ConstructorDeclarationSyntax Create( string className, BlockSyntax body, IEnumerable <Parameter> parameters = null, IEnumerable <Modifiers> modifiers = null, IEnumerable <Attribute> attributes = null) { if (className == null) { throw new ArgumentNullException(nameof(className)); } var constructor = SyntaxFactory.ConstructorDeclaration(SyntaxFactory.Identifier(className)) .WithBody(body); if (parameters != null) { constructor = constructor.WithParameterList(ParameterGenerator.Create(parameters.ToArray())); } if (attributes != null) { constructor = constructor.WithAttributeLists(AttributeGenerator.Create(attributes.ToArray())); } if (modifiers != null) { constructor = constructor.WithModifiers(ModifierGenerator.Create(modifiers.ToArray())); } return(constructor); }
/// <summary> /// Create the syntax for a field of a class. /// </summary> /// <param name="field">Field to create.</param> /// <returns>The declaration syntax for a field.</returns> public static FieldDeclarationSyntax Create(Field field) { if (field == null) { throw new ArgumentNullException(nameof(field)); } var variableDeclarator = VariableDeclarator(Identifier(field.Name)); if (field.InitializeWith != null) { variableDeclarator = variableDeclarator.WithInitializer(EqualsValueClause(field.InitializeWith)); } var fieldDeclaration = FieldDeclaration(VariableDeclaration(TypeGenerator.Create(field.Type), SeparatedList(new[] { variableDeclarator }))); if (field.Modifiers != null) { fieldDeclaration = fieldDeclaration.WithModifiers(ModifierGenerator.Create(field.Modifiers.ToArray())); } if (field.Attributes != null) { fieldDeclaration = fieldDeclaration.WithAttributeLists(AttributeGenerator.Create(field.Attributes.ToArray())); } return(fieldDeclaration); }
private void SetDuplicateCheckExpression(PutItemRequest request, Dictionary <string, AttributeValue> item) { ExpressionAttributeNames.Clear(); ExpressionAttributeValues.Clear(); AttributeGenerator.ResetIndex(); var hashKeyAttrValue = item.FirstOrDefault(x => x.Key == _hashKeyName).Value; if (hashKeyAttrValue == null) { throw new InvalidOperationException($"Item does not contains Hash key: {_hashKeyName}"); } var sb = new StringBuilder(); var hashKeyName = GetAttributeName(_hashKeyName); var hashKeyValue = GetAttributeValue(hashKeyAttrValue); sb.Append($"{hashKeyName} <> {hashKeyValue}"); if (!string.IsNullOrEmpty(_sortKeyName)) { var sortKeyAttrValue = item.FirstOrDefault(x => x.Key == _sortKeyName).Value; var sortKeyName = GetAttributeName(_sortKeyName); var sortKeyValue = GetAttributeValue(sortKeyAttrValue); sb.Append($" AND {sortKeyName} <> {sortKeyValue}"); } request.ExpressionAttributeNames = ExpressionAttributeNames; request.ExpressionAttributeValues = ExpressionAttributeValues; request.ConditionExpression = sb.ToString(); }
public void Create_WhenCreatingAttributeWithArguments_ShouldGenerateCorrectCode() { Assert.AreEqual("[Test(1,2)]", AttributeGenerator.Create(new Attribute("Test", new List <IArgument>() { new ValueArgument(1), new ValueArgument(2) })).ToString()); }
public void EmptyDataTest() { var generator = new AttributeGenerator(); var result = generator.Generate(new Type[0]); Assert.AreEqual("", result); }
public void SingleAttributeTypeDataTest() { var generator = new AttributeGenerator(); var attributes = new[] { typeof(System.ComponentModel.DataAnnotations.RequiredAttribute) }; var result = generator.Generate(attributes); Assert.AreEqual("[System.ComponentModel.DataAnnotations.RequiredAttribute]", result); }
public override string Generate(int indent) { if (Data != null) { var output = string.Empty; NamespaceGenerator @namespace = null; EnumGenerator @enum = null; if (string.IsNullOrEmpty(Data.title)) { return(output); } if (!string.IsNullOrEmpty(Data.category)) { @namespace = NamespaceGenerator.Namespace(Data.category); } @enum = EnumGenerator.Enum(Data.title.LegalMemberName()); indices.Clear(); for (int i = 0; i < Data.items.Count; i++) { if (!string.IsNullOrEmpty(Data.items[i].name)) { while (indices.Contains(Data.items[i].index)) { Data.items[i].index++; } indices.Add(Data.items[i].index); @enum.AddItem(Data.items[i].name, Data.items[i].index); } } @enum.indexing = Data.useIndex; #if VISUAL_SCRIPTING_1_7 if (Data.lastCompiledName != Data.GetFullTypeName()) { @enum.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName)); } #endif if (@namespace != null) { @namespace.AddEnum(@enum); return(@namespace.Generate(indent)); } return(@enum.Generate(indent)); } return(string.Empty); }
protected override TypeGenerator OnGenerateType(ref string output, NamespaceGenerator @namespace) { var @struct = StructGenerator.Struct(RootAccessModifier.Public, StructModifier.None, Data.title.LegalMemberName()); if (Data.definedEvent) { @struct.ImplementInterface(typeof(IDefinedEvent)); } if (Data.inspectable) { @struct.AddAttribute(AttributeGenerator.Attribute <InspectableAttribute>()); } if (Data.serialized) { @struct.AddAttribute(AttributeGenerator.Attribute <SerializableAttribute>()); } if (Data.includeInSettings) { @struct.AddAttribute(AttributeGenerator.Attribute <IncludeInSettingsAttribute>().AddParameter(true)); } for (int i = 0; i < Data.variables.Count; i++) { if (!string.IsNullOrEmpty(Data.variables[i].name) && Data.variables[i].type != null) { var field = FieldGenerator.Field(AccessModifier.Public, FieldModifier.None, Data.variables[i].type, Data.variables[i].name); if (Data.serialized) { if (Data.variables[i].inspectable) { field.AddAttribute(AttributeGenerator.Attribute <InspectableAttribute>()); } if (!Data.variables[i].serialized) { field.AddAttribute(AttributeGenerator.Attribute <NonSerializedAttribute>()); } } @struct.AddField(field); } } if (@namespace != null) { @namespace.AddStruct(@struct); } return(@struct); }
/// <summary> /// Create the syntax for a class constructor. /// </summary> /// <param name="className">Name of the class.</param> /// <param name="body">The generated body of the constructor.</param> /// <param name="parameters">A list with parameters.</param> /// <param name="modifiers">A list with modifiers.</param> /// <param name="attributes">A list with attributes.</param> /// <param name="constructorInitializer">The constructor initializer</param> /// <param name="summary">XML documentation summary</param> /// <returns>The declaration syntax for a constructor.</returns> public static ConstructorDeclarationSyntax Create( string className, BlockSyntax body, IEnumerable <Parameter> parameters = null, IEnumerable <Modifiers> modifiers = null, IEnumerable <Attribute> attributes = null, ConstructorInitializer constructorInitializer = null, string summary = null) { if (className == null) { throw new ArgumentNullException(nameof(className)); } var constructor = SyntaxFactory.ConstructorDeclaration(SyntaxFactory.Identifier(className)) .WithBody(body); if (parameters != null) { constructor = constructor.WithParameterList(ParameterGenerator.Create(parameters.ToArray())); } if (constructorInitializer != null) { constructor = constructor.WithInitializer( SyntaxFactory.ConstructorInitializer( constructorInitializer.ConstructorInitializerType == ConstructorInitializerTypes.Base ? SyntaxKind.BaseConstructorInitializer : SyntaxKind.ThisConstructorInitializer, constructorInitializer.Arguments == null ? null : ArgumentGenerator.Create(constructorInitializer.Arguments.ToArray()))); } if (attributes != null) { constructor = constructor.WithAttributeLists(AttributeGenerator.Create(attributes.ToArray())); } if (modifiers != null) { constructor = constructor.WithModifiers(ModifierGenerator.Create(modifiers.ToArray())); } if (!string.IsNullOrEmpty(summary)) { constructor = constructor.WithSummary(summary, parameters); } return(constructor); }
private async Task Generate(AttributeGenerator generator) { activity = $"Generating " + generator.AttributeName; max = _metadataStore.CountFilesMissingAttribute(generator.AttributeName); processed = 0; var files = _metadataStore.FilesMissingAttribute(generator.AttributeName); foreach (var file in files) { var values = generator.GenerateAttribute(file); if (values != null) { foreach (var value in values) { await _metadataStore.SetAttribute(file.Id, generator.AttributeName, value); } } processed++; } }
public override string Generate(int indent) { if (decorated != null) { var output = string.Empty; NamespaceGenerator @namespace = NamespaceGenerator.Namespace(string.Empty); if (string.IsNullOrEmpty(Data.title)) { return(output); } if (!string.IsNullOrEmpty(Data.category)) { @namespace = NamespaceGenerator.Namespace(Data.category); } TypeGenerator type = OnGenerateType(ref output, @namespace); ClassGenerator classType = type as ClassGenerator; StructGenerator structType = type as StructGenerator; if (Data.lastCompiledName != Data.GetFullTypeName() && !string.IsNullOrEmpty(Data.lastCompiledName)) { if (classType != null) { classType.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName)); } if (structType != null) { structType.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName)); } } return(@namespace.Generate(indent)); } return(string.Empty); }
public void Create_WhenNotProvidingAnyAttributes_ShouldGetEmptyString() { Assert.AreEqual(string.Empty, AttributeGenerator.Create().ToString()); }
/// <summary> /// Set type attributes. /// </summary> /// <param name="attributes">A set of wanted attributes.</param> /// <returns>The current builder</returns> public TBuilder WithAttributes(params Attribute[] attributes) { _attributes = AttributeGenerator.Create(attributes); return((TBuilder)this); }
public void Init(AttributeGenerator generator) { _attributeGenerator = generator; }
public void InvalidDataTypeTest() { var generator = new AttributeGenerator(); Assert.Throws(typeof(InvalidOperationException), () => generator.Generate(123)); }
protected override TypeGenerator OnGenerateType(ref string output, NamespaceGenerator @namespace) { var @class = ClassGenerator.Class(RootAccessModifier.Public, ClassModifier.None, Data.title.LegalMemberName(), Data.scriptableObject ? typeof(ScriptableObject) : typeof(object)); if (Data.definedEvent) { @class.ImplementInterface(typeof(IDefinedEvent)); } if (Data.inspectable) { @class.AddAttribute(AttributeGenerator.Attribute <InspectableAttribute>()); } if (Data.serialized) { @class.AddAttribute(AttributeGenerator.Attribute <SerializableAttribute>()); } if (Data.includeInSettings) { @class.AddAttribute(AttributeGenerator.Attribute <IncludeInSettingsAttribute>().AddParameter(true)); } if (Data.scriptableObject) { @class.AddAttribute(AttributeGenerator.Attribute <CreateAssetMenuAttribute>().AddParameter("menuName", Data.menuName).AddParameter("fileName", Data.fileName).AddParameter("order", Data.order)); } for (int i = 0; i < Data.constructors.Count; i++) { var constructor = ConstructorGenerator.Constructor(Data.constructors[i].scope, Data.constructors[i].modifier, Data.title.LegalMemberName()); if (Data.constructors[i].graph.units.Count > 0) { var unit = Data.constructors[i].graph.units[0] as FunctionNode; constructor.Body(FunctionNodeGenerator.GetSingleDecorator(unit, unit).GenerateControl(null, new ControlGenerationData(), 0)); for (int pIndex = 0; pIndex < Data.constructors[i].parameters.Count; pIndex++) { if (!string.IsNullOrEmpty(Data.constructors[i].parameters[pIndex].name)) { constructor.AddParameter(false, ParameterGenerator.Parameter(Data.constructors[i].parameters[pIndex].name, Data.constructors[i].parameters[pIndex].type, ParameterModifier.None)); } } } @class.AddConstructor(constructor); } for (int i = 0; i < Data.variables.Count; i++) { if (!string.IsNullOrEmpty(Data.variables[i].name) && Data.variables[i].type != null) { var attributes = Data.variables[i].attributes; if (Data.variables[i].isProperty) { var property = PropertyGenerator.Property(Data.variables[i].scope, Data.variables[i].propertyModifier, Data.variables[i].type, Data.variables[i].name, false); for (int attrIndex = 0; attrIndex < attributes.Count; attrIndex++) { AttributeGenerator attrGenerator = AttributeGenerator.Attribute(attributes[attrIndex].GetAttributeType()); property.AddAttribute(attrGenerator); } if (Data.variables[i].get) { property.MultiStatementGetter(AccessModifier.Public, NodeGenerator.GetSingleDecorator(Data.variables[i].getter.graph.units[0] as Unit, Data.variables[i].getter.graph.units[0] as Unit) .GenerateControl(null, new ControlGenerationData() { returns = Data.variables[i].type }, 0)); } if (Data.variables[i].set) { property.MultiStatementSetter(AccessModifier.Public, NodeGenerator.GetSingleDecorator(Data.variables[i].setter.graph.units[0] as Unit, Data.variables[i].setter.graph.units[0] as Unit) .GenerateControl(null, new ControlGenerationData(), 0)); } @class.AddProperty(property); } else { var field = FieldGenerator.Field(Data.variables[i].scope, Data.variables[i].fieldModifier, Data.variables[i].type, Data.variables[i].name); for (int attrIndex = 0; attrIndex < attributes.Count; attrIndex++) { AttributeGenerator attrGenerator = AttributeGenerator.Attribute(attributes[attrIndex].GetAttributeType()); field.AddAttribute(attrGenerator); } @class.AddField(field); } } } for (int i = 0; i < Data.methods.Count; i++) { if (!string.IsNullOrEmpty(Data.methods[i].name) && Data.methods[i].returnType != null) { var method = MethodGenerator.Method(Data.methods[i].scope, Data.methods[i].modifier, Data.methods[i].returnType, Data.methods[i].name); if (Data.methods[i].graph.units.Count > 0) { var unit = Data.methods[i].graph.units[0] as FunctionNode; method.Body(FunctionNodeGenerator.GetSingleDecorator(unit, unit).GenerateControl(null, new ControlGenerationData(), 0)); for (int pIndex = 0; pIndex < Data.methods[i].parameters.Count; pIndex++) { if (!string.IsNullOrEmpty(Data.methods[i].parameters[pIndex].name)) { method.AddParameter(ParameterGenerator.Parameter(Data.methods[i].parameters[pIndex].name, Data.methods[i].parameters[pIndex].type, ParameterModifier.None)); } } } @class.AddMethod(method); } } @namespace.AddClass(@class); return(@class); }
public AttributeGeneratorTests() { _sut = new AttributeGenerator(); }
public void NullDataTest() { var generator = new AttributeGenerator(); Assert.Throws(typeof(ArgumentNullException), () => generator.Generate(null)); }
public void Create_WhenCreatingWithSingleAttrbute_ShouldGenerateCorrectCode() { Assert.AreEqual("[Test]", AttributeGenerator.Create(new Attribute("Test", new List <IArgument>())).ToString()); }
public string LiteralDataTest(string data) { var generator = new AttributeGenerator(); return(generator.Generate(data)); }
private void GenerateInheritedMethods(Smoke.Class *klass, MethodsGenerator methgen, AttributeGenerator attrgen, List <Smoke.ModuleIndex> alreadyImplemented) { // Contains inherited methods that have to be implemented by the current class. // We use our custom comparer, so we don't end up with the same method multiple times. IDictionary <Smoke.ModuleIndex, string> implementMethods = new Dictionary <Smoke.ModuleIndex, string>(SmokeMethodEqualityComparer.DefaultEqualityComparer); bool firstParent = true; for (short *parent = data.Smoke->inheritanceList + klass->parents; *parent > 0; parent++) { if (firstParent) { // we're only interested in parents implemented as interfaces firstParent = false; continue; } // collect all methods (+ inherited ones) and add them to the implementMethods Dictionary data.Smoke->FindAllMethods(*parent, implementMethods, true); } foreach (KeyValuePair <Smoke.ModuleIndex, string> pair in implementMethods) { Smoke.Method *meth = pair.Key.smoke->methods + pair.Key.index; Smoke.Class * ifaceKlass = pair.Key.smoke->classes + meth->classId; if ((meth->flags & (ushort)Smoke.MethodFlags.mf_enum) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_ctor) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_copyctor) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_dtor) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_static) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_internal) > 0) { // no need to check for properties here - QObjects don't support multiple inheritance anyway continue; } if (alreadyImplemented.Contains(pair.Key, SmokeMethodEqualityComparer.DefaultEqualityComparer)) { continue; } if ((meth->flags & (ushort)Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(pair.Key.smoke, meth); continue; } CodeTypeReference type = translator.CppToCSharp(ByteArrayManager.GetString(ifaceKlass->className)); methgen.GenerateMethod(pair.Key.smoke, meth, pair.Value, type); } }
public override string Generate(int indent) { NamespaceGenerator @namespace = NamespaceGenerator.Namespace("Unity.VisualScripting.Community.Generated"); if (Data != null) { var title = GetCompoundTitle(); var delegateType = DelegateType; Data.title = title; if (!string.IsNullOrEmpty(Data.category)) { @namespace = NamespaceGenerator.Namespace(Data.category); } var @class = ClassGenerator.Class(RootAccessModifier.Public, ClassModifier.None, title, typeof(object)).ImplementInterface(delegateType); var properties = string.Empty; var method = Data.type.type.GetMethod("Invoke"); var parameterUsings = new List <string>(); var parameters = method.GetParameters(); var parameterNames = new List <string>(); var something = new Dictionary <ParameterInfo, string>(); for (int i = 0; i < parameters.Length; i++) { properties += " new".ConstructHighlight() + " TypeParam".TypeHighlight() + "() { name = " + $@"""{parameters[i].Name}""".StringHighlight() + ", type = " + "typeof".ConstructHighlight() + "(" + (parameters[i].ParameterType.IsGenericParameter ? Data.generics[i].type.type.As().CSharpName() : parameters[i].ParameterType.As().CSharpName()) + ") }"; if (!parameterUsings.Contains(parameters[i].ParameterType.Namespace)) { parameterUsings.Add(parameters[i].ParameterType.Namespace); } if (i < parameters.Length - 1) { properties += ", "; } } @class.AddUsings(parameterUsings); if (string.IsNullOrEmpty(properties)) { properties += " "; } else { properties = " " + properties + " "; } var displayName = string.IsNullOrEmpty(Data.displayName) ? Data.type.type.As().CSharpName().RemoveHighlights().RemoveMarkdown() : Data.displayName; var constructors = Data.type.type.GetConstructors(); var constructorParameters = constructors[constructors.Length - 1 > 0 ? 1 : 0]; var stringConstructorParameters = new List <string>(); var constParams = parameters.ToListPooled(); var assignParams = string.Empty; if (constParams.Count <= 0) { } var constParamsLength = constParams.Count; var invokeString = string.Empty; for (int i = constParamsLength - 1; i >= 0; i--) { if (constParams[i].Name == "object" || constParams[i].Name == "method") { constParams.Remove(constParams[i]); } } for (int i = 0; i < constParams.Count; i++) { assignParams += constParams[i].Name.EnsureNonConstructName().Replace("&", string.Empty); stringConstructorParameters.Add(constParams[i].Name.EnsureNonConstructName().Replace("&", string.Empty)); if (i < constParams.Count - 1) { assignParams += ", "; } } var remappedGenerics = string.Empty; var remappedGeneric = Data.type.type.Name.EnsureNonConstructName(); for (int i = 0; i < Data.generics.Count; i++) { remappedGenerics += Data.generics[i].type.type.As().CSharpName().Replace("&", string.Empty); if (i < Data.generics.Count - 1) { remappedGenerics += ", "; } } if (Data.generics.Count - 1 >= 0 || IsAction) { for (int i = 0; i < (IsAction ? Data.generics.Count : Mathf.Clamp(Data.generics.Count - 1, 0, Data.generics.Count)); i++) { if (i < Data.generics.Count - 1 || IsAction) { invokeString += $"({ Data.generics[i].type.type.As().CSharpName().Replace("&", string.Empty)})parameters[{i.ToString()}]"; if (i < Data.generics.Count - (IsAction ? 1 : 2)) { invokeString += ", "; } } } } if (Data.generics.Count > 0) { remappedGeneric = remappedGeneric.Contains("`") ? remappedGeneric.Remove(remappedGeneric.IndexOf("`"), remappedGeneric.Length - remappedGeneric.IndexOf("`")) : remappedGeneric; remappedGeneric = remappedGeneric.TypeHighlight() + "<" + remappedGenerics + ">"; } else { remappedGeneric.TypeHighlight(); } @class.AddField(FieldGenerator.Field(AccessModifier.Public, FieldModifier.None, remappedGeneric, Data.type.type.Namespace, "callback")); @class.AddField(FieldGenerator.Field(AccessModifier.Public, FieldModifier.None, remappedGeneric, Data.type.type.Namespace, "instance")); @class.AddField(FieldGenerator.Field(AccessModifier.Private, FieldModifier.None, typeof(bool), "_initialized")); @class.AddProperty(PropertyGenerator.Property(AccessModifier.Public, PropertyModifier.None, typeof(TypeParam), "parameters", false).SingleStatementGetter(AccessModifier.Public, "new".ConstructHighlight() + " TypeParam".TypeHighlight() + "[] {" + properties.Replace("&", string.Empty) + "}").AddTypeIndexer("")); @class.AddProperty(PropertyGenerator.Property(AccessModifier.Public, PropertyModifier.None, typeof(string), "DisplayName", false).SingleStatementGetter(AccessModifier.Public, $@"""{remappedGeneric.RemoveHighlights().RemoveMarkdown().Replace("<", " (").Replace(">", ")")}""".StringHighlight())); @class.AddProperty(PropertyGenerator.Property(AccessModifier.Public, PropertyModifier.None, typeof(bool), "initialized", false).SingleStatementGetter(AccessModifier.Public, "_initialized").SingleStatementSetter(AccessModifier.Public, "_initialized = value")); if (IsFunc) { @class.AddProperty(PropertyGenerator.Property(AccessModifier.Public, PropertyModifier.None, typeof(Type), "ReturnType", false).SingleStatementGetter(AccessModifier.Public, "typeof".ConstructHighlight() + "(" + Data.generics[Data.generics.Count - 1].type.type.As().CSharpName() + ")")); } @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, typeof(Type), "GetDelegateType").Body("return typeof".ConstructHighlight() + "(" + remappedGeneric + ");")); @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, typeof(object), "GetDelegate").Body("return".ConstructHighlight() + " callback;")); @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, IsAction ? typeof(void) : typeof(object), IsAction ? "Invoke" : "DynamicInvoke").AddParameter(ParameterGenerator.Parameter("parameters", typeof(object[]), Libraries.CSharp.ParameterModifier.None, isParameters: true)).Body($"{(IsAction ? string.Empty : "return").ConstructHighlight()} callback({invokeString});")); if (!IsAction) { @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, Data.generics[Mathf.Clamp(Data.generics.Count - 1, 0, Data.generics.Count - 1)].type.type, "Invoke").AddParameter(ParameterGenerator.Parameter("parameters", typeof(object[]), Libraries.CSharp.ParameterModifier.None, isParameters: true)).Body($"{(IsAction ? string.Empty : "return").ConstructHighlight()} callback({invokeString});")); } @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, typeof(void), "Initialize"). AddParameter(ParameterGenerator.Parameter("flow", typeof(Flow), Libraries.CSharp.ParameterModifier.None)). AddParameter(ParameterGenerator.Parameter("unit", IsAction ? typeof(ActionNode) : typeof(FuncNode), Libraries.CSharp.ParameterModifier.None)). AddParameter(ParameterGenerator.Parameter(IsAction ? "flowAction" : "flowFunc", IsAction ? typeof(Action) : typeof(Func <object>), Libraries.CSharp.ParameterModifier.None)). Body("SetInstance(flow, unit, " + (IsAction ? "flowAction" : "flowFunc") + "); \n" + "callback = " + "new ".ConstructHighlight() + remappedGeneric + "(" + LambdaGenerator.SingleLine(stringConstructorParameters, (!IsAction ? "return".ConstructHighlight() + " " : string.Empty) + $"instance({assignParams});").Generate(0) + ");\n" + "initialized = " + "true".ConstructHighlight() + ";")); @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, typeof(void), "SetInstance"). AddParameter(ParameterGenerator.Parameter("flow", typeof(Flow), Libraries.CSharp.ParameterModifier.None)). AddParameter(ParameterGenerator.Parameter("unit", IsAction ? typeof(ActionNode) : typeof(FuncNode), Libraries.CSharp.ParameterModifier.None)). AddParameter(ParameterGenerator.Parameter(IsAction ? "flowAction" : "flowFunc", IsAction ? typeof(Action) : typeof(Func <object>), Libraries.CSharp.ParameterModifier.None)). Body("instance = " + "new ".ConstructHighlight() + remappedGeneric + "(" + LambdaGenerator.SingleLine(stringConstructorParameters, (stringConstructorParameters.Count > 0 ? "unit.AssignParameters(flow, " + assignParams + "); " + (IsAction ? "flowAction();" : "return ".ConstructHighlight() + "(" + Data.generics[Data.generics.Count - 1].type.type.As().CSharpName() + ")" + "flowFunc();") : (IsAction ? "flowAction();" : "return ".ConstructHighlight() + "(" + Data.generics[Data.generics.Count - 1].type.type.As().CSharpName() + ")" + "flowFunc();"))).Generate(0) + ");")); @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, typeof(void), "Bind"). AddParameter(ParameterGenerator.Parameter("other", typeof(IDelegate), Libraries.CSharp.ParameterModifier.None)) .Body( "callback += (" + remappedGeneric + ")other.GetDelegate();" )); @class.AddMethod(MethodGenerator.Method(AccessModifier.Public, MethodModifier.None, typeof(void), "Unbind"). AddParameter(ParameterGenerator.Parameter("other", typeof(IDelegate), Libraries.CSharp.ParameterModifier.None)) .Body( "callback -= (" + remappedGeneric + ")other.GetDelegate();" )); @class.AddUsings(new List <string>() { Data.type.type.Namespace, "System" }); @class.AddAttribute(AttributeGenerator.Attribute <IncludeInSettingsAttribute>().AddParameter(true)); if (Data.lastCompiledName != Data.GetFullTypeName()) { @class.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName)); } var genericNamespace = new List <string>(); for (int i = 0; i < Data.generics.Count; i++) { if (!genericNamespace.Contains(Data.generics[i].type.type.Namespace)) { genericNamespace.Add(Data.generics[i].type.type.Namespace); } } @class.AddUsings(genericNamespace); @namespace.AddClass(@class); return(@namespace.Generate(indent)); } return(string.Empty); }
/* * Adds the methods to the classes created by Run() */ private void GenerateMethods(IList<IntPtr> excludedMethods) { List<Smoke.ModuleIndex> alreadyImplemented = new List<Smoke.ModuleIndex>(); this.FillEnums(); Dictionary<short, List<Smoke.MethodMap>> dictionary = new Dictionary<short, List<Smoke.MethodMap>>(); List<short> classes = new List<short>(); for (short i = 1; i < data.Smoke->numMethodMaps; i++) { Smoke.MethodMap* map = data.Smoke->methodMaps + i; if (!dictionary.ContainsKey(map->classId)) { dictionary.Add(map->classId, new List<Smoke.MethodMap>()); } dictionary[map->classId].Add(*map); if (!classes.Contains(map->classId)) { classes.Add(map->classId); } } foreach (KeyValuePair<short, List<Smoke.MethodMap>> pair in dictionary.OrderBy(k => { int chainLength = 0; Smoke.Class* klass = data.Smoke->classes + k.Key; short* parent = data.Smoke->inheritanceList + klass->parents; while (*parent > 0) { ++chainLength; klass = data.Smoke->classes + *parent; parent = data.Smoke->inheritanceList + klass->parents; } return chainLength; })) { Smoke.Class* klass = data.Smoke->classes + pair.Key; CodeTypeDeclaration type = data.SmokeTypeMap[(IntPtr) klass]; alreadyImplemented.Clear(); AttributeGenerator attrgen = new AttributeGenerator(data, translator, type); MethodsGenerator methgen = new MethodsGenerator(data, translator, type, klass); foreach (Smoke.MethodMap map in pair.Value) { string mungedName = ByteArrayManager.GetString(data.Smoke->methodNames[map.name]); if (map.method > 0) { Smoke.Method* meth = data.Smoke->methods + map.method; if (excludedMethods.Contains((IntPtr) meth) || (meth->flags & (ushort) Smoke.MethodFlags.mf_enum) > 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_property) > 0 // non-virtual properties are excluded && (meth->flags & (ushort) Smoke.MethodFlags.mf_virtual) == 0 && (meth->flags & (ushort) Smoke.MethodFlags.mf_purevirtual) == 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(meth); continue; } methgen.GenerateMethod(map.method, mungedName); alreadyImplemented.Add(new Smoke.ModuleIndex(data.Smoke, map.method)); } else if (map.method < 0) { for (short* overload = data.Smoke->ambiguousMethodList + (-map.method); *overload > 0; overload++) { Smoke.Method* meth = data.Smoke->methods + *overload; if (excludedMethods.Contains((IntPtr) meth) || (meth->flags & (ushort) Smoke.MethodFlags.mf_enum) > 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_property) > 0 // non-virtual properties are excluded && (meth->flags & (ushort) Smoke.MethodFlags.mf_virtual) == 0 && (meth->flags & (ushort) Smoke.MethodFlags.mf_purevirtual) == 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(meth); continue; } // if the methods differ only by constness, we will generate special code bool nextDiffersByConst = false; if (*(overload + 1) > 0) { if (SmokeMethodEqualityComparer.EqualExceptConstness(meth, data.Smoke->methods + *(overload + 1))) nextDiffersByConst = true; } methgen.GenerateMethod(*overload, mungedName); alreadyImplemented.Add(new Smoke.ModuleIndex(data.Smoke, *overload)); if (nextDiffersByConst) overload++; } } } // generate inherited methods this.GenerateInheritedMethods(klass, methgen, attrgen, alreadyImplemented); // generate all scheduled attributes attrgen.Run(); methgen.GenerateProperties(); } foreach (short @class in classes) { Smoke.Class* klass = data.Smoke->classes + @class; CodeTypeDeclaration type = data.SmokeTypeMap[(IntPtr) klass]; if (PostMembersHooks != null) { PostMembersHooks(this.data.Smoke, klass, type); } } AddMissingOperators(); }
public void Run() { HashSet <short> interfaceClasses = GetClassList(); // Make the interfaces known first, otherwise Translator won't work correctly. foreach (short idx in interfaceClasses) { Smoke.Class *klass = data.Smoke->classes + idx; string className = ByteArrayManager.GetString(klass->className); int colon = className.LastIndexOf("::", StringComparison.Ordinal); string prefix = (colon != -1) ? className.Substring(0, colon) : string.Empty; string name = (colon != -1) ? className.Substring(colon + 2) : className; CodeTypeDeclaration ifaceDecl = new CodeTypeDeclaration('I' + name); ifaceDecl.IsInterface = true; CodeAttributeDeclaration attr = new CodeAttributeDeclaration("SmokeClass", new CodeAttributeArgument( new CodePrimitiveExpression(className))); ifaceDecl.CustomAttributes.Add(attr); data.GetTypeCollection(prefix).Add(ifaceDecl); data.InterfaceTypeMap[className] = ifaceDecl; } // Now generate the methods. foreach (short idx in interfaceClasses) { Smoke.Class * klass = data.Smoke->classes + idx; string className = ByteArrayManager.GetString(klass->className); CodeTypeDeclaration ifaceDecl = data.InterfaceTypeMap[className]; short *parent = data.Smoke->inheritanceList + klass->parents; while (*parent > 0) { ifaceDecl.BaseTypes.Add(translator.CppToCSharp(data.Smoke->classes + *parent)); parent++; } MethodsGenerator mg = new MethodsGenerator(data, translator, ifaceDecl, klass); AttributeGenerator ag = new AttributeGenerator(data, translator, ifaceDecl); List <IntPtr> methods = new List <IntPtr>(); ///TODO: replace this algorithm, it's highly inefficient for (short i = 0; i <= data.Smoke->numMethods && data.Smoke->methods[i].classId <= idx; i++) { Smoke.Method *meth = data.Smoke->methods + i; if (meth->classId != idx) { continue; } string methName = ByteArrayManager.GetString(data.Smoke->methodNames[meth->name]); // we don't want anything except protected, const or empty flags if ((meth->flags & (ushort)Smoke.MethodFlags.mf_enum) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_ctor) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_copyctor) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_dtor) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_static) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_internal) > 0 || (meth->flags & (ushort)Smoke.MethodFlags.mf_protected) > 0 || methName.StartsWith("operator")) { continue; } if ((meth->flags & (ushort)Smoke.MethodFlags.mf_attribute) > 0) { ag.ScheduleAttributeAccessor(meth); continue; } methods.Add((IntPtr)meth); } methods.Sort(CompareSmokeMethods); foreach (Smoke.Method *method in methods) { CodeMemberMethod cmm = mg.GenerateBasicMethodDefinition(data.Smoke, method); if (cmm != null && !ifaceDecl.HasMethod(cmm)) { ifaceDecl.Members.Add(cmm); } } mg.GenerateProperties(); foreach (CodeMemberProperty prop in ag.GenerateBasicAttributeDefinitions()) { ifaceDecl.Members.Add(prop); } } }
public void Create_WhenCreatingWithMultipleAttributes_ShouldGenerateCorrectCode() { Assert.AreEqual("[Test][TestCase]", AttributeGenerator.Create(new Attribute("Test"), new Attribute("TestCase")).ToString()); }
private void GenerateInheritedMethods(Smoke.Class* klass, MethodsGenerator methgen, AttributeGenerator attrgen, List<Smoke.ModuleIndex> alreadyImplemented) { // Contains inherited methods that have to be implemented by the current class. // We use our custom comparer, so we don't end up with the same method multiple times. IDictionary<Smoke.ModuleIndex, string> implementMethods = new Dictionary<Smoke.ModuleIndex, string>(SmokeMethodEqualityComparer.DefaultEqualityComparer); bool firstParent = true; for (short* parent = data.Smoke->inheritanceList + klass->parents; *parent > 0; parent++) { if (firstParent) { // we're only interested in parents implemented as interfaces firstParent = false; continue; } // collect all methods (+ inherited ones) and add them to the implementMethods Dictionary data.Smoke->FindAllMethods(*parent, implementMethods, true); } foreach (KeyValuePair<Smoke.ModuleIndex, string> pair in implementMethods) { Smoke.Method* meth = pair.Key.smoke->methods + pair.Key.index; Smoke.Class* ifaceKlass = pair.Key.smoke->classes + meth->classId; if ((meth->flags & (ushort) Smoke.MethodFlags.mf_enum) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_ctor) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_copyctor) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_dtor) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_static) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_internal) > 0) { // no need to check for properties here - QObjects don't support multiple inheritance anyway continue; } if (alreadyImplemented.Contains(pair.Key, SmokeMethodEqualityComparer.DefaultEqualityComparer)) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(pair.Key.smoke, meth); continue; } CodeTypeReference type = translator.CppToCSharp(ByteArrayManager.GetString(ifaceKlass->className)); methgen.GenerateMethod(pair.Key.smoke, meth, pair.Value, type); } }
public void Run() { HashSet<short> interfaceClasses = GetClassList(); // Make the interfaces known first, otherwise Translator won't work correctly. foreach (short idx in interfaceClasses) { Smoke.Class* klass = data.Smoke->classes + idx; string className = ByteArrayManager.GetString(klass->className); int colon = className.LastIndexOf("::", StringComparison.Ordinal); string prefix = (colon != -1) ? className.Substring(0, colon) : string.Empty; string name = (colon != -1) ? className.Substring(colon + 2) : className; CodeTypeDeclaration ifaceDecl = new CodeTypeDeclaration('I' + name); ifaceDecl.IsInterface = true; CodeAttributeDeclaration attr = new CodeAttributeDeclaration("SmokeClass", new CodeAttributeArgument( new CodePrimitiveExpression(className))); ifaceDecl.CustomAttributes.Add(attr); data.GetTypeCollection(prefix).Add(ifaceDecl); data.InterfaceTypeMap[className] = ifaceDecl; } // Now generate the methods. foreach (short idx in interfaceClasses) { Smoke.Class* klass = data.Smoke->classes + idx; string className = ByteArrayManager.GetString(klass->className); CodeTypeDeclaration ifaceDecl = data.InterfaceTypeMap[className]; short* parent = data.Smoke->inheritanceList + klass->parents; while (*parent > 0) { ifaceDecl.BaseTypes.Add(translator.CppToCSharp(data.Smoke->classes + *parent, ifaceDecl)); parent++; } MethodsGenerator mg = new MethodsGenerator(data, translator, ifaceDecl, klass); AttributeGenerator ag = new AttributeGenerator(data, translator, ifaceDecl); List<IntPtr> methods = new List<IntPtr>(); ///TODO: replace this algorithm, it's highly inefficient for (short i = 0; i <= data.Smoke->numMethods && data.Smoke->methods[i].classId <= idx; i++) { Smoke.Method* meth = data.Smoke->methods + i; if (meth->classId != idx) continue; string methName = ByteArrayManager.GetString(data.Smoke->methodNames[meth->name]); // we don't want anything except protected, const or empty flags if ((meth->flags & (ushort) Smoke.MethodFlags.mf_enum) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_ctor) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_copyctor) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_dtor) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_static) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_internal) > 0 || (meth->flags & (ushort) Smoke.MethodFlags.mf_protected) > 0 || methName.StartsWith("operator")) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_attribute) > 0) { ag.ScheduleAttributeAccessor(meth); continue; } methods.Add((IntPtr) meth); } methods.Sort(CompareSmokeMethods); foreach (Smoke.Method* method in methods) { CodeMemberMethod cmm = mg.GenerateBasicMethodDefinition(data.Smoke, method); if (cmm != null && !ifaceDecl.HasMethod(cmm)) { ifaceDecl.Members.Add(cmm); } } mg.GenerateProperties(); foreach (CodeMemberProperty prop in ag.GenerateBasicAttributeDefinitions()) { ifaceDecl.Members.Add(prop); } } }
/* * Adds the methods to the classes created by Run() */ private void GenerateMethods() { short currentClassId = 0; Smoke.Class* klass = (Smoke.Class*) IntPtr.Zero; MethodsGenerator methgen = null; AttributeGenerator attrgen = null; CodeTypeDeclaration type = null; List<Smoke.ModuleIndex> alreadyImplemented = new List<Smoke.ModuleIndex>(); this.FillEnums(); for (short i = 1; i < data.Smoke->numMethodMaps; i++) { Smoke.MethodMap* map = data.Smoke->methodMaps + i; if (currentClassId != map->classId) { // we encountered a new class if (attrgen != null) { // generate inherited methods this.GenerateInheritedMethods(klass, methgen, attrgen, alreadyImplemented); // generate all scheduled attributes attrgen.Run(); if (PostMembersHooks != null) { PostMembersHooks(data.Smoke, klass, type); } methgen.GenerateProperties(); } currentClassId = map->classId; klass = data.Smoke->classes + currentClassId; type = data.SmokeTypeMap[(IntPtr) klass]; alreadyImplemented.Clear(); attrgen = new AttributeGenerator(data, translator, type); methgen = new MethodsGenerator(data, translator, type, klass); } string mungedName = ByteArrayManager.GetString(data.Smoke->methodNames[map->name]); if (map->method > 0) { Smoke.Method* meth = data.Smoke->methods + map->method; if ((meth->flags & (ushort) Smoke.MethodFlags.mf_enum) > 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_property) > 0 // non-virtual properties are excluded && (meth->flags & (ushort) Smoke.MethodFlags.mf_virtual) == 0 && (meth->flags & (ushort) Smoke.MethodFlags.mf_purevirtual) == 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(meth); continue; } methgen.GenerateMethod(map->method, mungedName); alreadyImplemented.Add(new Smoke.ModuleIndex(data.Smoke, map->method)); } else if (map->method < 0) { for (short* overload = data.Smoke->ambiguousMethodList + (-map->method); *overload > 0; overload++) { Smoke.Method* meth = data.Smoke->methods + *overload; if ((meth->flags & (ushort) Smoke.MethodFlags.mf_enum) > 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_property) > 0 // non-virtual properties are excluded && (meth->flags & (ushort) Smoke.MethodFlags.mf_virtual) == 0 && (meth->flags & (ushort) Smoke.MethodFlags.mf_purevirtual) == 0) { continue; } if ((meth->flags & (ushort) Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(meth); continue; } // if the methods differ only by constness, we will generate special code bool nextDiffersByConst = false; if (*(overload + 1) > 0) { if (SmokeMethodEqualityComparer.EqualExceptConstness(meth, data.Smoke->methods + *(overload + 1))) nextDiffersByConst = true; } methgen.GenerateMethod(*overload, mungedName); alreadyImplemented.Add(new Smoke.ModuleIndex(data.Smoke, *overload)); if (nextDiffersByConst) overload++; } } } // Generate the last scheduled attributes attrgen.Run(); // Generate remaining inherited methods this.GenerateInheritedMethods(klass, methgen, attrgen, alreadyImplemented); if (PostMembersHooks != null) { PostMembersHooks(data.Smoke, klass, type); } methgen.GenerateProperties(); AddMissingOperators(); }
/* * Adds the methods to the classes created by Run() */ private void GenerateMethods() { short currentClassId = 0; Smoke.Class * klass = (Smoke.Class *)IntPtr.Zero; MethodsGenerator methgen = null; AttributeGenerator attrgen = null; CodeTypeDeclaration type = null; List <Smoke.ModuleIndex> alreadyImplemented = new List <Smoke.ModuleIndex>(); this.FillEnums(); for (short i = 1; i < data.Smoke->numMethodMaps; i++) { Smoke.MethodMap *map = data.Smoke->methodMaps + i; if (currentClassId != map->classId) { // we encountered a new class if (attrgen != null) { // generate inherited methods this.GenerateInheritedMethods(klass, methgen, attrgen, alreadyImplemented); // generate all scheduled attributes attrgen.Run(); if (PostMembersHooks != null) { PostMembersHooks(data.Smoke, klass, type); } methgen.GenerateProperties(); } currentClassId = map->classId; klass = data.Smoke->classes + currentClassId; type = data.SmokeTypeMap[(IntPtr)klass]; alreadyImplemented.Clear(); attrgen = new AttributeGenerator(data, translator, type); methgen = new MethodsGenerator(data, translator, type, klass); } string mungedName = ByteArrayManager.GetString(data.Smoke->methodNames[map->name]); if (map->method > 0) { Smoke.Method *meth = data.Smoke->methods + map->method; if ((meth->flags & (ushort)Smoke.MethodFlags.mf_enum) > 0) { continue; } if ((meth->flags & (ushort)Smoke.MethodFlags.mf_property) > 0 && // non-virtual properties are excluded (meth->flags & (ushort)Smoke.MethodFlags.mf_virtual) == 0 && (meth->flags & (ushort)Smoke.MethodFlags.mf_purevirtual) == 0) { continue; } if ((meth->flags & (ushort)Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(meth); continue; } methgen.GenerateMethod(map->method, mungedName); alreadyImplemented.Add(new Smoke.ModuleIndex(data.Smoke, map->method)); } else if (map->method < 0) { for (short *overload = data.Smoke->ambiguousMethodList + (-map->method); *overload > 0; overload++) { Smoke.Method *meth = data.Smoke->methods + *overload; if ((meth->flags & (ushort)Smoke.MethodFlags.mf_enum) > 0) { continue; } if ((meth->flags & (ushort)Smoke.MethodFlags.mf_property) > 0 && // non-virtual properties are excluded (meth->flags & (ushort)Smoke.MethodFlags.mf_virtual) == 0 && (meth->flags & (ushort)Smoke.MethodFlags.mf_purevirtual) == 0) { continue; } if ((meth->flags & (ushort)Smoke.MethodFlags.mf_attribute) > 0) { attrgen.ScheduleAttributeAccessor(meth); continue; } // if the methods differ only by constness, we will generate special code bool nextDiffersByConst = false; if (*(overload + 1) > 0) { if (SmokeMethodEqualityComparer.EqualExceptConstness(meth, data.Smoke->methods + *(overload + 1))) { nextDiffersByConst = true; } } methgen.GenerateMethod(*overload, mungedName); alreadyImplemented.Add(new Smoke.ModuleIndex(data.Smoke, *overload)); if (nextDiffersByConst) { overload++; } } } } // Generate the last scheduled attributes attrgen.Run(); // Generate remaining inherited methods this.GenerateInheritedMethods(klass, methgen, attrgen, alreadyImplemented); if (PostMembersHooks != null) { PostMembersHooks(data.Smoke, klass, type); } methgen.GenerateProperties(); AddMissingOperators(); }
public override string Generate(int indent) { if (Data != null) { var output = string.Empty; NamespaceGenerator @namespace = NamespaceGenerator.Namespace(Data.category); InterfaceGenerator @interface = InterfaceGenerator.Interface(Data.title.LegalMemberName()); if (string.IsNullOrEmpty(Data.title)) { return(output); } for (int i = 0; i < Data.variables.Count; i++) { var prop = Data.variables[i]; if (string.IsNullOrEmpty(prop.name) || prop.type == null) { continue; } if (!prop.get && !prop.set) { prop.get = true; } @interface.AddProperty(InterfacePropertyGenerator.Property(prop.name, prop.type, prop.get, prop.set)); } for (int i = 0; i < Data.methods.Count; i++) { var method = Data.methods[i]; if (string.IsNullOrEmpty(method.name) || method.returnType == null) { continue; } var methodGen = InterfaceMethodGenerator.Method(method.name, method.returnType); for (int paramIndex = 0; paramIndex < Data.methods[i].parameters.Count; paramIndex++) { var parameter = Data.methods[i].parameters[paramIndex]; if (string.IsNullOrEmpty(parameter.name) || parameter.type == null) { continue; } methodGen.AddParameter(ParameterGenerator.Parameter(parameter.name, parameter.type, parameter.modifier)); } @interface.AddMethod(methodGen); } #if VISUAL_SCRIPTING_1_7 if (Data.lastCompiledName != Data.GetFullTypeName() && !string.IsNullOrEmpty(Data.GetFullTypeName()) && !string.IsNullOrEmpty(Data.lastCompiledName)) { @interface.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName)); } #endif @namespace.AddInterface(@interface); return(@namespace.Generate(indent)); } return(string.Empty); }