public static void CheckValueTypeClone(ResolveResult resolveResult, Expression expression, IAbstractEmitterBlock block) { if (resolveResult == null || resolveResult.IsError) { return; } if (resolveResult is InvocationResolveResult || block.Emitter.IsAssignment) { return; } if (resolveResult.Type.Kind == TypeKind.Struct) { var typeDef = block.Emitter.GetTypeDefinition(resolveResult.Type); if (block.Emitter.Validator.IsIgnoreType(typeDef)) { return; } var memberResult = resolveResult as MemberResolveResult; var field = memberResult != null ? memberResult.Member as DefaultResolvedField : null; if (field != null && field.IsReadOnly) { block.Write(".$clone()"); return; } if (expression == null || expression.Parent is NamedExpression || expression.Parent is ObjectCreateExpression || expression.Parent is ArrayInitializerExpression || expression.Parent is ReturnStatement || expression.Parent is InvocationExpression || expression.Parent is AssignmentExpression || expression.Parent is VariableInitializer) { block.Write(".$clone()"); } } }
public static void CheckValueTypeClone(ResolveResult resolveResult, Expression expression, IAbstractEmitterBlock block) { if (resolveResult == null || resolveResult.IsError) { return; } if (resolveResult is InvocationResolveResult || block.Emitter.IsAssignment) { return; } if (resolveResult.Type.Kind == TypeKind.Struct) { var typeDef = block.Emitter.GetTypeDefinition(resolveResult.Type); if (block.Emitter.Validator.IsIgnoreType(typeDef)) { return; } var memberResult = resolveResult as MemberResolveResult; var field = memberResult != null ? memberResult.Member as DefaultResolvedField : null; if (field != null && field.IsReadOnly) { block.Write(".$clone()"); return; } if (expression == null || expression.Parent is NamedExpression || expression.Parent is ObjectCreateExpression || expression.Parent is ArrayInitializerExpression || expression.Parent is ReturnStatement || expression.Parent is InvocationExpression || expression.Parent is AssignmentExpression || expression.Parent is VariableInitializer) { block.Write(".$clone()"); } } }
private static void WriteClone(IAbstractEmitterBlock block, int insertPosition, bool nullable) { if (nullable) { block.Emitter.Output.Insert(insertPosition, JS.Types.SYSTEM_NULLABLE + "." + JS.Funcs.Math.LIFT1 + "(\"" + JS.Funcs.CLONE + "\", "); block.WriteCloseParentheses(); } else { block.Write("." + JS.Funcs.CLONE + "()"); } }
public static void CheckValueTypeClone(ResolveResult resolveResult, Expression expression, IAbstractEmitterBlock block, int insertPosition) { if (resolveResult == null || resolveResult.IsError) { return; } if (block.Emitter.IsAssignment) { return; } if (resolveResult is InvocationResolveResult) { bool ret = true; if (expression.Parent is InvocationExpression) { var invocationExpression = (InvocationExpression)expression.Parent; if (invocationExpression.Arguments.Any(a => a == expression)) { ret = false; } } else if (expression.Parent is AssignmentExpression) { ret = false; } else if (expression.Parent is VariableInitializer) { ret = false; } if (ret) { return; } } var nullable = resolveResult.Type.IsKnownType(KnownTypeCode.NullableOfT); var type = nullable ? ((ParameterizedType)resolveResult.Type).TypeArguments[0] : resolveResult.Type; if (type.Kind == TypeKind.Struct) { var typeDef = block.Emitter.GetTypeDefinition(type); if (block.Emitter.Validator.IsIgnoreType(typeDef) || block.Emitter.Validator.IsImmutableType(typeDef)) { return; } var mutableFields = type.GetFields(f => !f.IsReadOnly && !f.IsConst, GetMemberOptions.IgnoreInheritedMembers); var autoProps = typeDef.Properties.Where(Helpers.IsAutoProperty); var autoEvents = type.GetEvents(null, GetMemberOptions.IgnoreInheritedMembers); if (!mutableFields.Any() && !autoProps.Any() && !autoEvents.Any()) { return; } var memberResult = resolveResult as MemberResolveResult; var field = memberResult != null ? memberResult.Member as DefaultResolvedField : null; if (field != null && field.IsReadOnly) { if (nullable) { block.Emitter.Output.Insert(insertPosition, "Bridge.Nullable.lift1(\"$clone\", "); block.WriteCloseParentheses(); } else { block.Write(".$clone()"); } return; } if (expression == null || expression.Parent is NamedExpression || expression.Parent is ObjectCreateExpression || expression.Parent is ArrayInitializerExpression || expression.Parent is ReturnStatement || expression.Parent is InvocationExpression || expression.Parent is AssignmentExpression || expression.Parent is VariableInitializer) { if (expression.Parent is InvocationExpression) { var invocationExpression = (InvocationExpression)expression.Parent; if (invocationExpression.Target == expression) { return; } } if (nullable) { block.Emitter.Output.Insert(insertPosition, "Bridge.Nullable.lift1(\"$clone\", "); block.WriteCloseParentheses(); } else { block.Write(".$clone()"); } } } }
public static void EmitComment(IAbstractEmitterBlock block, AstNode node, bool?getter = null, VariableInitializer varInitializer = null) { if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.None || node.Parent == null) { return; } var visitor = new DocumentationCommentVisitor(); node.AcceptChildren(visitor); if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0) { return; } object value = null; var rr = block.Emitter.Resolver.ResolveNode(varInitializer ?? node, block.Emitter); string source = BuildCommentString(visitor.Comments); if (node is FieldDeclaration) { var initializer = varInitializer.Initializer as PrimitiveExpression; if (initializer != null) { value = initializer.Value; } } else if (node is EventDeclaration) { var eventDecl = (EventDeclaration)node; foreach (var evVar in eventDecl.Variables) { var ev_rr = block.Emitter.Resolver.ResolveNode(evVar, block.Emitter); var memberResolveResult = ev_rr as MemberResolveResult; var ev = memberResolveResult.Member as IEvent; if (!getter.HasValue || getter.Value) { var comment = new JsDocComment(); InitMember(comment, ev.AddAccessor, block.Emitter, null); comment.Function = Helpers.GetEventRef(ev, block.Emitter, false); block.Write( block.WriteIndentToString(XmlToJsDoc.ReadComment(source, ev_rr, block.Emitter, comment))); block.WriteNewLine(); } if (!getter.HasValue || !getter.Value) { var comment = new JsDocComment(); InitMember(comment, ev.RemoveAccessor, block.Emitter, null); comment.Function = Helpers.GetEventRef(ev, block.Emitter, true); block.Write( block.WriteIndentToString(XmlToJsDoc.ReadComment(source, ev_rr, block.Emitter, comment))); block.WriteNewLine(); } } return; } var prop = node as PropertyDeclaration; if (prop != null) { var memberResolveResult = rr as MemberResolveResult; var rProp = memberResolveResult.Member as IProperty; var comment = new JsDocComment(); InitMember(comment, rProp, block.Emitter, null); comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); return; } var indexer = node as IndexerDeclaration; if (indexer != null) { var memberResolveResult = rr as MemberResolveResult; var rProp = memberResolveResult.Member as IProperty; var comment = new JsDocComment(); InitMember(comment, getter.HasValue && getter.Value ? rProp.Getter : rProp.Setter, block.Emitter, null); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); return; } block.Write(block.WriteIndentToString(XmlToJsDoc.Convert(source, rr, block.Emitter, value))); block.WriteNewLine(); }
public static void EmitComment(IAbstractEmitterBlock block, AstNode node) { if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.None || node.Parent == null) { return; } var visitor = new DocumentationCommentVisitor(); node.AcceptChildren(visitor); if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0) { return; } object value = null; if (node is FieldDeclaration) { var fieldDecl = (FieldDeclaration)node; node = fieldDecl.Variables.First(); var initializer = fieldDecl.Variables.First().Initializer as PrimitiveExpression; if (initializer != null) { value = initializer.Value; } } else if (node is EventDeclaration) { var eventDecl = (EventDeclaration)node; node = eventDecl.Variables.First(); var initializer = eventDecl.Variables.First().Initializer as PrimitiveExpression; if (initializer != null) { value = initializer.Value; } } var rr = block.Emitter.Resolver.ResolveNode(node, block.Emitter); string source = BuildCommentString(visitor.Comments); var prop = node as PropertyDeclaration; if (prop != null) { var memberResolveResult = rr as MemberResolveResult; var rProp = memberResolveResult.Member as DefaultResolvedProperty; var comment = new JsDocComment(); InitMember(comment, rProp.Getter, block.Emitter, null); comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter, false); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); comment = new JsDocComment(); InitMember(comment, rProp.Setter, block.Emitter, null); comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter, true); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); return; } block.Write(block.WriteIndentToString(XmlToJsDoc.Convert(source, rr, block.Emitter, value))); block.WriteNewLine(); }
public static void EmitComment(IAbstractEmitterBlock block, AstNode node) { if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.None || node.Parent == null) { return; } var visitor = new DocumentationCommentVisitor(); node.AcceptChildren(visitor); if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0) { return; } object value = null; if (node is FieldDeclaration) { var fieldDecl = (FieldDeclaration)node; node = fieldDecl.Variables.First(); var initializer = fieldDecl.Variables.First().Initializer as PrimitiveExpression; if (initializer != null) { value = initializer.Value; } } else if (node is EventDeclaration) { var eventDecl = (EventDeclaration)node; node = eventDecl.Variables.First(); var initializer = eventDecl.Variables.First().Initializer as PrimitiveExpression; if (initializer != null) { value = initializer.Value; } } var rr = block.Emitter.Resolver.ResolveNode(node, block.Emitter); string source = BuildCommentString(visitor.Comments); var prop = node as PropertyDeclaration; if (prop != null) { var memberResolveResult = rr as MemberResolveResult; var rProp = memberResolveResult.Member as DefaultResolvedProperty; var comment = new JsDocComment(); InitMember(comment, rProp.Getter, block.Emitter, null); comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter, false); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); comment = new JsDocComment(); InitMember(comment, rProp.Setter, block.Emitter, null); comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter, true); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); return; } block.Write(block.WriteIndentToString(XmlToJsDoc.Convert(source, rr, block.Emitter, value))); block.WriteNewLine(); }
public static void CheckValueTypeClone(ResolveResult resolveResult, Expression expression, IAbstractEmitterBlock block, int insertPosition) { if (resolveResult == null || resolveResult.IsError) { return; } if (block.Emitter.IsAssignment) { return; } if (resolveResult is InvocationResolveResult) { bool ret = true; if (expression.Parent is InvocationExpression) { var invocationExpression = (InvocationExpression)expression.Parent; if (invocationExpression.Arguments.Any(a => a == expression)) { ret = false; } } else if (expression.Parent is AssignmentExpression) { ret = false; } if (ret) { return; } } var nullable = resolveResult.Type.IsKnownType(KnownTypeCode.NullableOfT); var type = nullable ? ((ParameterizedType)resolveResult.Type).TypeArguments[0] : resolveResult.Type; if (type.Kind == TypeKind.Struct) { var typeDef = block.Emitter.GetTypeDefinition(type); if (block.Emitter.Validator.IsIgnoreType(typeDef)) { return; } var mutableFields = type.GetFields(f => !f.IsReadOnly && !f.IsConst, GetMemberOptions.IgnoreInheritedMembers); var autoProps = typeDef.Properties.Where(Helpers.IsAutoProperty); var autoEvents = type.GetEvents(null, GetMemberOptions.IgnoreInheritedMembers); if (!mutableFields.Any() && !autoProps.Any() && !autoEvents.Any()) { return; } var memberResult = resolveResult as MemberResolveResult; var field = memberResult != null ? memberResult.Member as DefaultResolvedField : null; if (field != null && field.IsReadOnly) { if (nullable) { block.Emitter.Output.Insert(insertPosition, "Bridge.Nullable.lift1(\"$clone\", "); block.WriteCloseParentheses(); } else { block.Write(":__clone__()"); } return; } if (expression == null || expression.Parent is NamedExpression || expression.Parent is ObjectCreateExpression || expression.Parent is ArrayInitializerExpression || expression.Parent is ReturnStatement || expression.Parent is InvocationExpression || expression.Parent is AssignmentExpression || expression.Parent is VariableInitializer) { if (expression.Parent is InvocationExpression) { var invocationExpression = (InvocationExpression)expression.Parent; if (invocationExpression.Target == expression) { return; } } if (nullable) { block.Emitter.Output.Insert(insertPosition, "Bridge.Nullable.lift1(\"$clone\", "); block.WriteCloseParentheses(); } else { block.Write(":__clone__()"); } } } }
public static void CheckValueTypeClone(ResolveResult resolveResult, Expression expression, IAbstractEmitterBlock block, int insertPosition) { if (resolveResult == null || resolveResult.IsError) { return; } if (block.Emitter.IsAssignment) { return; } var conversion = block.Emitter.Resolver.Resolver.GetConversion(expression); if (conversion.IsBoxingConversion || conversion.IsUnboxingConversion) { return; } if (resolveResult is InvocationResolveResult) { bool ret = true; if (expression.Parent is InvocationExpression) { var invocationExpression = (InvocationExpression)expression.Parent; if (invocationExpression.Arguments.Any(a => a == expression)) { ret = false; } } else if (expression.Parent is AssignmentExpression) { ret = false; } else if (expression.Parent is VariableInitializer) { ret = false; } if (ret) { return; } } var rrtype = resolveResult.Type; var forEachResolveResult = resolveResult as ForEachResolveResult; if (forEachResolveResult != null) { rrtype = forEachResolveResult.ElementType; } var nullable = rrtype.IsKnownType(KnownTypeCode.NullableOfT); var type = nullable ? ((ParameterizedType)rrtype).TypeArguments[0] : rrtype; if (type.Kind == TypeKind.Struct) { if (Helpers.IsImmutableStruct(block.Emitter, type)) { return; } var memberResult = resolveResult as MemberResolveResult; var field = memberResult != null ? memberResult.Member as DefaultResolvedField : null; if (field != null && field.IsReadOnly) { if (nullable) { block.Emitter.Output.Insert(insertPosition, JS.Types.SYSTEM_NULLABLE + "." + JS.Funcs.Math.LIFT1 + "(\"" + JS.Funcs.CLONE + "\", "); block.WriteCloseParentheses(); } else { block.Write("." + JS.Funcs.CLONE + "()"); } return; } var isOperator = false; if (expression != null && (expression.Parent is BinaryOperatorExpression || expression.Parent is UnaryOperatorExpression)) { var orr = block.Emitter.Resolver.ResolveNode(expression.Parent, block.Emitter) as OperatorResolveResult; isOperator = orr != null && orr.UserDefinedOperatorMethod != null; } if (expression == null || isOperator || expression.Parent is NamedExpression || expression.Parent is ObjectCreateExpression || expression.Parent is ArrayInitializerExpression || expression.Parent is ReturnStatement || expression.Parent is InvocationExpression || expression.Parent is AssignmentExpression || expression.Parent is VariableInitializer || expression.Parent is ForeachStatement && resolveResult is ForEachResolveResult) { if (expression != null && expression.Parent is InvocationExpression) { var invocationExpression = (InvocationExpression)expression.Parent; if (invocationExpression.Target == expression) { return; } } if (nullable) { block.Emitter.Output.Insert(insertPosition, JS.Types.SYSTEM_NULLABLE + "." + JS.Funcs.Math.LIFT1 + "(\"" + JS.Funcs.CLONE + "\", "); block.WriteCloseParentheses(); } else { block.Write("." + JS.Funcs.CLONE + "()"); } } } }