public void typedef( Dictionary<string, IdhCommentProcessor.CommentInfo> typedefs ) //throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST typedef_AST = null; IToken name = null; AST name_AST = null; IToken name2 = null; AST name2_AST = null; IToken structname = null; AST structname_AST = null; IToken structname2 = null; AST structname2_AST = null; IToken typename = null; AST typename_AST = null; string mainComment, firstComment; Dictionary<string, IdhCommentProcessor.CommentInfo> children = new Dictionary<string, IdhCommentProcessor.CommentInfo>(); bool fCheckInline = true; try { // for error handling mainComment=comment(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } AST tmp2_AST = null; tmp2_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp2_AST); match(LITERAL_typedef); { switch ( LA(1) ) { case ATTRIBUTE: case LITERAL_enum: { { switch ( LA(1) ) { case ATTRIBUTE: { AST tmp3_AST = null; tmp3_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp3_AST); match(ATTRIBUTE); break; } case LITERAL_enum: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp4_AST = null; tmp4_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp4_AST); match(LITERAL_enum); { switch ( LA(1) ) { case IDENTIFIER: { name = LT(1); name_AST = astFactory.create(name); astFactory.addASTChild(ref currentAST, name_AST); match(IDENTIFIER); break; } case COMMENT: case LBRACE: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { // ( ... )* for (;;) { if ((LA(1)==COMMENT)) { AST tmp5_AST = null; tmp5_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp5_AST); match(COMMENT); } else { goto _loop37_breakloop; } } _loop37_breakloop: ; } // ( ... )* AST tmp6_AST = null; tmp6_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp6_AST); match(LBRACE); firstComment=comment(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } { // ( ... )+ int _cnt39=0; for (;;) { if ((LA(1)==IDENTIFIER)) { enumMemberDeclaration(children, ref firstComment); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } } else { if (_cnt39 >= 1) { goto _loop39_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; } } _cnt39++; } _loop39_breakloop: ; } // ( ... )+ AST tmp7_AST = null; tmp7_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp7_AST); match(RBRACE); { switch ( LA(1) ) { case IDENTIFIER: { name2 = LT(1); name2_AST = astFactory.create(name2); astFactory.addASTChild(ref currentAST, name2_AST); match(IDENTIFIER); break; } case SEMICOLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp8_AST = null; tmp8_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp8_AST); match(SEMICOLON); if (0==inputState.guessing) { string tmpName = string.Empty; int lineNo = 0; if (name != null) { tmpName = name.getText(); lineNo = name.getLine(); } if (name2 != null) { tmpName = name2.getText(); lineNo = name2.getLine(); } typedefs[tmpName] = new IdhCommentProcessor.CommentInfo(mainComment, children, lineNo); #if DEBUG_IDHGRAMMAR System.Diagnostics.Debug.WriteLine("***typedef enum: " + tmpName); #endif } break; } case LITERAL_struct: { AST tmp9_AST = null; tmp9_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp9_AST); match(LITERAL_struct); { switch ( LA(1) ) { case IDENTIFIER: { structname = LT(1); structname_AST = astFactory.create(structname); astFactory.addASTChild(ref currentAST, structname_AST); match(IDENTIFIER); break; } case COMMENT: case LBRACE: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { // ( ... )* for (;;) { if ((LA(1)==COMMENT)) { AST tmp10_AST = null; tmp10_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp10_AST); match(COMMENT); } else { goto _loop43_breakloop; } } _loop43_breakloop: ; } // ( ... )* AST tmp11_AST = null; tmp11_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp11_AST); match(LBRACE); firstComment=comment(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } { // ( ... )+ int _cnt45=0; for (;;) { if ((LA(1)==IDENTIFIER)) { structMemberDeclaration(children, ref firstComment); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } } else { if (_cnt45 >= 1) { goto _loop45_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; } } _cnt45++; } _loop45_breakloop: ; } // ( ... )+ AST tmp12_AST = null; tmp12_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp12_AST); match(RBRACE); { switch ( LA(1) ) { case IDENTIFIER: { structname2 = LT(1); structname2_AST = astFactory.create(structname2); astFactory.addASTChild(ref currentAST, structname2_AST); match(IDENTIFIER); break; } case SEMICOLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp13_AST = null; tmp13_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp13_AST); match(SEMICOLON); if (0==inputState.guessing) { // NOTE: the ATTRIBUTE above is really LBRACKET number RBRACKET, but it's easier to // treat it the same as the attribute, and since we don't do anything with it I guess it's ok. // Makes at least things easier in the parser/lexer. string tmpName = string.Empty; int lineNo = 0; if (structname != null) { tmpName = structname.getText(); lineNo = structname.getLine(); } if (structname2 != null) { tmpName = structname2.getText(); lineNo = structname2.getLine(); } typedefs[tmpName] = new IdhCommentProcessor.CommentInfo(mainComment, children, lineNo); #if DEBUG_IDHGRAMMAR System.Diagnostics.Debug.WriteLine("***typedef struct: " + tmpName); #endif } break; } case IDENTIFIER: { AST tmp14_AST = null; tmp14_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp14_AST); match(IDENTIFIER); typename = LT(1); typename_AST = astFactory.create(typename); astFactory.addASTChild(ref currentAST, typename_AST); match(IDENTIFIER); AST tmp15_AST = null; tmp15_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp15_AST); match(SEMICOLON); if (0==inputState.guessing) { // TODO: deal with line comment for typename typedefs[typename_AST.getText()] = new IdhCommentProcessor.CommentInfo(string.Empty, null, typename.getLine()); } break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } typedef_AST = currentAST.root; } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_1_); } else { throw ex; } } returnAST = typedef_AST; }
public string parameterDeclaration( Dictionary<string, IdhCommentProcessor.CommentInfo> parameters ) //throws RecognitionException, TokenStreamException { string paramName; returnAST = null; ASTPair currentAST = new ASTPair(); AST parameterDeclaration_AST = null; IToken attribute = null; AST attribute_AST = null; IToken name = null; AST name_AST = null; IToken comment = null; AST comment_AST = null; StringBuilder bldr = new StringBuilder(); paramName = null; try { // for error handling { switch ( LA(1) ) { case ATTRIBUTE: { attribute = LT(1); attribute_AST = astFactory.create(attribute); astFactory.addASTChild(ref currentAST, attribute_AST); match(ATTRIBUTE); break; } case IDENTIFIER: case LITERAL_const: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1) ) { case LITERAL_const: { AST tmp88_AST = null; tmp88_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp88_AST); match(LITERAL_const); break; } case IDENTIFIER: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp89_AST = null; tmp89_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp89_AST); match(IDENTIFIER); { // ( ... )* for (;;) { if ((LA(1)==STAR)) { AST tmp90_AST = null; tmp90_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp90_AST); match(STAR); } else { goto _loop74_breakloop; } } _loop74_breakloop: ; } // ( ... )* name = LT(1); name_AST = astFactory.create(name); astFactory.addASTChild(ref currentAST, name_AST); match(IDENTIFIER); { // ( ... )* for (;;) { if ((LA(1)==LBRACKET)) { AST tmp91_AST = null; tmp91_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp91_AST); match(LBRACKET); { switch ( LA(1) ) { case IDENTIFIER: case MINUS: { enumVal(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } break; } case RBRACKET: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp92_AST = null; tmp92_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp92_AST); match(RBRACKET); } else { goto _loop77_breakloop; } } _loop77_breakloop: ; } // ( ... )* { if ((LA(1)==COMMENT) && (LA(2)==COMMA)) { AST tmp93_AST = null; tmp93_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp93_AST); match(COMMENT); AST tmp94_AST = null; tmp94_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp94_AST); match(COMMA); } else if ((LA(1)==COMMA)) { AST tmp95_AST = null; tmp95_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp95_AST); match(COMMA); } else if ((tokenSet_12_.member(LA(1))) && (tokenSet_13_.member(LA(2)))) { } else { throw new NoViableAltException(LT(1), getFilename()); } } { // ( ... )* for (;;) { if ((LA(1)==COMMENT)) { comment = LT(1); comment_AST = astFactory.create(comment); astFactory.addASTChild(ref currentAST, comment_AST); match(COMMENT); if (0==inputState.guessing) { bldr.Append(comment.getText()); } } else { goto _loop80_breakloop; } } _loop80_breakloop: ; } // ( ... )* if (0==inputState.guessing) { paramName = IDLConversions.ConvertParamName(name.getText()); parameters[paramName] = new IdhCommentProcessor.CommentInfo(bldr.ToString(), null, name.getLine()); if (attribute != null && attribute.getText().Contains("retval")) parameters[paramName].Attributes.Add("retval", paramName); } parameterDeclaration_AST = currentAST.root; } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_14_); } else { throw ex; } } returnAST = parameterDeclaration_AST; return paramName; }
public void structMemberDeclaration( Dictionary<string, IdhCommentProcessor.CommentInfo> members, ref string addComment ) //throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST structMemberDeclaration_AST = null; IToken name = null; AST name_AST = null; IToken lineComment = null; AST lineComment_AST = null; StringBuilder bldr = new StringBuilder(addComment); addComment = string.Empty; IdhCommentProcessor.CommentInfo info = new IdhCommentProcessor.CommentInfo(string.Empty, null, 0); bool fCheckInline = true; try { // for error handling AST tmp76_AST = null; tmp76_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp76_AST); match(IDENTIFIER); name = LT(1); name_AST = astFactory.create(name); astFactory.addASTChild(ref currentAST, name_AST); match(IDENTIFIER); { switch ( LA(1) ) { case ATTRIBUTE: { AST tmp77_AST = null; tmp77_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp77_AST); match(ATTRIBUTE); break; } case SEMICOLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp78_AST = null; tmp78_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp78_AST); match(SEMICOLON); { // ( ... )* for (;;) { if ((LA(1)==COMMENT)) { lineComment = LT(1); lineComment_AST = astFactory.create(lineComment); astFactory.addASTChild(ref currentAST, lineComment_AST); match(COMMENT); if (0==inputState.guessing) { if (fCheckInline && name.getLine() == lineComment.getLine()) { // inline comment belongs to current member bldr.Append(lineComment_AST.getText()); } else { // comment belongs to following member if (fCheckInline) { // append all comments we got so far and create a new CommentInfo members[name_AST.getText()] = new IdhCommentProcessor.CommentInfo(bldr.ToString(), null, 0); bldr = new StringBuilder(); fCheckInline = false; } bldr.Append(lineComment_AST.getText()); } } } else { goto _loop61_breakloop; } } _loop61_breakloop: ; } // ( ... )* if (0==inputState.guessing) { if (fCheckInline) { // append all comments left if there was none members[name_AST.getText()] = new IdhCommentProcessor.CommentInfo(bldr.ToString(), null, name.getLine()); } else addComment = bldr.ToString(); } structMemberDeclaration_AST = currentAST.root; } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_8_); } else { throw ex; } } returnAST = structMemberDeclaration_AST; }
public void methodDeclaration( Dictionary<string, IdhCommentProcessor.CommentInfo> methods ) //throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST methodDeclaration_AST = null; IToken comment = null; AST comment_AST = null; IToken name = null; AST name_AST = null; IToken paramComment = null; AST paramComment_AST = null; StringBuilder bldr = new StringBuilder(); Dictionary<string, IdhCommentProcessor.CommentInfo> parameters = new Dictionary<string, IdhCommentProcessor.CommentInfo>(); string lastParamName = null; int lastParamLine = 0; try { // for error handling { // ( ... )* for (;;) { if ((LA(1)==COMMENT)) { comment = LT(1); comment_AST = astFactory.create(comment); astFactory.addASTChild(ref currentAST, comment_AST); match(COMMENT); if (0==inputState.guessing) { bldr.Append(comment.getText()); } } else { goto _loop64_breakloop; } } _loop64_breakloop: ; } // ( ... )* { switch ( LA(1) ) { case ATTRIBUTE: { AST tmp67_AST = null; tmp67_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp67_AST); match(ATTRIBUTE); break; } case IDENTIFIER: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } AST tmp68_AST = null; tmp68_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp68_AST); match(IDENTIFIER); name = LT(1); name_AST = astFactory.create(name); astFactory.addASTChild(ref currentAST, name_AST); match(IDENTIFIER); AST tmp69_AST = null; tmp69_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp69_AST); match(LPAREN); { switch ( LA(1) ) { case COMMENT: { AST tmp70_AST = null; tmp70_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp70_AST); match(COMMENT); break; } case IDENTIFIER: case RPAREN: case ATTRIBUTE: case LITERAL_const: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { // ( ... )* for (;;) { if ((LA(1)==IDENTIFIER||LA(1)==ATTRIBUTE||LA(1)==LITERAL_const)) { lastParamName=parameterDeclaration(parameters); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } if (0==inputState.guessing) { lastParamLine = LT(1).getLine(); } } else { goto _loop68_breakloop; } } _loop68_breakloop: ; } // ( ... )* AST tmp71_AST = null; tmp71_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp71_AST); match(RPAREN); AST tmp72_AST = null; tmp72_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp72_AST); match(SEMICOLON); { if (((LA(1)==COMMENT) && (tokenSet_4_.member(LA(2))))&&(LT(1).getLine() == lastParamLine)) { paramComment = LT(1); paramComment_AST = astFactory.create(paramComment); astFactory.addASTChild(ref currentAST, paramComment_AST); match(COMMENT); } else if ((tokenSet_4_.member(LA(1))) && (tokenSet_6_.member(LA(2)))) { } else { throw new NoViableAltException(LT(1), getFilename()); } } if (0==inputState.guessing) { // This is tricky. We might get a comment after the semicolon - which really belongs to // the last parameter before the end of the method declaration. So we remember the // name of the last method so that we can assign the comment correctly. if (paramComment != null && lastParamName != null) { IdhCommentProcessor.CommentInfo lastParam = parameters[lastParamName]; lastParam.Comment = paramComment.getText(); } string key = name.getText(); IdhCommentProcessor.CommentInfo info; if (methods.ContainsKey(key)) info = methods[key]; else info = new IdhCommentProcessor.CommentInfo(); info.Comment = bldr.ToString(); info.Children = parameters; info.LineNumber = name.getLine(); methods[key] = info; foreach (IdhCommentProcessor.CommentInfo paramInfo in parameters.Values) { if (paramInfo.Attributes.ContainsKey("retval")) { info.Attributes.Add("retval", paramInfo.Attributes["retval"]); break; } } //#if DEBUG_IDHGRAMMAR //System.Diagnostics.Debug.WriteLine(" method declaration: " + key + ", next: " + LT(1).getText()); //#endif } methodDeclaration_AST = currentAST.root; } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_4_); } else { throw ex; } } returnAST = methodDeclaration_AST; }
public IdhCommentProcessor.CommentInfo idhfile() //throws RecognitionException, TokenStreamException { IdhCommentProcessor.CommentInfo info; returnAST = null; ASTPair currentAST = new ASTPair(); AST idhfile_AST = null; IToken comment = null; AST comment_AST = null; IToken id = null; AST id_AST = null; Dictionary<string, IdhCommentProcessor.CommentInfo> toplevel = new Dictionary<string, IdhCommentProcessor.CommentInfo>(); info = new IdhCommentProcessor.CommentInfo(string.Empty, toplevel, 0); try { // for error handling { // ( ... )+ int _cnt7=0; for (;;) { switch ( LA(1) ) { case LITERAL_interface: { forwardDeclaration(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } break; } case LITERAL_DeclareCoClass: { coclassDeclaration(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } break; } case LITERAL_import: { import(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } if (0==inputState.guessing) { #if DEBUG_IDHGRAMMAR System.Diagnostics.Debug.WriteLine("***import"); #endif } break; } case IDENTIFIER: { id = LT(1); id_AST = astFactory.create(id); astFactory.addASTChild(ref currentAST, id_AST); match(IDENTIFIER); if (0==inputState.guessing) { #if DEBUG_IDHGRAMMAR System.Diagnostics.Debug.WriteLine("***IDENTIFIER: " + id_AST.getText()); #endif } break; } case LITERAL_const: { constDeclaration(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } if (0==inputState.guessing) { #if DEBUG_IDHGRAMMAR System.Diagnostics.Debug.WriteLine("***const"); #endif } break; } default: bool synPredMatched6 = false; if ((((LA(1) >= COMMENT && LA(1) <= PREPROCESSOR)) && (tokenSet_0_.member(LA(2))))) { int _m6 = mark(); synPredMatched6 = true; inputState.guessing++; try { { { // ( ... )* for (;;) { if ((LA(1)==COMMENT)) { match(COMMENT); } else { goto _loop5_breakloop; } } _loop5_breakloop: ; } // ( ... )* match(LITERAL_typedef); } } catch (RecognitionException) { synPredMatched6 = false; } rewind(_m6); inputState.guessing--; } if ( synPredMatched6 ) { typedef(toplevel); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } } else if ((LA(1)==COMMENT) && (tokenSet_1_.member(LA(2)))) { comment = LT(1); comment_AST = astFactory.create(comment); astFactory.addASTChild(ref currentAST, comment_AST); match(COMMENT); if (0==inputState.guessing) { info.Comment = comment.getText(); info.LineNumber = comment.getLine(); } } else if ((LA(1)==COMMENT) && (LA(2)==LITERAL_DeclareInterface)) { interfaceDeclaration(toplevel); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } } else if ((LA(1)==COMMENT) && (LA(2)==LITERAL_DeclareDualInterface||LA(2)==18)) { dualInterface(toplevel); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } } else if ((LA(1)==PREPROCESSOR) && (tokenSet_1_.member(LA(2)))) { AST tmp1_AST = null; tmp1_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp1_AST); match(PREPROCESSOR); } else { if (_cnt7 >= 1) { goto _loop7_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; } } break; } _cnt7++; } _loop7_breakloop: ; } // ( ... )+ idhfile_AST = currentAST.root; } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_2_); } else { throw ex; } } returnAST = idhfile_AST; return info; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add comments to each class and method /// </summary> /// <param name="types">Collection of types</param> /// ------------------------------------------------------------------------------------ private void AddComments(CodeTypeDeclarationCollection types) { foreach (CodeTypeDeclaration type in types) { // we probably inherited the comments (from a base class in an external file), // so we don't want to add the same comments again! if (type.Comments.Count > 0) { continue; } string comment = type.Name; IdhCommentProcessor.CommentInfo ifaceComment = null; if (!s_idhProcessor.Comments.TryGetValue(type.Name, out ifaceComment) && type.Name != string.Empty) { s_idhProcessor.Comments.TryGetValue(type.Name.Substring(1), out ifaceComment); } // Also get comments for base class - if we derive from a class // we might need to get some comments from there if we don't have our own. List <IdhCommentProcessor.CommentInfo> baseComments = new List <IdhCommentProcessor.CommentInfo>(); if (type.BaseTypes.Count > 0) { for (int i = 0; i < type.BaseTypes.Count; i++) { IdhCommentProcessor.CommentInfo baseComment = null; if (!s_idhProcessor.Comments.TryGetValue(type.BaseTypes[i].BaseType, out baseComment)) { s_idhProcessor.Comments.TryGetValue(type.BaseTypes[i].BaseType.Substring(1), out baseComment); } if (baseComment != null) { baseComments.Add(baseComment); } } } if (ifaceComment != null) { comment = ifaceComment.Comment; } type.Comments.Add(new CodeCommentStatement( string.Format(comment.Length > 80 ? "<summary>{1}{0}{1}</summary>" : "<summary>{0} </summary>", comment, Environment.NewLine), true)); foreach (CodeTypeMember member in type.Members) { if ((!type.IsInterface && !type.IsEnum && (member.Attributes & MemberAttributes.Private) == MemberAttributes.Private) || member.Comments.Count > 0 || member.Name == string.Empty) { continue; } IdhCommentProcessor.CommentInfo methodComment = null; if (ifaceComment != null) { ifaceComment.Children.TryGetValue(member.Name, out methodComment); } for (int i = 0; i < baseComments.Count && methodComment == null; i++) { baseComments[i].Children.TryGetValue(member.Name, out methodComment); } if (member is CodeMemberMethod) { if (methodComment == null) { // Maybe it's a property with a parameter? Try and see if the IDH // file has a comment for a method without the "get_" or "set_" if (member.Name.StartsWith("get_") || member.Name.StartsWith("set_")) { string name = member.Name.Substring(4); if (ifaceComment != null) { ifaceComment.Children.TryGetValue(name, out methodComment); } for (int i = 0; i < baseComments.Count && methodComment == null; i++) { baseComments[i].Children.TryGetValue(name, out methodComment); } } } comment = "Member " + member.Name; if (methodComment != null) { comment = methodComment.Comment; } member.Comments.Add(new CodeCommentStatement( string.Format(comment.Length > 80 ? "<summary>{1}{0}{1}</summary>" : "<summary>{0} </summary>", comment, Environment.NewLine), true)); CodeMemberMethod method = member as CodeMemberMethod; foreach (CodeParameterDeclarationExpression param in method.Parameters) { IdhCommentProcessor.CommentInfo paramComment = null; if (methodComment != null) { methodComment.Children.TryGetValue(param.Name, out paramComment); } comment = string.Empty; if (paramComment != null) { comment = paramComment.Comment; } member.Comments.Add(new CodeCommentStatement( string.Format("<param name='{0}'>{1} </param>", param.Name, comment), true)); } if (method.ReturnType.BaseType != "System.Void") { comment = "A " + method.ReturnType.BaseType; if (methodComment != null && methodComment.Attributes.ContainsKey("retval")) { string retparamName = methodComment.Attributes["retval"]; if (methodComment.Children.ContainsKey(retparamName)) { comment = methodComment.Children[retparamName].Comment; } } member.Comments.Add(new CodeCommentStatement( string.Format("<returns>{0}</returns>", comment), true)); } } else if (member is CodeMemberProperty) { CodeMemberProperty property = member as CodeMemberProperty; string getset = string.Empty; if (methodComment == null) { // No comment from IDH file - generate a pseudo one if (property.HasGet) { getset += "Gets"; } if (property.HasSet) { if (getset.Length > 0) { getset += "/"; } getset += "Sets"; } getset = string.Format("{0} a {1}", getset, member.Name); } else { // Use comment provided in IDH file getset = methodComment.Comment; } member.Comments.Add(new CodeCommentStatement( string.Format(getset.Length > 80 ? "<summary>{1}{0}{1}</summary>" : "<summary>{0} </summary>", getset, Environment.NewLine), true)); member.Comments.Add(new CodeCommentStatement( string.Format("<returns>A {0} </returns>", property.Type.BaseType), true)); } else if (member is CodeMemberField) { if (methodComment == null) { // No comment from IDH file - generate a pseudo one comment = string.Empty; } else { // Use comment provided in IDH file comment = methodComment.Comment; } member.Comments.Add(new CodeCommentStatement( string.Format(comment.Length > 80 ? "<summary>{1}{0}{1}</summary>" : "<summary>{0} </summary>", comment, Environment.NewLine), true)); } else { comment = "Member " + member.Name; if (methodComment != null) { comment = methodComment.Comment; } member.Comments.Add(new CodeCommentStatement( string.Format(comment.Length > 80 ? "<summary>{1}{0}{1}</summary>" : "<summary>{0} </summary>", comment, Environment.NewLine), true)); member.Comments.Add(new CodeCommentStatement( string.Format("Not expecting a member of type {0}", member.GetType()))); } if (methodComment != null && methodComment.Attributes.ContainsKey("exception")) { string[] exceptions = methodComment.Attributes["exception"].Split(','); foreach (string exception in exceptions) { comment = methodComment.Attributes[exception]; member.Comments.Add(new CodeCommentStatement( string.Format(@"<exception cref=""{0}"">{1}</exception>", exception, comment), true)); } } } } }