Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions CfrontCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,19 @@ CodeGeneratorVariant::CodeGenerators::CodeGenerators(OutputFormatHelper&
CodeGenerator::ProcessingPrimaryTemplate processingPrimaryTemplate)
{
if(GetInsightsOptions().UseShow2C) {
new(&cfcg) CfrontCodeGenerator{
_outputFormatHelper, lambdaStack, CodeGenerator::LambdaInInitCapture::No, processingPrimaryTemplate};
new(&cfcg) CfrontCodeGenerator{_outputFormatHelper, lambdaStack, processingPrimaryTemplate};
} else {
new(&cg) CodeGenerator{
_outputFormatHelper, lambdaStack, CodeGenerator::LambdaInInitCapture::No, processingPrimaryTemplate};
new(&cg) CodeGenerator{_outputFormatHelper, lambdaStack, processingPrimaryTemplate};
}
}
//-----------------------------------------------------------------------------

CodeGeneratorVariant::CodeGenerators::CodeGenerators(OutputFormatHelper& _outputFormatHelper,
CodeGenerator::LambdaInInitCapture lambdaInitCapture)
CodeGeneratorVariant::CodeGenerators::CodeGenerators(OutputFormatHelper& _outputFormatHelper)
{
if(GetInsightsOptions().UseShow2C) {
new(&cfcg) CfrontCodeGenerator{_outputFormatHelper, lambdaInitCapture};
new(&cfcg) CfrontCodeGenerator{_outputFormatHelper};
} else {
new(&cg) CodeGenerator{_outputFormatHelper, lambdaInitCapture};
new(&cg) CodeGenerator{_outputFormatHelper};
}
}
//-----------------------------------------------------------------------------
Expand Down
480 changes: 140 additions & 340 deletions CodeGenerator.cpp

Large diffs are not rendered by default.

87 changes: 20 additions & 67 deletions CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,23 @@ class CodeGenerator
enum class LambdaCallerType
{
VarDecl,
InitCapture,
CallExpr,
OperatorCallExpr,
MemberCallExpr,
LambdaExpr,
ReturnStmt,
BinaryOperator,
CXXMethodDecl,
TemplateHead,
LambdaExpr,
Decltype,
DecltypeWithName,
};

