Browse Source

Fixed whitespace.

pull/16/merge
triton 13 years ago
parent
commit
c3ac5ca130
  1. 410
      src/Parser/Comments.cpp

410
src/Parser/Comments.cpp

@ -15,257 +15,257 @@
static CppSharp::AST::RawCommentKind static CppSharp::AST::RawCommentKind
ConvertCommentKind(clang::RawComment::CommentKind Kind) ConvertCommentKind(clang::RawComment::CommentKind Kind)
{ {
using clang::RawComment; using clang::RawComment;
using namespace CppSharp::AST; using namespace CppSharp::AST;
switch(Kind) switch(Kind)
{ {
case RawComment::RCK_Invalid: return RawCommentKind::Invalid; case RawComment::RCK_Invalid: return RawCommentKind::Invalid;
case RawComment::RCK_OrdinaryBCPL: return RawCommentKind::OrdinaryBCPL; case RawComment::RCK_OrdinaryBCPL: return RawCommentKind::OrdinaryBCPL;
case RawComment::RCK_OrdinaryC: return RawCommentKind::OrdinaryC; case RawComment::RCK_OrdinaryC: return RawCommentKind::OrdinaryC;
case RawComment::RCK_BCPLSlash: return RawCommentKind::BCPLSlash; case RawComment::RCK_BCPLSlash: return RawCommentKind::BCPLSlash;
case RawComment::RCK_BCPLExcl: return RawCommentKind::BCPLExcl; case RawComment::RCK_BCPLExcl: return RawCommentKind::BCPLExcl;
case RawComment::RCK_JavaDoc: return RawCommentKind::JavaDoc; case RawComment::RCK_JavaDoc: return RawCommentKind::JavaDoc;
case RawComment::RCK_Qt: return RawCommentKind::Qt; case RawComment::RCK_Qt: return RawCommentKind::Qt;
case RawComment::RCK_Merged: return RawCommentKind::Merged; case RawComment::RCK_Merged: return RawCommentKind::Merged;
} }
llvm_unreachable("Unknown comment kind"); llvm_unreachable("Unknown comment kind");
} }
CppSharp::AST::RawComment^ Parser::WalkRawComment(const clang::RawComment* RC) CppSharp::AST::RawComment^ Parser::WalkRawComment(const clang::RawComment* RC)
{ {
using namespace clang; using namespace clang;
using namespace clix; using namespace clix;
auto &SM = C->getSourceManager(); auto &SM = C->getSourceManager();
auto Comment = gcnew CppSharp::AST::RawComment(); auto Comment = gcnew CppSharp::AST::RawComment();
Comment->Kind = ConvertCommentKind(RC->getKind()); Comment->Kind = ConvertCommentKind(RC->getKind());
Comment->Text = marshalString<E_UTF8>(RC->getRawText(SM)); Comment->Text = marshalString<E_UTF8>(RC->getRawText(SM));
Comment->BriefText = marshalString<E_UTF8>(RC->getBriefText(*AST)); Comment->BriefText = marshalString<E_UTF8>(RC->getBriefText(*AST));
return Comment; return Comment;
} }
static CppSharp::AST::InlineCommandComment::RenderKind static CppSharp::AST::InlineCommandComment::RenderKind
ConvertRenderKind(clang::comments::InlineCommandComment::RenderKind Kind) ConvertRenderKind(clang::comments::InlineCommandComment::RenderKind Kind)
{ {
using namespace clang::comments; using namespace clang::comments;
switch(Kind) switch(Kind)
{ {
case InlineCommandComment::RenderNormal: case InlineCommandComment::RenderNormal:
return CppSharp::AST::InlineCommandComment::RenderKind::RenderNormal; return CppSharp::AST::InlineCommandComment::RenderKind::RenderNormal;
case InlineCommandComment::RenderBold: case InlineCommandComment::RenderBold:
return CppSharp::AST::InlineCommandComment::RenderKind::RenderBold; return CppSharp::AST::InlineCommandComment::RenderKind::RenderBold;
case InlineCommandComment::RenderMonospaced: case InlineCommandComment::RenderMonospaced:
return CppSharp::AST::InlineCommandComment::RenderKind::RenderMonospaced; return CppSharp::AST::InlineCommandComment::RenderKind::RenderMonospaced;
case InlineCommandComment::RenderEmphasized: case InlineCommandComment::RenderEmphasized:
return CppSharp::AST::InlineCommandComment::RenderKind::RenderEmphasized; return CppSharp::AST::InlineCommandComment::RenderKind::RenderEmphasized;
} }
llvm_unreachable("Unknown render kind"); llvm_unreachable("Unknown render kind");
} }
static CppSharp::AST::ParamCommandComment::PassDirection static CppSharp::AST::ParamCommandComment::PassDirection
ConvertParamPassDirection(clang::comments::ParamCommandComment::PassDirection Dir) ConvertParamPassDirection(clang::comments::ParamCommandComment::PassDirection Dir)
{ {
using namespace clang::comments; using namespace clang::comments;
switch(Dir) switch(Dir)
{ {
case ParamCommandComment::In: case ParamCommandComment::In:
return CppSharp::AST::ParamCommandComment::PassDirection::In; return CppSharp::AST::ParamCommandComment::PassDirection::In;
case ParamCommandComment::Out: case ParamCommandComment::Out:
return CppSharp::AST::ParamCommandComment::PassDirection::Out; return CppSharp::AST::ParamCommandComment::PassDirection::Out;
case ParamCommandComment::InOut: case ParamCommandComment::InOut:
return CppSharp::AST::ParamCommandComment::PassDirection::InOut; return CppSharp::AST::ParamCommandComment::PassDirection::InOut;
} }
llvm_unreachable("Unknown parameter pass direction"); llvm_unreachable("Unknown parameter pass direction");
} }
static void HandleBlockCommand(const clang::comments::BlockCommandComment *CK, static void HandleBlockCommand(const clang::comments::BlockCommandComment *CK,
CppSharp::AST::BlockCommandComment^ BC) CppSharp::AST::BlockCommandComment^ BC)
{ {
using namespace clix; using namespace clix;
BC->CommandId = CK->getCommandID(); BC->CommandId = CK->getCommandID();
for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I) for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I)
{ {
auto Arg = CppSharp::AST::BlockCommandComment::Argument(); auto Arg = CppSharp::AST::BlockCommandComment::Argument();
Arg.Text = marshalString<E_UTF8>(CK->getArgText(I)); Arg.Text = marshalString<E_UTF8>(CK->getArgText(I));
BC->Arguments->Add(Arg); BC->Arguments->Add(Arg);
} }
} }
static CppSharp::AST::Comment^ ConvertCommentBlock(clang::comments::Comment* C) static CppSharp::AST::Comment^ ConvertCommentBlock(clang::comments::Comment* C)
{ {
using namespace clang; using namespace clang;
using clang::comments::Comment; using clang::comments::Comment;
using namespace clix; using namespace clix;
using namespace CppSharp::AST; using namespace CppSharp::AST;
// This needs to have an underscore else we get an ICE under VS2012. // This needs to have an underscore else we get an ICE under VS2012.
CppSharp::AST::Comment^ _Comment; CppSharp::AST::Comment^ _Comment;
switch(C->getCommentKind()) switch(C->getCommentKind())
{ {
case Comment::BlockCommandCommentKind: case Comment::BlockCommandCommentKind:
{ {
auto CK = cast<const clang::comments::BlockCommandComment>(C); auto CK = cast<const clang::comments::BlockCommandComment>(C);
auto BC = gcnew BlockCommandComment(); auto BC = gcnew BlockCommandComment();
_Comment = BC; _Comment = BC;
HandleBlockCommand(CK, BC); HandleBlockCommand(CK, BC);
break; break;
} }
case Comment::ParamCommandCommentKind: case Comment::ParamCommandCommentKind:
{ {
auto CK = cast<clang::comments::ParamCommandComment>(C); auto CK = cast<clang::comments::ParamCommandComment>(C);
auto PC = gcnew ParamCommandComment(); auto PC = gcnew ParamCommandComment();
_Comment = PC; _Comment = PC;
HandleBlockCommand(CK, PC); HandleBlockCommand(CK, PC);
PC->Direction = ConvertParamPassDirection(CK->getDirection()); PC->Direction = ConvertParamPassDirection(CK->getDirection());
PC->ParamIndex = CK->getParamIndex(); PC->ParamIndex = CK->getParamIndex();
break; break;
} }
case Comment::TParamCommandCommentKind: case Comment::TParamCommandCommentKind:
{ {
auto CK = cast<clang::comments::TParamCommandComment>(C); auto CK = cast<clang::comments::TParamCommandComment>(C);
_Comment = gcnew TParamCommandComment(); _Comment = gcnew TParamCommandComment();
auto TC = gcnew TParamCommandComment(); auto TC = gcnew TParamCommandComment();
_Comment = TC; _Comment = TC;
HandleBlockCommand(CK, TC); HandleBlockCommand(CK, TC);
if (CK->isPositionValid()) if (CK->isPositionValid())
for (unsigned I = 0, E = CK->getDepth(); I != E; ++I) for (unsigned I = 0, E = CK->getDepth(); I != E; ++I)
TC->Position->Add(CK->getIndex(I)); TC->Position->Add(CK->getIndex(I));
break; break;
} }
case Comment::VerbatimBlockCommentKind: case Comment::VerbatimBlockCommentKind:
{ {
auto CK = cast<clang::comments::VerbatimBlockComment>(C); auto CK = cast<clang::comments::VerbatimBlockComment>(C);
auto VB = gcnew VerbatimBlockComment(); auto VB = gcnew VerbatimBlockComment();
_Comment = VB; _Comment = VB;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I) for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
{ {
auto Line = ConvertCommentBlock(*I); auto Line = ConvertCommentBlock(*I);
VB->Lines->Add(dynamic_cast<VerbatimBlockLineComment^>(Line)); VB->Lines->Add(dynamic_cast<VerbatimBlockLineComment^>(Line));
} }
break; break;
} }
case Comment::VerbatimLineCommentKind: case Comment::VerbatimLineCommentKind:
{ {
auto CK = cast<clang::comments::VerbatimLineComment>(C); auto CK = cast<clang::comments::VerbatimLineComment>(C);
auto VL = gcnew VerbatimLineComment(); auto VL = gcnew VerbatimLineComment();
_Comment = VL; _Comment = VL;
VL->Text = marshalString<E_UTF8>(CK->getText()); VL->Text = marshalString<E_UTF8>(CK->getText());
break; break;
} }
case Comment::ParagraphCommentKind: case Comment::ParagraphCommentKind:
{ {
auto CK = cast<clang::comments::ParagraphComment>(C); auto CK = cast<clang::comments::ParagraphComment>(C);
auto PC = gcnew ParagraphComment(); auto PC = gcnew ParagraphComment();
_Comment = PC; _Comment = PC;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I) for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
{ {
auto Content = ConvertCommentBlock(*I); auto Content = ConvertCommentBlock(*I);
PC->Content->Add(dynamic_cast<InlineContentComment^>(Content)); PC->Content->Add(dynamic_cast<InlineContentComment^>(Content));
} }
PC->IsWhitespace = CK->isWhitespace(); PC->IsWhitespace = CK->isWhitespace();
break; break;
} }
case Comment::FullCommentKind: case Comment::FullCommentKind:
{ {
auto CK = cast<clang::comments::FullComment>(C); auto CK = cast<clang::comments::FullComment>(C);
auto FC = gcnew FullComment(); auto FC = gcnew FullComment();
_Comment = FC; _Comment = FC;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I) for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
{ {
auto Content = ConvertCommentBlock(*I); auto Content = ConvertCommentBlock(*I);
FC->Blocks->Add(dynamic_cast<BlockContentComment^>(Content)); FC->Blocks->Add(dynamic_cast<BlockContentComment^>(Content));
} }
break; break;
} }
case Comment::HTMLStartTagCommentKind: case Comment::HTMLStartTagCommentKind:
{ {
auto CK = cast<clang::comments::HTMLStartTagComment>(C); auto CK = cast<clang::comments::HTMLStartTagComment>(C);
auto TC = gcnew HTMLStartTagComment(); auto TC = gcnew HTMLStartTagComment();
_Comment = TC; _Comment = TC;
TC->TagName = marshalString<E_UTF8>(CK->getTagName()); TC->TagName = marshalString<E_UTF8>(CK->getTagName());
for (unsigned I = 0, E = CK->getNumAttrs(); I != E; ++I) for (unsigned I = 0, E = CK->getNumAttrs(); I != E; ++I)
{ {
auto A = CK->getAttr(I); auto A = CK->getAttr(I);
auto Attr = CppSharp::AST::HTMLStartTagComment::Attribute(); auto Attr = CppSharp::AST::HTMLStartTagComment::Attribute();
Attr.Name = marshalString<E_UTF8>(A.Name); Attr.Name = marshalString<E_UTF8>(A.Name);
Attr.Value = marshalString<E_UTF8>(A.Value); Attr.Value = marshalString<E_UTF8>(A.Value);
TC->Attributes->Add(Attr); TC->Attributes->Add(Attr);
} }
break; break;
} }
case Comment::HTMLEndTagCommentKind: case Comment::HTMLEndTagCommentKind:
{ {
auto CK = cast<clang::comments::HTMLEndTagComment>(C); auto CK = cast<clang::comments::HTMLEndTagComment>(C);
auto TC = gcnew HTMLEndTagComment(); auto TC = gcnew HTMLEndTagComment();
_Comment = TC; _Comment = TC;
TC->TagName = marshalString<E_UTF8>(CK->getTagName()); TC->TagName = marshalString<E_UTF8>(CK->getTagName());
break; break;
} }
case Comment::TextCommentKind: case Comment::TextCommentKind:
{ {
auto CK = cast<clang::comments::TextComment>(C); auto CK = cast<clang::comments::TextComment>(C);
auto TC = gcnew TextComment(); auto TC = gcnew TextComment();
_Comment = TC; _Comment = TC;
TC->Text = marshalString<E_UTF8>(CK->getText()); TC->Text = marshalString<E_UTF8>(CK->getText());
break; break;
} }
case Comment::InlineCommandCommentKind: case Comment::InlineCommandCommentKind:
{ {
auto CK = cast<clang::comments::InlineCommandComment>(C); auto CK = cast<clang::comments::InlineCommandComment>(C);
auto IC = gcnew InlineCommandComment(); auto IC = gcnew InlineCommandComment();
_Comment = IC; _Comment = IC;
IC->Kind = ConvertRenderKind(CK->getRenderKind()); IC->Kind = ConvertRenderKind(CK->getRenderKind());
for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I) for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I)
{ {
auto Arg = CppSharp::AST::InlineCommandComment::Argument(); auto Arg = CppSharp::AST::InlineCommandComment::Argument();
Arg.Text = marshalString<E_UTF8>(CK->getArgText(I)); Arg.Text = marshalString<E_UTF8>(CK->getArgText(I));
IC->Arguments->Add(Arg); IC->Arguments->Add(Arg);
} }
break; break;
} }
case Comment::VerbatimBlockLineCommentKind: case Comment::VerbatimBlockLineCommentKind:
{ {
auto CK = cast<clang::comments::VerbatimBlockLineComment>(C); auto CK = cast<clang::comments::VerbatimBlockLineComment>(C);
auto VL = gcnew VerbatimBlockLineComment(); auto VL = gcnew VerbatimBlockLineComment();
_Comment = VL; _Comment = VL;
VL->Text = marshalString<E_UTF8>(CK->getText()); VL->Text = marshalString<E_UTF8>(CK->getText());
break; break;
} }
case Comment::NoCommentKind: return nullptr; case Comment::NoCommentKind: return nullptr;
default: default:
llvm_unreachable("Unknown comment kind"); llvm_unreachable("Unknown comment kind");
} }
assert(_Comment && "Invalid comment instance"); assert(_Comment && "Invalid comment instance");
return _Comment; return _Comment;
} }
void Parser::HandleComments(clang::Decl* D, CppSharp::AST::Declaration^ Decl) void Parser::HandleComments(clang::Decl* D, CppSharp::AST::Declaration^ Decl)
{ {
using namespace clang; using namespace clang;
using namespace clang::comments; using namespace clang::comments;
using namespace clix; using namespace clix;
const RawComment* RC = 0; const RawComment* RC = 0;
if (!(RC = AST->getRawCommentForAnyRedecl(D))) if (!(RC = AST->getRawCommentForAnyRedecl(D)))
return; return;
auto RawComment = WalkRawComment(RC); auto RawComment = WalkRawComment(RC);
Decl->Comment = RawComment; Decl->Comment = RawComment;
if (FullComment* FC = RC->parse(*AST, &C->getPreprocessor(), D)) if (FullComment* FC = RC->parse(*AST, &C->getPreprocessor(), D))
{ {
auto CB = safe_cast<CppSharp::AST::FullComment^>(ConvertCommentBlock(FC)); auto CB = safe_cast<CppSharp::AST::FullComment^>(ConvertCommentBlock(FC));
RawComment->FullComment = CB; RawComment->FullComment = CB;
} }
// Debug Text // Debug Text
SourceManager& SM = C->getSourceManager(); SourceManager& SM = C->getSourceManager();
const LangOptions& LangOpts = C->getLangOpts(); const LangOptions& LangOpts = C->getLangOpts();

Loading…
Cancel
Save