Browse Source

Updated declarations parsing in both parsers to use common declaration handling code.

pull/123/head
triton 12 years ago
parent
commit
55efc0c862
  1. 38
      src/CppParser/Parser.cpp
  2. 59
      src/Parser/Parser.cpp

38
src/CppParser/Parser.cpp

@ -556,6 +556,7 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -556,6 +556,7 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
return RC;
RC = NS->FindClass(Name, isCompleteDefinition, /*Create=*/true);
HandleDeclaration(Record, RC);
if (HasEmptyName)
NS->Anonymous[(uint64_t)Record] = RC;
@ -614,7 +615,6 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -614,7 +615,6 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
{
auto MD = cast<CXXMethodDecl>(D);
auto Method = WalkMethodCXX(MD);
HandleDeclaration(MD, Method);
Method->AccessDecl = AccessDecl;
break;
}
@ -626,8 +626,6 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -626,8 +626,6 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
if (Layout)
Field->Offset = Layout->getFieldOffset(FD->getFieldIndex());
HandleDeclaration(FD, Field);
RC->Fields.push_back(Field);
break;
}
case Decl::AccessSpec:
@ -635,14 +633,11 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -635,14 +633,11 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
AccessSpecDecl* AS = cast<AccessSpecDecl>(D);
AccessDecl = new AccessSpecifierDecl();
HandleDeclaration(AS, AccessDecl);
AccessDecl->Access = ConvertToAccess(AS->getAccess());
AccessDecl->_Namespace = RC;
auto startLoc = GetDeclStartLocation(C.get(), AS);
auto range = SourceRange(startLoc, AS->getColonLoc());
HandlePreprocessedEntities(AccessDecl, range,
MacroLocation::Unknown);
HandleDeclaration(AS, AccessDecl);
RC->Specifiers.push_back(AccessDecl);
break;
}
@ -705,7 +700,10 @@ FunctionTemplate* Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) @@ -705,7 +700,10 @@ FunctionTemplate* Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD)
{
auto Function = WalkFunction(TD->getTemplatedDecl(), /*IsDependent=*/true,
/*AddToNamespace=*/false);
FunctionTemplate* FT = new FunctionTemplate;
HandleDeclaration(TD, FT);
FT->TemplatedDecl = Function;
auto TPL = TD->getTemplateParameters();
@ -789,6 +787,8 @@ Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) @@ -789,6 +787,8 @@ Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD)
DeclarationName Name = MD->getDeclName();
Method* Method = new CppSharp::CppParser::Method();
HandleDeclaration(MD, Method);
Method->Access = ConvertToAccess(MD->getAccess());
Method->Kind = GetMethodKindFromDecl(Name);
Method->IsStatic = MD->isStatic();
@ -826,17 +826,17 @@ Field* Parser::WalkFieldCXX(clang::FieldDecl* FD, Class* Class) @@ -826,17 +826,17 @@ Field* Parser::WalkFieldCXX(clang::FieldDecl* FD, Class* Class)
{
using namespace clang;
Field* F = new Field();
F->_Namespace = Class;
HandleDeclaration(FD, F);
F->_Namespace = Class;
F->Name = FD->getName();
auto TL = FD->getTypeSourceInfo()->getTypeLoc();
F->QualifiedType = GetQualifiedType(FD->getType(), WalkType(FD->getType(), &TL));
F->Access = ConvertToAccess(FD->getAccess());
F->Class = Class;
HandleComments(FD, F);
Class->Fields.push_back(F);
return F;
}
@ -1229,9 +1229,11 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1229,9 +1229,11 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
for (unsigned i = 0; i < FP->getNumArgs(); ++i)
{
auto PVD = FTL.getArg(i);
auto FA = new Parameter();
HandleDeclaration(PVD, FA);
auto PVD = FTL.getArg(i);
auto PTL = PVD->getTypeSourceInfo()->getTypeLoc();
FA->Name = PVD->getNameAsString();
@ -1469,6 +1471,8 @@ Enumeration* Parser::WalkEnum(clang::EnumDecl* ED) @@ -1469,6 +1471,8 @@ Enumeration* Parser::WalkEnum(clang::EnumDecl* ED)
BriefText = Comment->getBriefText(*AST);
auto EnumItem = Enumeration::Item();
HandleDeclaration(ECD, &EnumItem);
EnumItem.Name = ECD->getNameAsString();
auto Value = ECD->getInitVal();
EnumItem.Value = Value.isSigned() ? Value.getSExtValue()
@ -1655,6 +1659,8 @@ Function* Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDependent, @@ -1655,6 +1659,8 @@ Function* Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDependent,
return F;
F = new Function();
HandleDeclaration(FD, F);
WalkFunction(FD, F, IsDependent);
if (AddToNamespace)
@ -1795,6 +1801,8 @@ Variable* Parser::WalkVariable(clang::VarDecl *VD) @@ -1795,6 +1801,8 @@ Variable* Parser::WalkVariable(clang::VarDecl *VD)
using namespace clang;
auto Var = new Variable();
HandleDeclaration(VD, Var);
Var->Name = VD->getName();
Var->Access = ConvertToAccess(VD->getAccess());
@ -2051,7 +2059,8 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2051,7 +2059,8 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
if (Typedef) return Typedef;
Typedef = NS->FindTypedef(Name, /*Create=*/true);
HandleDeclaration(TD, Typedef);
auto TTL = TD->getTypeSourceInfo()->getTypeLoc();
Typedef->QualifiedType = GetQualifiedType(TD->getUnderlyingType(),
WalkType(TD->getUnderlyingType(), &TTL));
@ -2113,9 +2122,6 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2113,9 +2122,6 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
break;
} };
if (Decl)
HandleDeclaration(D, Decl);
return Decl;
}

