Skip to content

Commit 61c4496

Browse files
committed
Compiler: Add createStrCmpEQ() method
1 parent f2cdb0c commit 61c4496

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/scratchcpp/dev/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
8181
CompilerValue *createCmpGT(CompilerValue *operand1, CompilerValue *operand2);
8282
CompilerValue *createCmpLT(CompilerValue *operand1, CompilerValue *operand2);
8383

84+
CompilerValue *createStrCmpEQ(CompilerValue *string1, CompilerValue *string2, bool caseSensitive = false);
85+
8486
CompilerValue *createAnd(CompilerValue *operand1, CompilerValue *operand2);
8587
CompilerValue *createOr(CompilerValue *operand1, CompilerValue *operand2);
8688
CompilerValue *createNot(CompilerValue *operand);

src/dev/engine/compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ CompilerValue *Compiler::createCmpLT(CompilerValue *operand1, CompilerValue *ope
324324
return impl->builder->createCmpLT(operand1, operand2);
325325
}
326326

327+
/*! Creates a string equality comparison (explicitly casts operands to string). */
328+
CompilerValue *Compiler::createStrCmpEQ(CompilerValue *string1, CompilerValue *string2, bool caseSensitive)
329+
{
330+
return impl->builder->createStrCmpEQ(string1, string2, caseSensitive);
331+
}
332+
327333
/*! Creates an AND operation. */
328334
CompilerValue *Compiler::createAnd(CompilerValue *operand1, CompilerValue *operand2)
329335
{

test/dev/compiler/compiler_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,27 @@ TEST_F(CompilerTest, CreateCmpLT)
610610
compile(m_compiler.get(), block);
611611
}
612612

613+
TEST_F(CompilerTest, CreateStrCmpEQ)
614+
{
615+
616+
auto block = std::make_shared<Block>("", "");
617+
618+
block->setCompileFunction([](Compiler *compiler) -> CompilerValue * {
619+
CompilerValue arg1(Compiler::StaticType::Unknown);
620+
CompilerValue arg2(Compiler::StaticType::Unknown);
621+
CompilerValue ret(Compiler::StaticType::Unknown);
622+
EXPECT_CALL(*m_builder, createStrCmpEQ(&arg1, &arg2, true)).WillOnce(Return(&ret));
623+
EXPECT_EQ(compiler->createStrCmpEQ(&arg1, &arg2, true), &ret);
624+
625+
EXPECT_CALL(*m_builder, createStrCmpEQ(&arg1, &arg2, false)).WillOnce(Return(&ret));
626+
EXPECT_EQ(compiler->createStrCmpEQ(&arg1, &arg2, false), &ret);
627+
628+
return nullptr;
629+
});
630+
631+
compile(m_compiler.get(), block);
632+
}
633+
613634
TEST_F(CompilerTest, CreateAnd)
614635
{
615636

0 commit comments

Comments
 (0)