class LambdaHelper : public StackListEntry<LambdaHelper>
{
public:
LambdaHelper(const LambdaCallerType lambdaCallerType, OutputFormatHelper& outputFormatHelper)
: mLambdaCallerType{lambdaCallerType}
, mCurrentVarDeclPos{outputFormatHelper.CurrentPos()}
, mCurrentDeclPos{outputFormatHelper.CurrentPos()}
, mOutputFormatHelper{outputFormatHelper}
{
mLambdaOutputFormatHelper.SetIndent(mOutputFormatHelper);
Expand All @@ -132,71 +131,44 @@ class CodeGenerator
void finish()
{
if(not mLambdaOutputFormatHelper.empty()) {
mOutputFormatHelper.InsertAt(mCurrentVarDeclPos, mLambdaOutputFormatHelper);
mOutputFormatHelper.InsertAt(mCurrentDeclPos, mLambdaOutputFormatHelper);
}
}

OutputFormatHelper& buffer() { return mLambdaOutputFormatHelper; }

std::string& inits() { return mInits; }

void insertInits(OutputFormatHelper& outputFormatHelper)
{
if(not mInits.empty()) {
outputFormatHelper.Append(mInits);
mInits.clear();
}
LambdaCallerType callerType() const { return mLambdaCallerType; }
void setCallerType(LambdaCallerType lambdaCallerType) { mLambdaCallerType = lambdaCallerType; }
bool insertName() const
{ // do we require the name or only the datatype?
return (mLambdaCallerType != LambdaCallerType::Decltype) and
(mLambdaCallerType != LambdaCallerType::LambdaExpr);
}

LambdaCallerType callerType() const { return mLambdaCallerType; }
bool insertName() const { return (LambdaCallerType::Decltype != mLambdaCallerType) or mForceName; }

void setInsertName(bool b) { mForceName = b; }

private:
const LambdaCallerType mLambdaCallerType;
const size_t mCurrentVarDeclPos;
OutputFormatHelper& mOutputFormatHelper;
OutputFormatHelper mLambdaOutputFormatHelper{};
std::string mInits{};
bool mForceName{};
LambdaCallerType mLambdaCallerType{};
const size_t mCurrentDeclPos{};
OutputFormatHelper& mOutputFormatHelper;
OutputFormatHelper mLambdaOutputFormatHelper{};
};
//-----------------------------------------------------------------------------

using LambdaStackType = StackList<class LambdaHelper>;

STRONG_BOOL(LambdaInInitCapture); ///! Signal whether we are processing a lambda created and assigned to an init
/// capture of another lambda.

STRONG_BOOL(
ProcessingPrimaryTemplate); ///! We do not want to transform a primary template which contains a Coroutine.

constexpr CodeGenerator(OutputFormatHelper& _outputFormatHelper,
LambdaStackType& lambdaStack,
LambdaInInitCapture lambdaInitCapture,
ProcessingPrimaryTemplate processingPrimaryTemplate)
: mOutputFormatHelper{_outputFormatHelper}
, mLambdaStack{lambdaStack}
, mLambdaInitCapture{lambdaInitCapture}
, mProcessingPrimaryTemplate{processingPrimaryTemplate}
{
}

public:
explicit constexpr CodeGenerator(OutputFormatHelper& _outputFormatHelper)
: CodeGenerator{_outputFormatHelper, mLambdaStackThis, ProcessingPrimaryTemplate::No}
{
}

constexpr CodeGenerator(OutputFormatHelper& _outputFormatHelper, LambdaInInitCapture lambdaInitCapture)
: CodeGenerator{_outputFormatHelper, mLambdaStackThis, lambdaInitCapture, ProcessingPrimaryTemplate::No}
{
}

constexpr CodeGenerator(OutputFormatHelper& _outputFormatHelper,
LambdaStackType& lambdaStack,
ProcessingPrimaryTemplate processingPrimaryTemplate)
: CodeGenerator{_outputFormatHelper, lambdaStack, LambdaInInitCapture::No, processingPrimaryTemplate}
: mOutputFormatHelper{_outputFormatHelper}
, mLambdaStack{lambdaStack}
, mProcessingPrimaryTemplate{processingPrimaryTemplate}
{
}

Expand Down Expand Up @@ -420,7 +392,6 @@ class CodeGenerator
OutputFormatHelper& GetBuffer(OutputFormatHelper& outputFormatHelper) const;
};

void HandleLambdaExpr(const LambdaExpr* stmt, LambdaHelper& lambdaHelper);
static std::string FillConstantArray(const ConstantArrayType* ct, const std::string& value, const uint64_t startAt);
static std::string GetValueOfValueInit(const QualType& t);

Expand All @@ -433,7 +404,6 @@ class CodeGenerator
STRONG_BOOL(UseCommaInsteadOfSemi);
STRONG_BOOL(NoEmptyInitList);
STRONG_BOOL(ShowConstantExprValue);
LambdaInInitCapture mLambdaInitCapture{LambdaInInitCapture::No};

ShowConstantExprValue mShowConstantExprValue{ShowConstantExprValue::No};
SkipVarDecl mSkipVarDecl{SkipVarDecl::No};
Expand Down Expand Up @@ -461,18 +431,6 @@ class CodeGenerator
};
//-----------------------------------------------------------------------------

class LambdaCodeGenerator final : public CodeGenerator
{
public:
using CodeGenerator::CodeGenerator;

using CodeGenerator::InsertArg;
void InsertArg(const CXXThisExpr* stmt) override;

bool mCapturedThisAsCopy{};
};
//-----------------------------------------------------------------------------

