本文整理汇总了C++中AssignmentExpressionPtr::getVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ AssignmentExpressionPtr::getVariable方法的具体用法?C++ AssignmentExpressionPtr::getVariable怎么用?C++ AssignmentExpressionPtr::getVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssignmentExpressionPtr
的用法示例。
在下文中一共展示了AssignmentExpressionPtr::getVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: analyzeProgramImpl
void ClassVariable::analyzeProgramImpl(AnalysisResultPtr ar) {
m_declaration->analyzeProgram(ar);
AnalysisResult::Phase phase = ar->getPhase();
if (phase != AnalysisResult::AnalyzeAll) {
return;
}
ClassScopePtr scope = getClassScope();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
scope->getVariables()->setClassInitVal(var->getName(), value);
scope->getVariables()->markOverride(ar, var->getName());
} else {
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(exp);
scope->getVariables()->markOverride(ar, var->getName());
scope->getVariables()->setClassInitVal(var->getName(),
makeConstant(ar, "null"));
}
}
}
示例2: analyzeProgram
void ClassVariable::analyzeProgram(AnalysisResultPtr ar) {
m_declaration->analyzeProgram(ar);
AnalysisResult::Phase phase = ar->getPhase();
if (phase != AnalysisResult::AnalyzeAll) {
return;
}
if (m_modifiers->isAbstract()) {
Compiler::Error(Compiler::AbstractProperty, shared_from_this());
}
ClassScopePtr scope = getClassScope();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
bool error;
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
scope->getVariables()->setClassInitVal(var->getName(), value);
error = scope->getVariables()->markOverride(ar, var->getName());
} else {
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(exp);
error = scope->getVariables()->markOverride(ar, var->getName());
scope->getVariables()->setClassInitVal(var->getName(),
makeConstant(ar, "null"));
}
if (error) {
Compiler::Error(Compiler::InvalidOverride, exp);
}
}
}
示例3: onParse
void ClassVariable::onParse(AnalysisResultPtr ar) {
ModifierExpressionPtr modifiers =
ar->getScope()->setModifiers(m_modifiers);
for (int i = 0; i < m_declaration->getCount(); i++) {
VariableTablePtr variables = ar->getScope()->getVariables();
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<SimpleVariable>(var)->getName();
if (variables->isPresent(name)) {
ar->getCodeError()->record(CodeError::DeclaredVariableTwice, exp);
}
IParseHandlerPtr ph = dynamic_pointer_cast<IParseHandler>(exp);
ph->onParse(ar);
} else {
const std::string &name =
dynamic_pointer_cast<SimpleVariable>(exp)->getName();
if (variables->isPresent(name)) {
ar->getCodeError()->record(CodeError::DeclaredVariableTwice, exp);
}
variables->add(name, TypePtr(), false, ar, exp, m_modifiers);
}
}
ar->getScope()->setModifiers(modifiers);
}
示例4: inferTypes
void ClassVariable::inferTypes(AnalysisResultPtr ar) {
ASSERT(getScope().get() == getClassScope().get());
IMPLEMENT_INFER_AND_CHECK_ASSERT(getScope());
m_declaration->inferAndCheck(ar, Type::Variant, false);
if (m_modifiers->isStatic()) {
ClassScopePtr scope = getClassScope();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
// If the class variable's type is Object, we have to
// force it to be a Variant, because we don't include
// the class header files in global_variables.h
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
if (var) {
TypePtr type = scope->getVariables()->getFinalType(var->getName());
if (type->is(Type::KindOfObject)) {
scope->getVariables()->forceVariant(ar, var->getName(),
VariableTable::AnyVars);
}
}
ExpressionPtr value = assignment->getValue();
if (value->containsDynamicConstant(ar)) {
scope->getVariables()->
setAttribute(VariableTable::ContainsDynamicStatic);
}
}
}
}
}
示例5: preOptimize
StatementPtr ClassConstant::preOptimize(AnalysisResultConstPtr ar) {
if (!isAbstract() && !isTypeconst()) {
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
ExpressionPtr val = assignment->getValue();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
Symbol *sym = getScope()->getConstants()->getSymbol(name);
Lock lock(BlockScope::s_constMutex);
if (sym->getValue() != val) {
getScope()->addUpdates(BlockScope::UseKindConstRef);
sym->setValue(val);
}
}
}
// abstract constants are not added to the constant table and don't have
// any values to propagate.
return StatementPtr();
}
示例6: onParseRecur
void ClassVariable::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ModifierExpressionPtr modifiers =
scope->setModifiers(m_modifiers);
for (int i = 0; i < m_declaration->getCount(); i++) {
VariableTablePtr variables = scope->getVariables();
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<SimpleVariable>(var)->getName();
if (variables->isPresent(name)) {
Compiler::Error(Compiler::DeclaredVariableTwice, exp);
m_declaration->removeElement(i--);
} else {
assignment->onParseRecur(ar, scope);
}
} else {
const std::string &name =
dynamic_pointer_cast<SimpleVariable>(exp)->getName();
if (variables->isPresent(name)) {
Compiler::Error(Compiler::DeclaredVariableTwice, exp);
m_declaration->removeElement(i--);
} else {
variables->add(name, Type::Variant, false, ar, exp, m_modifiers);
}
}
}
scope->setModifiers(modifiers);
}
示例7: onParseRecur
void ClassConstant::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ConstantTablePtr constants = scope->getConstants();
if (scope->isTrait()) {
parseTimeFatal(Compiler::InvalidTraitStatement,
"Traits cannot have constants");
}
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
if (constants->isPresent(name)) {
assignment->parseTimeFatal(Compiler::DeclaredConstantTwice,
"Cannot redeclare %s::%s",
scope->getOriginalName().c_str(),
name.c_str());
} else {
assignment->onParseRecur(ar, scope);
}
}
}
示例8: onParseRecur
void ClassConstant::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ConstantTablePtr constants = scope->getConstants();
if (scope->isTrait()) {
parseTimeFatal(Compiler::InvalidTraitStatement,
"Traits cannot have constants");
}
if (isAbstract()) {
for (int i = 0; i < m_exp->getCount(); i++) {
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>((*m_exp)[i]);
const std::string &name = exp->getName();
if (constants->isPresent(name)) {
exp->parseTimeFatal(Compiler::DeclaredConstantTwice,
"Cannot redeclare %s::%s",
scope->getOriginalName().c_str(),
name.c_str());
}
// HACK: break attempts to write global constants here;
// see ConstantExpression::preOptimize
exp->setContext(Expression::LValue);
// Unlike with assignment expression below, nothing needs to be added
// to the scope's constant table
}
} else {
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
if (constants->isPresent(name)) {
assignment->parseTimeFatal(Compiler::DeclaredConstantTwice,
"Cannot redeclare %s::%s",
scope->getOriginalName().c_str(),
name.c_str());
} else {
if (isTypeconst()) {
// We do not want type constants to be available at run time.
// To ensure this we do not want them to be added to the constants
// table. The constants table is used to inline values for expressions
// See ClassConstantExpression::preOptimize.
// AssignmentExpression::onParseRecur essentially adds constants to
// the constant table so we skip it.
continue;
}
assignment->onParseRecur(ar, scope);
}
}
}
}
示例9: preOptimize
StatementPtr ClassVariable::preOptimize(AnalysisResultConstPtr ar) {
ClassScopePtr scope = getClassScope();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
scope->getVariables()->setClassInitVal(var->getName(), value);
}
}
return StatementPtr();
}
示例10: analyzeProgramImpl
void ClassVariable::analyzeProgramImpl(AnalysisResultPtr ar) {
m_declaration->analyzeProgram(ar);
if (ar->getPhase() != AnalysisResult::AnalyzeInclude) return;
ClassScopePtr scope = ar->getClassScope();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
scope->getVariables()->setClassInitVal(var->getName(), value);
}
}
}
示例11: getCtorAndInitInfo
void ClassVariable::getCtorAndInitInfo(
ExpressionPtr exp,
bool &needsCppCtor,
bool &needsInit,
SimpleVariablePtr &var,
TypePtr &type,
Symbol *&sym,
ExpressionPtr &value) {
ClassScopePtr scope = getClassScope();
bool derivFromRedec = scope->derivesFromRedeclaring() &&
!m_modifiers->isPrivate();
AssignmentExpressionPtr assignment;
bool isAssign = exp->is(Expression::KindOfAssignmentExpression);
if (isAssign) {
assignment = static_pointer_cast<AssignmentExpression>(exp);
var = dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ASSERT(var);
value = assignment->getValue();
ASSERT(value);
} else {
var = dynamic_pointer_cast<SimpleVariable>(exp);
ASSERT(var);
}
sym = scope->getVariables()->getSymbol(var->getName());
ASSERT(sym);
type = scope->getVariables()->getFinalType(var->getName());
ASSERT(type);
bool isValueNull = isAssign ? value->isLiteralNull() : false;
bool typeIsInitable = type->is(Type::KindOfVariant) ||
type->getCPPInitializer();
if (!derivFromRedec &&
!sym->isOverride() &&
(isAssign ?
(isValueNull ||
(value->is(Expression::KindOfScalarExpression) &&
type->isPrimitive())) :
typeIsInitable)) {
needsCppCtor = true;
} else if (isAssign || typeIsInitable) {
// if we aren't an assignment and the type is not a variant
// w/ no CPP initializer, then we currently don't bother
// to initialize it in init().
needsInit = true;
}
}
示例12: onParseRecur
void ClassVariable::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ModifierExpressionPtr modifiers =
scope->setModifiers(m_modifiers);
if (m_modifiers->isAbstract()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Properties cannot be declared abstract");
}
if (m_modifiers->isFinal()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Properties cannot be declared final");
}
for (int i = 0; i < m_declaration->getCount(); i++) {
VariableTablePtr variables = scope->getVariables();
ExpressionPtr exp = (*m_declaration)[i];
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<SimpleVariable>(var)->getName();
if (variables->isPresent(name)) {
exp->parseTimeFatal(Compiler::DeclaredVariableTwice,
"Cannot redeclare %s::$%s",
scope->getOriginalName().c_str(), name.c_str());
} else {
assignment->onParseRecur(ar, scope);
}
} else {
const std::string &name =
dynamic_pointer_cast<SimpleVariable>(exp)->getName();
if (variables->isPresent(name)) {
exp->parseTimeFatal(Compiler::DeclaredVariableTwice,
"Cannot redeclare %s::$%s",
scope->getOriginalName().c_str(), name.c_str());
} else {
variables->add(name, Type::Null, false, ar, exp, m_modifiers);
}
}
}
scope->setModifiers(modifiers);
}
示例13: onParse
void ExpStatement::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
if (Option::OutputHHBC && !ar->isParseOnDemand()) return;
if (!m_exp->is(Expression::KindOfAssignmentExpression)) return;
AssignmentExpressionPtr assign =
dynamic_pointer_cast<AssignmentExpression>(m_exp);
if (!assign->getVariable()->is(Expression::KindOfArrayElementExpression)) {
return;
}
if (!assign->getValue()->is(Expression::KindOfScalarExpression) ||
!dynamic_pointer_cast<ScalarExpression>
(assign->getValue())->isLiteralString()) {
return;
}
string file = assign->getValue()->getLiteralString();
if (file.empty()) return;
string s = assign->getText();
string path = Option::GetAutoloadRoot(s);
if (path.empty()) return;
if (path[path.length() - 1] != '/' && file[0] != '/') {
file = path + '/' + file;
} else {
file = path + file;
}
if (Option::OutputHHBC) {
ar->parseOnDemand(file);
return;
}
ScalarExpressionPtr exp
(new ScalarExpression(getScope(), assign->getValue()->getLocation(),
T_STRING, file, true));
IncludeExpressionPtr include
(new IncludeExpression(getScope(), assign->getLocation(),
exp, T_INCLUDE_ONCE));
include->setDocumentRoot(); // autoload always starts from document root
include->onParse(ar, scope);
m_exp = include;
}
示例14: onParseRecur
void ClassConstant::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ConstantTablePtr constants = scope->getConstants();
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
if (constants->isPresent(name)) {
Compiler::Error(Compiler::DeclaredConstantTwice, assignment);
m_exp->removeElement(i--);
} else {
assignment->onParseRecur(ar, scope);
}
}
}
示例15: addTraitPropsToScope
void ClassVariable::addTraitPropsToScope(AnalysisResultPtr ar,
ClassScopePtr scope) {
ModifierExpressionPtr modifiers = scope->setModifiers(m_modifiers);
VariableTablePtr variables = scope->getVariables();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
SimpleVariablePtr var;
ExpressionPtr value;
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
var = dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
value = assignment->getValue();
} else {
var = dynamic_pointer_cast<SimpleVariable>(exp);
value = makeConstant(ar, "null");
}
const string &name = var->getName();
Symbol *sym;
ClassScopePtr prevScope = variables->isPresent(name) ? scope :
scope->getVariables()->findParent(ar, name, sym);
if (prevScope &&
!isEquivRedecl(name, exp, m_modifiers,
prevScope->getVariables()->getSymbol(name))) {
Compiler::Error(Compiler::DeclaredVariableTwice, exp);
m_declaration->removeElement(i--);
} else {
if (prevScope != scope) { // Property is new or override, so add it
variables->add(name, Type::Variant, false, ar, exp, m_modifiers);
variables->getSymbol(name)->setValue(exp);
variables->setClassInitVal(name, value);
variables->markOverride(ar, name);
} else {
m_declaration->removeElement(i--);
}
}
}
scope->setModifiers(modifiers);
}