Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/AST/Interp/ByteCodeExprGen.cpp
Show First 20 Lines • Show All 554 Lines • ▼ Show 20 Lines | |||||
template <class Emitter> | template <class Emitter> | ||||
bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { | bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { | ||||
return this->visit(E->getSourceExpr()); | return this->visit(E->getSourceExpr()); | ||||
} | } | ||||
template <class Emitter> | template <class Emitter> | ||||
bool ByteCodeExprGen<Emitter>::VisitAbstractConditionalOperator( | bool ByteCodeExprGen<Emitter>::VisitAbstractConditionalOperator( | ||||
const AbstractConditionalOperator *E) { | const AbstractConditionalOperator *E) { | ||||
const Expr *Condition = E->getCond(); | return this->visitConditional( | ||||
const Expr *TrueExpr = E->getTrueExpr(); | E, [this](const Expr *E) { return this->visit(E); }); | ||||
const Expr *FalseExpr = E->getFalseExpr(); | |||||
LabelTy LabelEnd = this->getLabel(); // Label after the operator. | |||||
LabelTy LabelFalse = this->getLabel(); // Label for the false expr. | |||||
if (!this->visit(Condition)) | |||||
return false; | |||||
if (!this->jumpFalse(LabelFalse)) | |||||
return false; | |||||
if (!this->visit(TrueExpr)) | |||||
return false; | |||||
if (!this->jump(LabelEnd)) | |||||
return false; | |||||
this->emitLabel(LabelFalse); | |||||
if (!this->visit(FalseExpr)) | |||||
return false; | |||||
this->fallthrough(LabelEnd); | |||||
this->emitLabel(LabelEnd); | |||||
return true; | |||||
} | } | ||||
template <class Emitter> | template <class Emitter> | ||||
bool ByteCodeExprGen<Emitter>::VisitStringLiteral(const StringLiteral *E) { | bool ByteCodeExprGen<Emitter>::VisitStringLiteral(const StringLiteral *E) { | ||||
unsigned StringIndex = P.createGlobalString(E); | unsigned StringIndex = P.createGlobalString(E); | ||||
return this->emitGetPtrGlobal(StringIndex, E); | return this->emitGetPtrGlobal(StringIndex, E); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Lines | |||||
bool ByteCodeExprGen<Emitter>::visitBool(const Expr *E) { | bool ByteCodeExprGen<Emitter>::visitBool(const Expr *E) { | ||||
if (std::optional<PrimType> T = classify(E->getType())) { | if (std::optional<PrimType> T = classify(E->getType())) { | ||||
return visit(E); | return visit(E); | ||||
} else { | } else { | ||||
return this->bail(E); | return this->bail(E); | ||||
} | } | ||||
} | } | ||||
/// Visit a conditional operator, i.e. `A ? B : C`. | |||||
/// \V determines what function to call for the B and C expressions. | |||||
template <class Emitter> | |||||
bool ByteCodeExprGen<Emitter>::visitConditional( | |||||
const AbstractConditionalOperator *E, | |||||
llvm::function_ref<bool(const Expr *)> V) { | |||||
const Expr *Condition = E->getCond(); | |||||
const Expr *TrueExpr = E->getTrueExpr(); | |||||
const Expr *FalseExpr = E->getFalseExpr(); | |||||
LabelTy LabelEnd = this->getLabel(); // Label after the operator. | |||||
erichkeane: This meant to be here? | |||||
Nope! :( tbaeder: Nope! :( | |||||
LabelTy LabelFalse = this->getLabel(); // Label for the false expr. | |||||
Is this condition supposed to be just a 'visit', or should this be using the functor? erichkeane: Is this condition supposed to be just a 'visit', or should this be using the functor? | |||||
The visit is correct here, the functor is just for the true/false expr. tbaeder: The visit is correct here, the functor is just for the true/false expr. | |||||
if (!this->visit(Condition)) | |||||
return false; | |||||
if (!this->jumpFalse(LabelFalse)) | |||||
return false; | |||||
if (!V(TrueExpr)) | |||||
return false; | |||||
if (!this->jump(LabelEnd)) | |||||
return false; | |||||
this->emitLabel(LabelFalse); | |||||
if (!V(FalseExpr)) | |||||
return false; | |||||
this->fallthrough(LabelEnd); | |||||
this->emitLabel(LabelEnd); | |||||
return true; | |||||
} | |||||
template <class Emitter> | template <class Emitter> | ||||
bool ByteCodeExprGen<Emitter>::visitZeroInitializer(PrimType T, const Expr *E) { | bool ByteCodeExprGen<Emitter>::visitZeroInitializer(PrimType T, const Expr *E) { | ||||
switch (T) { | switch (T) { | ||||
case PT_Bool: | case PT_Bool: | ||||
return this->emitZeroBool(E); | return this->emitZeroBool(E); | ||||
case PT_Sint8: | case PT_Sint8: | ||||
return this->emitZeroSint8(E); | return this->emitZeroSint8(E); | ||||
case PT_Uint8: | case PT_Uint8: | ||||
▲ Show 20 Lines • Show All 492 Lines • ▼ Show 20 Lines | if (const auto CtorExpr = dyn_cast<CXXConstructExpr>(Initializer)) { | ||||
return this->visit(CE); | return this->visit(CE); | ||||
} else if (const auto *DIE = dyn_cast<CXXDefaultInitExpr>(Initializer)) { | } else if (const auto *DIE = dyn_cast<CXXDefaultInitExpr>(Initializer)) { | ||||
return this->visitInitializer(DIE->getExpr()); | return this->visitInitializer(DIE->getExpr()); | ||||
} else if (const auto *CE = dyn_cast<CastExpr>(Initializer)) { | } else if (const auto *CE = dyn_cast<CastExpr>(Initializer)) { | ||||
return this->visitInitializer(CE->getSubExpr()); | return this->visitInitializer(CE->getSubExpr()); | ||||
} else if (const auto *CE = dyn_cast<CXXBindTemporaryExpr>(Initializer)) { | } else if (const auto *CE = dyn_cast<CXXBindTemporaryExpr>(Initializer)) { | ||||
return this->visitInitializer(CE->getSubExpr()); | return this->visitInitializer(CE->getSubExpr()); | ||||
} else if (const auto *ACO = | |||||
dyn_cast<AbstractConditionalOperator>(Initializer)) { | |||||
return this->visitConditional( | |||||
ACO, [this](const Expr *E) { return this->visitRecordInitializer(E); }); | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
template <class Emitter> | template <class Emitter> | ||||
bool ByteCodeExprGen<Emitter>::visitInitializer(const Expr *Initializer) { | bool ByteCodeExprGen<Emitter>::visitInitializer(const Expr *Initializer) { | ||||
QualType InitializerType = Initializer->getType(); | QualType InitializerType = Initializer->getType(); | ||||
▲ Show 20 Lines • Show All 563 Lines • Show Last 20 Lines |
This meant to be here?