/*
* \brief Special case to generate the inits of e.g. a \c ForStmt.
*
Expand Down Expand Up @@ -679,7 +637,7 @@ class CodeGeneratorVariant
CodeGenerators(OutputFormatHelper& _outputFormatHelper,
CodeGenerator::LambdaStackType& lambdaStack,
CodeGenerator::ProcessingPrimaryTemplate processingPrimaryTemplate);
CodeGenerators(OutputFormatHelper& _outputFormatHelper, CodeGenerator::LambdaInInitCapture lambdaInitCapture);
CodeGenerators(OutputFormatHelper& _outputFormatHelper);

~CodeGenerators();
} cgs;
Expand All @@ -690,11 +648,6 @@ class CodeGeneratorVariant
void Set();

public:
CodeGeneratorVariant(OutputFormatHelper& _outputFormatHelper)
: CodeGeneratorVariant{_outputFormatHelper, CodeGenerator::LambdaInInitCapture::No}
{
}

CodeGeneratorVariant(OutputFormatHelper& _outputFormatHelper,
CodeGenerator::LambdaStackType& lambdaStack,
CodeGenerator::ProcessingPrimaryTemplate processingPrimaryTemplate)
Expand All @@ -705,8 +658,8 @@ class CodeGeneratorVariant
Set();
}

CodeGeneratorVariant(OutputFormatHelper& _outputFormatHelper, CodeGenerator::LambdaInInitCapture lambdaInitCapture)
: cgs{_outputFormatHelper, lambdaInitCapture}
CodeGeneratorVariant(OutputFormatHelper& _outputFormatHelper)
: cgs{_outputFormatHelper}
, ofm{_outputFormatHelper}
, cg{}
{
Expand Down
1 change: 1 addition & 0 deletions InsightsStaticStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ consteval std::string_view KwWithNoSpace(std::string_view kw)
return kw;
}

inline constexpr std::string_view kwConstExpr{KW_CONSTEXPR};
inline constexpr std::string_view kwNoexcept{KW_NOEXCEPT};
inline constexpr std::string_view kwRequires{KW_REQUIRES};
inline constexpr std::string_view kwPublic{KW_PUBLIC};
Expand Down
5 changes: 2 additions & 3 deletions tests/Basic.Start.Main.P5.3Test.expect
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ int main()
return __lambda_3_13{}.operator()();
}


} __lambda_3_13{};
};

int x = __lambda_3_13.operator()();
int x = __lambda_3_13{}.operator()();
return 0;
}
5 changes: 2 additions & 3 deletions tests/Basic.Start.Main.P5.4Test.expect
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ int main(int argc, const char ** argv)
return __lambda_5_13{}.operator()();
}


} __lambda_5_13{};
};

int x = __lambda_5_13.operator()();
int x = __lambda_5_13{}.operator()();
return 0;
}
5 changes: 2 additions & 3 deletions tests/ClassOperatorHandler2Test.expect
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ int main()
__lambda_60_5{}.operator()();
}


} __lambda_60_5{};
};

__lambda_60_5.operator()();
__lambda_60_5{}.operator()();
int n = 10;
f(n);
f(42);
Expand Down
7 changes: 3 additions & 4 deletions tests/ConstevalTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class __lambda_16_15


public:
// /*constexpr */ __lambda_16_15() = default;

} __lambda_16_15{};
// /* constexpr */ __lambda_16_15() = default;
};

/* PASSED: static_assert(__lambda_16_15.operator()()); */
/* PASSED: static_assert(__lambda_16_15{}.operator()()); */
3 changes: 1 addition & 2 deletions tests/ConstraintAutoParameterTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class __lambda_6_15
}

public:
// /*constexpr */ __lambda_6_15() = default;

// /* constexpr */ __lambda_6_15() = default;
};

__lambda_6_15 lambda = __lambda_6_15{};
Expand Down
4 changes: 2 additions & 2 deletions tests/EduCoroutineWithLambdaTest.cerr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.tmp.cpp:79:9: note: in instantiation of member function 'SyncAwait(std::suspend_always &&)::__lambda_45_24::operator()' requested here
79 | class __lambda_45_24
| ^
.tmp.cpp:232:3: note: in instantiation of function template specialization 'SyncAwait<std::suspend_always>' requested here
232 | SyncAwait(std::suspend_always{});
.tmp.cpp:225:3: note: in instantiation of function template specialization 'SyncAwait<std::suspend_always>' requested here
225 | SyncAwait(std::suspend_always{});
| ^
.tmp.cpp:76:25: note: 'a' declared here
76 | void SyncAwait(_AwrT && a)
Expand Down
9 changes: 1 addition & 8 deletions tests/EduCoroutineWithLambdaTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ void SyncAwait(_AwrT && a)
co_await a;
}


};

auto asyncLambda = __lambda_45_24{};
Expand Down Expand Up @@ -211,14 +210,8 @@ inline generator operator()() const
}


private:
// private:
std::suspend_always & a;

public:
__lambda_45_24(std::suspend_always & _a)
: a{_a}
{}

};

__lambda_45_24 asyncLambda = __lambda_45_24{a};
Expand Down
5 changes: 2 additions & 3 deletions tests/EmptyLambda.expect
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ void foo()
__lambda_2_1{}.operator()();
}


} __lambda_2_1{};
};

__lambda_2_1.operator()();
__lambda_2_1{}.operator()();
}
Loading
Loading