Index: src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs =================================================================== --- src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs (revision 1924) +++ src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs (working copy) @@ -677,21 +677,25 @@ override public void OnCallableBlockExpression(CallableBlockExpression node) { + SetCallableDocumentation(node); + TypeMemberModifiers modifiers = TypeMemberModifiers.Internal; if (_currentMethod.IsStatic) { modifiers |= TypeMemberModifiers.Static; } - + Method closure = CodeBuilder.CreateMethod( - "___closure" + _context.AllocIndex(), - Unknown.Default, - modifiers); + TypeSystemServices.CreateCallableName(node, + "_Closure" + _context.AllocIndex().ToString()), + Unknown.Default, + modifiers); InternalMethod closureEntity = (InternalMethod)closure.Entity; closure.LexicalInfo = node.LexicalInfo; closure.Parameters = node.Parameters; closure.Body = node.Body; + closure.Documentation = node.Documentation; _currentMethod.Method.DeclaringType.Members.Add(closure); @@ -709,7 +713,22 @@ node.ExpressionType = closureEntity.Type; node.Entity = closureEntity; } - + + static public void SetCallableDocumentation(CallableBlockExpression node) + { + if (node.Body != null && node.Body.Statements.Count > 0 + && node.Body.Statements[0].NodeType == NodeType.ExpressionStatement) + { + ExpressionStatement stmt = (ExpressionStatement)node.Body.Statements[0]; + StringLiteralExpression s = stmt.Expression as StringLiteralExpression; + if (s != null && s.Value != null && s.Value.StartsWith("Name:")) + { + node.Documentation = s.Value; + node.Body.Statements.RemoveAt(0); + } + } + } + override public void OnMethod(Method method) { if (WasVisited(method)) Index: src/Boo.Lang.Compiler/TypeSystem/TypeSystemServices.cs =================================================================== --- src/Boo.Lang.Compiler/TypeSystem/TypeSystemServices.cs (revision 1924) +++ src/Boo.Lang.Compiler/TypeSystem/TypeSystemServices.cs (working copy) @@ -35,6 +35,7 @@ using Boo.Lang.Compiler.Ast; using Attribute = Boo.Lang.Compiler.Ast.Attribute; using Module = Boo.Lang.Compiler.Ast.Module; + using System.Text.RegularExpressions; public class TypeSystemServices { @@ -140,6 +141,8 @@ CompilerContext _context; + static Regex _cleanNamePattern = new Regex(@"[^_a-zA-Z0-9]+", RegexOptions.Compiled); + public TypeSystemServices() : this(new CompilerContext()) { } @@ -1264,11 +1267,33 @@ return anonymousType.ConcreteType; } + static public string CreateCallableName(Node n, string suffix) + { + string s = n.Documentation; + if (s != null && s.StartsWith("Name:")) + { + s = s.Split('\n')[0].Substring(5).Trim(); + s = _cleanNamePattern.Replace(s,""); + s += suffix; + } + else + { + s = "__" + suffix; + if (n.LexicalInfo != null) + { + s += "_" + n.LexicalInfo.Line.ToString(); + s += "_" + n.LexicalInfo.Column.ToString(); + } + } + return s; + } + protected virtual IType CreateConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType) { Module module = GetAnonymousTypesModule(); - string name = string.Format("___callable{0}", module.Members.Count); + string name = CreateCallableName(sourceNode, "_Callable" + module.Members.Count.ToString()); + ClassDefinition cd = CreateCallableDefinition(name); cd.Modifiers |= TypeMemberModifiers.Public; cd.LexicalInfo = sourceNode.LexicalInfo;