59
src/Parser/Parser.cpp

@ -583,7 +583,6 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record, @@ -583,7 +583,6 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record,
{
auto MD = cast<CXXMethodDecl>(D);
auto Method = WalkMethodCXX(MD);
HandleDeclaration(MD, Method);
Method->AccessDecl = AccessDecl;
break;
}
@ -595,8 +594,6 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record, @@ -595,8 +594,6 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record,
if (Layout)
Field->Offset = Layout->getFieldOffset(FD->getFieldIndex());
HandleDeclaration(FD, Field);
RC->Fields->Add(Field);
break;
}
case Decl::AccessSpec:
@ -604,14 +601,11 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record, @@ -604,14 +601,11 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record,
AccessSpecDecl* AS = cast<AccessSpecDecl>(D);
AccessDecl = gcnew CppSharp::AST::AccessSpecifierDecl();
HandleDeclaration(AS, AccessDecl);
AccessDecl->Access = ConvertToAccess(AS->getAccess());
AccessDecl->Namespace = RC;
auto startLoc = GetDeclStartLocation(C.get(), AS);
auto range = SourceRange(startLoc, AS->getColonLoc());
HandlePreprocessedEntities(AccessDecl, range,
CppSharp::AST::MacroLocation::Unknown);
HandleDeclaration(AS, AccessDecl);
RC->Specifiers->Add(AccessDecl);
break;
}
@ -674,6 +668,7 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -674,6 +668,7 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
return RC;
RC = NS->FindClass(Name, isCompleteDefinition, /*Create=*/true);
HandleDeclaration(Record, RC);
if (HasEmptyName)
NS->Anonymous[(uint64_t)Record] = RC;
@ -718,7 +713,6 @@ Parser::WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* @@ -718,7 +713,6 @@ Parser::WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl*
auto TS = gcnew CppSharp::AST::ClassTemplateSpecialization();
HandleDeclaration(CTS, TS);
TS->OriginalPtr = System::IntPtr(CTS);
TS->Name = clix::marshalString<clix::E_UTF8>(CTS->getName());
auto NS = GetNamespace(CTS);
@ -750,7 +744,6 @@ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecia @@ -750,7 +744,6 @@ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecia
auto TS = gcnew CppSharp::AST::ClassTemplatePartialSpecialization();
HandleDeclaration(CTS, TS);
TS->OriginalPtr = System::IntPtr(CTS);
TS->Name = clix::marshalString<clix::E_UTF8>(CTS->getName());
auto NS = GetNamespace(CTS);
@ -787,8 +780,9 @@ CppSharp::AST::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl @@ -787,8 +780,9 @@ CppSharp::AST::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl
return CT;
CT = gcnew CppSharp::AST::ClassTemplate();
HandleDeclaration(TD, CT);
CT->Namespace = NS;
CT->OriginalPtr = System::IntPtr(TD);
NS->Templates->Add(CT);
CT->TemplatedDecl = WalkRecordCXX(TD->getTemplatedDecl());
@ -826,10 +820,12 @@ CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate(clang::FunctionTem @@ -826,10 +820,12 @@ CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate(clang::FunctionTem
auto Function = WalkFunction(TD->getTemplatedDecl(), /*IsDependent=*/true,
/*AddToNamespace=*/false);
FT = gcnew CppSharp::AST::FunctionTemplate(Function);
HandleDeclaration(TD, FT);
FT->Namespace = NS;
FT->OriginalPtr = System::IntPtr(TD);
NS->Templates->Add(FT);
FT->TemplatedDecl = Function;
auto TPL = TD->getTemplateParameters();
for(auto it = TPL->begin(); it != TPL->end(); ++it)
@ -842,6 +838,8 @@ CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate(clang::FunctionTem @@ -842,6 +838,8 @@ CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate(clang::FunctionTem
FT->Parameters->Add(TP);
}
NS->Templates->Add(FT);
return FT;
}
@ -911,6 +909,8 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) @@ -911,6 +909,8 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD)
DeclarationName Name = MD->getDeclName();
CppSharp::AST::Method^ Method = gcnew CppSharp::AST::Method();
HandleDeclaration(MD, Method);
Method->Access = ConvertToAccess(MD->getAccess());
Method->IsStatic = MD->isStatic();
Method->IsVirtual = MD->isVirtual();
@ -951,15 +951,16 @@ CppSharp::AST::Field^ Parser::WalkFieldCXX(clang::FieldDecl* FD, CppSharp::AST:: @@ -951,15 +951,16 @@ CppSharp::AST::Field^ Parser::WalkFieldCXX(clang::FieldDecl* FD, CppSharp::AST::
using namespace clix;
CppSharp::AST::Field^ F = gcnew CppSharp::AST::Field();
F->Namespace = Class;
HandleDeclaration(FD, F);
F->Namespace = Class;
F->Name = marshalString<E_UTF8>(FD->getName());
auto TL = FD->getTypeSourceInfo()->getTypeLoc();
F->QualifiedType = GetQualifiedType(FD->getType(), WalkType(FD->getType(), &TL));
F->Access = ConvertToAccess(FD->getAccess());
F->Class = Class;
HandleComments(FD, F);
Class->Fields->Add(F);
return F;
}
@ -1361,9 +1362,11 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1361,9 +1362,11 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
for (unsigned i = 0; i < FP->getNumArgs(); ++i)
{
auto PVD = FTL.getArg(i);
auto FA = gcnew CppSharp::AST::Parameter();
HandleDeclaration(PVD, FA);
auto PVD = FTL.getArg(i);
auto PTL = PVD->getTypeSourceInfo()->getTypeLoc();
FA->Name = marshalString<E_UTF8>(PVD->getNameAsString());
@ -1595,16 +1598,13 @@ CppSharp::AST::Enumeration^ Parser::WalkEnum(clang::EnumDecl* ED) @@ -1595,16 +1598,13 @@ CppSharp::AST::Enumeration^ Parser::WalkEnum(clang::EnumDecl* ED)
{
EnumConstantDecl* ECD = (*it);
std::string BriefText;
if (const RawComment* Comment = AST->getRawCommentForAnyRedecl(ECD))
BriefText = Comment->getBriefText(*AST);
auto EnumItem = gcnew CppSharp::AST::Enumeration::Item();
HandleDeclaration(ECD, EnumItem);
EnumItem->Name = marshalString<E_UTF8>(ECD->getNameAsString());
auto Value = ECD->getInitVal();
EnumItem->Value = Value.isSigned() ? Value.getSExtValue()
: Value.getZExtValue();
EnumItem->Comment = marshalString<E_UTF8>(BriefText);
std::string Text;
if (GetDeclText(ECD->getSourceRange(), Text))
@ -1651,13 +1651,11 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, @@ -1651,13 +1651,11 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F,
using namespace clix;
assert (FD->getBuiltinID() == 0);
auto FT = FD->getType()->getAs<FunctionType>();
auto NS = GetNamespace(FD);
assert(NS && "Expected a valid namespace");
F->OriginalPtr = System::IntPtr(FD);
F->Name = marshalString<E_UTF8>(FD->getNameAsString());
F->Namespace = NS;
F->IsVariadic = FD->isVariadic();
@ -1789,6 +1787,8 @@ CppSharp::AST::Function^ Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDe @@ -1789,6 +1787,8 @@ CppSharp::AST::Function^ Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDe
return F;
F = gcnew CppSharp::AST::Function();
HandleDeclaration(FD, F);
WalkFunction(FD, F, IsDependent);
if (AddToNamespace)
@ -1931,6 +1931,8 @@ CppSharp::AST::Variable^ Parser::WalkVariable(clang::VarDecl *VD) @@ -1931,6 +1931,8 @@ CppSharp::AST::Variable^ Parser::WalkVariable(clang::VarDecl *VD)
using namespace clix;
auto Var = gcnew CppSharp::AST::Variable();
HandleDeclaration(VD, Var);
Var->Name = marshalString<E_UTF8>(VD->getName());
Var->Access = ConvertToAccess(VD->getAccess());
@ -2031,6 +2033,11 @@ void Parser::HandleOriginalText(clang::Decl* D, CppSharp::AST::Declaration^ Decl @@ -2031,6 +2033,11 @@ void Parser::HandleOriginalText(clang::Decl* D, CppSharp::AST::Declaration^ Decl
void Parser::HandleDeclaration(clang::Decl* D, CppSharp::AST::Declaration^ Decl)
{
if (Decl->OriginalPtr.ToPointer() != nullptr)
return;
Decl->OriginalPtr = System::IntPtr(D);
if (Decl->PreprocessedEntities->Count == 0)
{
auto startLoc = GetDeclStartLocation(C.get(), D);
@ -2180,7 +2187,8 @@ CppSharp::AST::Declaration^ Parser::WalkDeclaration(clang::Decl* D, @@ -2180,7 +2187,8 @@ CppSharp::AST::Declaration^ Parser::WalkDeclaration(clang::Decl* D,
if (Typedef) return Typedef;
Typedef = NS->FindTypedef(Name, /*Create=*/true);
HandleDeclaration(TD, Typedef);
auto TTL = TD->getTypeSourceInfo()->getTypeLoc();
Typedef->QualifiedType = GetQualifiedType(TD->getUnderlyingType(),
WalkType(TD->getUnderlyingType(), &TTL));
@ -2242,9 +2250,6 @@ CppSharp::AST::Declaration^ Parser::WalkDeclaration(clang::Decl* D, @@ -2242,9 +2250,6 @@ CppSharp::AST::Declaration^ Parser::WalkDeclaration(clang::Decl* D,
break;
} };
if (Decl)
HandleDeclaration(D, Decl);
return Decl;
}

Loading…
Cancel
Save