/// <summary> /// Add the specified text to the documentation comment. /// </summary> public virtual void Add(string text) { if (text != null) { if (_content == null) { _content = text; } else if (_content is string) { _content += text; } else if (_content is ChildList <DocComment> ) { ChildList <DocComment> children = (ChildList <DocComment>)_content; if (children.Count == 0) { _content = text; } else if (children.Last is DocText) { children.Last.Add(text); } else { children.Add(new DocText(text)); } } else { throw new Exception("Can't add to a DocComment that contains code objects - add to the contained BlockDecl instead."); } } }
protected void AddInternal(FieldDecl fieldDecl) { // Override the default newlines to 0 if it hasn't been explicitly set if (!fieldDecl.IsNewLinesSet) { fieldDecl.SetNewLines(0); } _fieldDecls.Add(fieldDecl); }
/// <summary> /// Create a <see cref="ChildList{T}"/> with the specified number of null entries. /// </summary> public static ChildList <T> CreateListOfNulls(int nullEntryCount) { ChildList <T> list = new ChildList <T>(nullEntryCount); for (int i = 0; i < nullEntryCount; ++i) { list.Add((T)null); } return(list); }
protected void AddInternal(LocalDecl localDecl) { // Override the default newlines to 0 if it hasn't been explicitly set if (!localDecl.IsNewLinesSet) { localDecl.SetNewLines(0); } _localDecls.Add(localDecl); }
/// <summary> /// Deep-clone the collection. /// </summary> public static ChildList <T> Clone <T>(ChildList <T> thisChildList, CodeObject parent) where T : CodeObject { if (thisChildList != null) { ChildList <T> clone = new ChildList <T>(thisChildList.Count, parent); foreach (T child in thisChildList) { clone.Add(child != null ? (T)child.Clone() : null); } return(clone); } return(null); }
/// <summary> /// Add an <see cref="Expression"/> to the right side. /// </summary> public void AddRight(Expression expression) { if (expression != null) { // Move any newlines to the parent if (_expressions.Count == 0 && expression.IsFirstOnLine) { MoveFormatting(expression); } // Clear the current parent first, to prevent a Clone() of the object, so that any // notified error messages don't end up pointing to an orphaned original object. expression.Parent = null; _expressions.Add(expression); } }
/// <summary> /// Add an <see cref="EnumMemberDecl"/>. /// </summary> public void Add(EnumMemberDecl enumMemberDecl) { // Force enum values on separate lines by default if the parent block is on a separate line if (!enumMemberDecl.IsNewLinesSet && !enumMemberDecl.IsFirstOnLine && _parent is BlockStatement && ((BlockStatement)_parent).Body.IsFirstOnLine) { enumMemberDecl.SetNewLines(1); } // If we're adding an EnumMemberDecl on a line by itself, and the main decl isn't multi-line, then // we need to re-format after adding. bool reformatAsMultiLine = (!IsFirstOnLine && enumMemberDecl.IsFirstOnLine); _enumMemberDecls.Add(enumMemberDecl); if (reformatAsMultiLine && _parent is BlockStatement) { ((BlockStatement)_parent).ReformatBlock(); } }
protected internal GenericMethodDecl(Parser parser, CodeObject parent, bool typeParametersAlreadyParsed, ParseFlags flags) : base(parser, parent, false, flags) { if (typeParametersAlreadyParsed) { // The type parameters were already parsed on the unused Dot expression - fetch them from there UnresolvedRef unresolvedRef = (UnresolvedRef)((Dot)parser.LastUnusedCodeObject).Right; _typeParameters = new ChildList <TypeParameter>(this); foreach (Expression expression in unresolvedRef.TypeArguments) { _typeParameters.Add(new TypeParameter(expression is UnresolvedRef ? ((UnresolvedRef)expression).Name : null)); } unresolvedRef.TypeArguments = null; } ParseMethodNameAndType(parser, parent, true, false); ParseModifiersAndAnnotations(parser); // Parse any attributes and/or modifiers if (!typeParametersAlreadyParsed) { _typeParameters = TypeParameter.ParseList(parser, this); // Parse any type parameters } ParseParameters(parser); _constraintClauses = ConstraintClause.ParseList(parser, this); // Parse any constraint clauses ParseTerminatorOrBody(parser, flags); }
/// <summary> /// Create (or re-create) the compiler-generated invoke methods and constructor. /// This method should be called whenever the parameters of the delegate are set or changed. /// </summary> public void GenerateMethods() { // Remove any existing methods before generating them - since the Body is compiler-generated just // to hold these methods, we can just re-create it. Body = new Block { IsGenerated = true }; // The Invoke method has the same parameters as the delegate, and the same return type MethodDecl invokeDecl = new MethodDecl("Invoke", (Expression)_returnType.Clone(), Modifiers.Public) { IsGenerated = true }; invokeDecl.Parameters = (_parameters != null ? ChildListHelpers.Clone(_parameters, invokeDecl) : null); Add(invokeDecl); // The BeginInvoke method has the same parameters as the delegate, plus 2 extra ones, and a return type of IAsyncResult MethodDecl beginInvokeDecl = new MethodDecl("BeginInvoke", (TypeRef)TypeRef.IAsyncResultRef.Clone(), Modifiers.Public) { IsGenerated = true }; ChildList <ParameterDecl> parameters = (_parameters != null ? ChildListHelpers.Clone(_parameters, beginInvokeDecl) : new ChildList <ParameterDecl>(beginInvokeDecl)); parameters.Add(new ParameterDecl("callback", (TypeRef)TypeRef.AsyncCallbackRef.Clone())); parameters.Add(new ParameterDecl("object", (TypeRef)TypeRef.ObjectRef.Clone())); beginInvokeDecl.Parameters = parameters; Add(beginInvokeDecl); // The EndInvoke method has any 'ref' or 'out' parameters of the delegate, plus 1 extra one, and the same return type MethodDecl endInvokeDecl = new MethodDecl("EndInvoke", (Expression)_returnType.Clone(), Modifiers.Public) { IsGenerated = true }; parameters = new ChildList <ParameterDecl>(endInvokeDecl); if (_parameters != null) { foreach (ParameterDecl parameterDecl in _parameters) { if (parameterDecl.IsRef || parameterDecl.IsOut) { parameters.Add((ParameterDecl)parameterDecl.Clone()); } } } parameters.Add(new ParameterDecl("result", (TypeRef)TypeRef.IAsyncResultRef.Clone())); endInvokeDecl.Parameters = parameters; Add(endInvokeDecl); // Delegates have a constructor that takes an object and an IntPtr that is used internally by the compiler during // code generation. We have to create a dummy constructor that will allow a MethodRef to be passed to it, in order // to make the C# syntax work when resolving. TypeRef delegateTypeRef = CreateRef(); ConstructorDecl constructor = new ConstructorDecl(new[] { new ParameterDecl(DelegateConstructorParameterName, delegateTypeRef) }) { IsGenerated = true }; Add(constructor); }