Skip to content

Commit

Permalink
Revert "Removed the macros in C++ AST for std::string because we can …
Browse files Browse the repository at this point in the history
…marshal it (mono#866)"
  • Loading branch information
tritao committed Oct 29, 2024
1 parent 38621c3 commit b684fe0
Show file tree
Hide file tree
Showing 34 changed files with 5,255 additions and 44,990 deletions.
102 changes: 75 additions & 27 deletions src/CppParser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ DependentNameType::DependentNameType() : Type(TypeKind::DependentName) {}

DependentNameType::~DependentNameType() {}

DEF_STRING(DependentNameType, Identifier)

PackExpansionType::PackExpansionType() : Type(TypeKind::PackExpansion) {}

UnaryTransformType::UnaryTransformType() : Type(TypeKind::UnaryTransform) {}
Expand Down Expand Up @@ -242,14 +244,16 @@ LayoutField::LayoutField() : offset(0), fieldPtr(0) {}

LayoutField::LayoutField(const LayoutField & other)
: offset(other.offset)
, name(other.name)
, Name(other.Name)
, qualifiedType(other.qualifiedType)
, fieldPtr(other.fieldPtr)
{
}

LayoutField::~LayoutField() {}

DEF_STRING(LayoutField, Name)

LayoutBase::LayoutBase() : offset(0), _class(0) {}

LayoutBase::LayoutBase(const LayoutBase& other) : offset(other.offset), _class(other._class) {}
Expand Down Expand Up @@ -293,9 +297,9 @@ Declaration::Declaration(const Declaration& rhs)
, location(rhs.location.ID)
, lineNumberStart(rhs.lineNumberStart)
, lineNumberEnd(rhs.lineNumberEnd)
, name(rhs.name)
, Name(rhs.Name)
, comment(rhs.comment)
, debugText(rhs.debugText)
, DebugText(rhs.DebugText)
, isIncomplete(rhs.isIncomplete)
, isDependent(rhs.isDependent)
, isImplicit(rhs.isImplicit)
Expand All @@ -312,6 +316,9 @@ Declaration::~Declaration()
{
}

DEF_STRING(Declaration, Name)
DEF_STRING(Declaration, USR)
DEF_STRING(Declaration, DebugText)
DEF_VECTOR(Declaration, PreprocessedEntity*, PreprocessedEntities)
DEF_VECTOR(Declaration, Declaration*, Redeclarations)

Expand Down Expand Up @@ -353,7 +360,7 @@ DeclarationContext::FindNamespace(const std::vector<std::string>& Namespaces)
auto childNamespace = std::find_if(currentNamespace->Namespaces.begin(),
currentNamespace->Namespaces.end(),
[&](CppSharp::CppParser::AST::Namespace* ns) {
return ns->name == _namespace;
return ns->Name == _namespace;
});

if (childNamespace == currentNamespace->Namespaces.end())
Expand All @@ -372,7 +379,7 @@ Namespace* DeclarationContext::FindCreateNamespace(const std::string& Name)
if (!_namespace)
{
_namespace = new Namespace();
_namespace->name = Name;
_namespace->Name = Name;
_namespace->_namespace = this;

Namespaces.push_back(_namespace);
Expand All @@ -393,7 +400,7 @@ Class* DeclarationContext::FindClass(const void* OriginalPtr,
auto _class = std::find_if(Classes.begin(), Classes.end(),
[OriginalPtr, Name, IsComplete](Class* klass) {
return (OriginalPtr && klass->originalPtr == OriginalPtr) ||
(klass->name == Name && klass->isIncomplete == !IsComplete); });
(klass->Name == Name && klass->isIncomplete == !IsComplete); });

return _class != Classes.end() ? *_class : nullptr;
}
Expand All @@ -413,7 +420,7 @@ Class* DeclarationContext::FindClass(const void* OriginalPtr,
Class* DeclarationContext::CreateClass(const std::string& Name, bool IsComplete)
{
auto _class = new Class();
_class->name = Name;
_class->Name = Name;
_class->_namespace = this;
_class->isIncomplete = !IsComplete;

Expand Down Expand Up @@ -457,7 +464,7 @@ Enumeration* DeclarationContext::FindEnum(const std::string& Name, bool Create)
if (entries.size() == 1)
{
auto foundEnum = std::find_if(Enums.begin(), Enums.end(),
[&](Enumeration* _enum) { return _enum->name == Name; });
[&](Enumeration* _enum) { return _enum->Name == Name; });

if (foundEnum != Enums.end())
return *foundEnum;
Expand All @@ -466,7 +473,7 @@ Enumeration* DeclarationContext::FindEnum(const std::string& Name, bool Create)
return nullptr;

auto _enum = new Enumeration();
_enum->name = Name;
_enum->Name = Name;
_enum->_namespace = this;
Enums.push_back(_enum);
return _enum;
Expand Down Expand Up @@ -525,7 +532,7 @@ Function* DeclarationContext::FindFunction(const std::string& USR)
TypedefDecl* DeclarationContext::FindTypedef(const std::string& Name, bool Create)
{
auto foundTypedef = std::find_if(Typedefs.begin(), Typedefs.end(),
[&](TypedefDecl* tdef) { return tdef->name == Name; });
[&](TypedefDecl* tdef) { return tdef->Name == Name; });

if (foundTypedef != Typedefs.end())
return *foundTypedef;
Expand All @@ -534,7 +541,7 @@ TypedefDecl* DeclarationContext::FindTypedef(const std::string& Name, bool Creat
return nullptr;

auto tdef = new TypedefDecl();
tdef->name = Name;
tdef->Name = Name;
tdef->_namespace = this;

return tdef;
Expand All @@ -543,7 +550,7 @@ TypedefDecl* DeclarationContext::FindTypedef(const std::string& Name, bool Creat
TypeAlias* DeclarationContext::FindTypeAlias(const std::string& Name, bool Create)
{
auto foundTypeAlias = std::find_if(TypeAliases.begin(), TypeAliases.end(),
[&](TypeAlias* talias) { return talias->name == Name; });
[&](TypeAlias* talias) { return talias->Name == Name; });

if (foundTypeAlias != TypeAliases.end())
return *foundTypeAlias;
Expand All @@ -552,7 +559,7 @@ TypeAlias* DeclarationContext::FindTypeAlias(const std::string& Name, bool Creat
return nullptr;

auto talias = new TypeAlias();
talias->name = Name;
talias->Name = Name;
talias->_namespace = this;

return talias;
Expand Down Expand Up @@ -596,22 +603,25 @@ Friend::Friend() : CppSharp::CppParser::AST::Declaration(DeclarationKind::Friend

Friend::~Friend() {}

StatementObsolete::StatementObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl) : string(str), _class(stmtClass), decl(decl) {}
DEF_STRING(StatementObsolete, String)

StatementObsolete::StatementObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl) : String(str), _class(stmtClass), decl(decl) {}

ExpressionObsolete::ExpressionObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl)
: StatementObsolete(str, stmtClass, decl) {}

DEF_STRING(BinaryOperatorObsolete, OpcodeStr)

BinaryOperatorObsolete::BinaryOperatorObsolete(const std::string& str, ExpressionObsolete* lhs, ExpressionObsolete* rhs, const std::string& opcodeStr)
: ExpressionObsolete(str, StatementClassObsolete::BinaryOperator), LHS(lhs), RHS(rhs), opcodeStr(opcodeStr) {}
: ExpressionObsolete(str, StatementClassObsolete::BinaryOperator), LHS(lhs), RHS(rhs), OpcodeStr(opcodeStr) {}

BinaryOperatorObsolete::~BinaryOperatorObsolete()
{
deleteExpression(LHS);
deleteExpression(RHS);
}


CallExprObsolete::CallExprObsolete(const std::string& str, Declaration* decl)
CallExprObsolete::CallExprObsolete(const char* str, Declaration* decl)
: ExpressionObsolete(str, StatementClassObsolete::CallExprClass, decl) {}

CallExprObsolete::~CallExprObsolete()
Expand All @@ -622,7 +632,7 @@ CallExprObsolete::~CallExprObsolete()

DEF_VECTOR(CallExprObsolete, ExpressionObsolete*, Arguments)

CXXConstructExprObsolete::CXXConstructExprObsolete(const std::string& str, Declaration* decl)
CXXConstructExprObsolete::CXXConstructExprObsolete(const char* str, Declaration* decl)
: ExpressionObsolete(str, StatementClassObsolete::CXXConstructExprClass, decl) {}

CXXConstructExprObsolete::~CXXConstructExprObsolete()
Expand Down Expand Up @@ -666,6 +676,10 @@ Function::Function()
}

Function::~Function() {}

DEF_STRING(Function, Mangled)
DEF_STRING(Function, Signature)
DEF_STRING(Function, Body)
DEF_VECTOR(Function, Parameter*, Parameters)

Method::Method()
Expand Down Expand Up @@ -699,14 +713,16 @@ DEF_VECTOR(Enumeration, Enumeration::Item*, Items)
Enumeration::Item::Item() : Declaration(DeclarationKind::EnumerationItem) {}

Enumeration::Item::Item(const Item& rhs) : Declaration(rhs),
expression(rhs.expression), value(rhs.value) {}
Expression(rhs.Expression), value(rhs.value) {}

Enumeration::Item::~Item() {}

DEF_STRING(Enumeration::Item, Expression)

Enumeration::Item* Enumeration::FindItemByName(const std::string& Name)
{
auto foundEnumItem = std::find_if(Items.begin(), Items.end(),
[&](Item* _item) { return _item->name == Name; });
[&](Item* _item) { return _item->Name == Name; });
if (foundEnumItem != Items.end())
return *foundEnumItem;
return nullptr;
Expand All @@ -717,6 +733,8 @@ Variable::Variable() : Declaration(DeclarationKind::Variable),

Variable::~Variable() {}

DEF_STRING(Variable, Mangled)

BaseClassSpecifier::BaseClassSpecifier() : type(0), offset(0) {}

Field::Field() : Declaration(DeclarationKind::Field), _class(0),
Expand Down Expand Up @@ -891,13 +909,21 @@ MacroDefinition::MacroDefinition()

MacroDefinition::~MacroDefinition() {}

DEF_STRING(MacroDefinition, Name)
DEF_STRING(MacroDefinition, Expression)

MacroExpansion::MacroExpansion() : definition(0) { kind = DeclarationKind::MacroExpansion; }

MacroExpansion::~MacroExpansion() {}

DEF_STRING(MacroExpansion, Name)
DEF_STRING(MacroExpansion, Text)

TranslationUnit::TranslationUnit() { kind = DeclarationKind::TranslationUnit; }

TranslationUnit::~TranslationUnit() {}

DEF_STRING(TranslationUnit, FileName)
DEF_VECTOR(TranslationUnit, MacroDefinition*, Macros)

NativeLibrary::NativeLibrary()
Expand All @@ -906,6 +932,7 @@ NativeLibrary::NativeLibrary()
NativeLibrary::~NativeLibrary() {}

// NativeLibrary
DEF_STRING(NativeLibrary, FileName)
DEF_VECTOR_STRING(NativeLibrary, Symbols)
DEF_VECTOR_STRING(NativeLibrary, Dependencies)

Expand Down Expand Up @@ -941,14 +968,14 @@ TranslationUnit* ASTContext::FindOrCreateModule(std::string File)

auto existingUnit = std::find_if(TranslationUnits.begin(),
TranslationUnits.end(), [&](TranslationUnit* unit) {
return unit && unit->fileName == normalizedFile;
return unit && unit->FileName == normalizedFile;
});

if (existingUnit != TranslationUnits.end())
return *existingUnit;

auto unit = new TranslationUnit();
unit->fileName = normalizedFile;
unit->FileName = normalizedFile;
TranslationUnits.push_back(unit);

return unit;
Expand All @@ -957,6 +984,9 @@ TranslationUnit* ASTContext::FindOrCreateModule(std::string File)
// Comments
Comment::Comment(CommentKind kind) : kind(kind) {}

DEF_STRING(RawComment, Text)
DEF_STRING(RawComment, BriefText)

RawComment::RawComment() : fullCommentBlock(0) {}

RawComment::~RawComment()
Expand Down Expand Up @@ -1007,10 +1037,12 @@ BlockContentComment::BlockContentComment(CommentKind Kind) : Comment(Kind) {}

BlockCommandComment::Argument::Argument() {}

BlockCommandComment::Argument::Argument(const Argument& rhs) : text(rhs.text) {}
BlockCommandComment::Argument::Argument(const Argument& rhs) : Text(rhs.Text) {}

BlockCommandComment::Argument::~Argument() {}

DEF_STRING(BlockCommandComment::Argument, Text)

BlockCommandComment::BlockCommandComment() : BlockContentComment(CommentKind::BlockCommandComment), commandId(0), paragraphComment(0) {}

BlockCommandComment::BlockCommandComment(CommentKind Kind) : BlockContentComment(Kind), commandId(0), paragraphComment(0) {}
Expand All @@ -1028,6 +1060,8 @@ TParamCommandComment::TParamCommandComment() : BlockCommandComment(CommentKind::

DEF_VECTOR(TParamCommandComment, unsigned, Position)

DEF_STRING(VerbatimBlockLineComment, Text)

VerbatimBlockComment::VerbatimBlockComment() : BlockCommandComment(CommentKind::VerbatimBlockComment) {}

VerbatimBlockComment::~VerbatimBlockComment()
Expand All @@ -1036,10 +1070,14 @@ VerbatimBlockComment::~VerbatimBlockComment()
delete line;
}

VerbatimBlockLineComment::VerbatimBlockLineComment() : Comment(CommentKind::VerbatimBlockLineComment) {}

DEF_VECTOR(VerbatimBlockComment, VerbatimBlockLineComment*, Lines)

VerbatimLineComment::VerbatimLineComment() : BlockCommandComment(CommentKind::VerbatimLineComment) {}

DEF_STRING(VerbatimLineComment, Text)

ParagraphComment::ParagraphComment() : BlockContentComment(CommentKind::ParagraphComment), isWhitespace(false) {}

ParagraphComment::~ParagraphComment()
Expand Down Expand Up @@ -1079,25 +1117,37 @@ HTMLTagComment::HTMLTagComment(CommentKind Kind) : InlineContentComment(Kind) {}

HTMLStartTagComment::Attribute::Attribute() {}

HTMLStartTagComment::Attribute::Attribute(const Attribute& rhs) : name(rhs.name), value(rhs.value) {}
HTMLStartTagComment::Attribute::Attribute(const Attribute& rhs) : Name(rhs.Name), Value(rhs.Value) {}

DEF_STRING(HTMLStartTagComment::Attribute, Name)

DEF_STRING(HTMLStartTagComment::Attribute, Value)

HTMLStartTagComment::Attribute::~Attribute() {}

HTMLStartTagComment::HTMLStartTagComment() : HTMLTagComment(CommentKind::HTMLStartTagComment) {}

DEF_VECTOR(HTMLStartTagComment, HTMLStartTagComment::Attribute, Attributes)

DEF_STRING(HTMLStartTagComment, TagName)

HTMLEndTagComment::HTMLEndTagComment() : HTMLTagComment(CommentKind::HTMLEndTagComment) {}

DEF_STRING(HTMLEndTagComment, TagName)

InlineContentComment::InlineContentComment() : Comment(CommentKind::InlineContentComment), hasTrailingNewline(false) {}

InlineContentComment::InlineContentComment(CommentKind Kind) : Comment(Kind), hasTrailingNewline(false) {}

TextComment::TextComment() : InlineContentComment(CommentKind::TextComment) {}

DEF_STRING(TextComment, Text)

InlineCommandComment::Argument::Argument() {}

InlineCommandComment::Argument::Argument(const Argument& rhs) : text(rhs.text) {}
InlineCommandComment::Argument::Argument(const Argument& rhs) : Text(rhs.Text) {}

DEF_STRING(InlineCommandComment::Argument, Text)

InlineCommandComment::Argument::~Argument() {}

Expand All @@ -1106,6 +1156,4 @@ InlineCommandComment::InlineCommandComment()

DEF_VECTOR(InlineCommandComment, InlineCommandComment::Argument, Arguments)

VerbatimBlockLineComment::VerbatimBlockLineComment() : Comment(CommentKind::VerbatimBlockLineComment) {}

} } }
Loading

0 comments on commit b684fe0

Please sign in to comment.