当前位置: 首页>>代码示例>>C++>>正文


C++ ScalarExpressionPtr::getString方法代码示例

本文整理汇总了C++中ScalarExpressionPtr::getString方法的典型用法代码示例。如果您正苦于以下问题:C++ ScalarExpressionPtr::getString方法的具体用法?C++ ScalarExpressionPtr::getString怎么用?C++ ScalarExpressionPtr::getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScalarExpressionPtr的用法示例。


在下文中一共展示了ScalarExpressionPtr::getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Expression

FunctionCall::FunctionCall
(EXPRESSION_CONSTRUCTOR_PARAMETERS,
 ExpressionPtr nameExp, const std::string &name, ExpressionListPtr params,
 ExpressionPtr classExp)
    : Expression(EXPRESSION_CONSTRUCTOR_PARAMETER_VALUES),
      StaticClassName(classExp), m_nameExp(nameExp), m_params(params),
      m_valid(false), m_validClass(false),
      m_extraArg(0), m_variableArgument(false), m_voidReturn(false),
      m_voidWrapper(false), m_allowVoidReturn(false), m_redeclared(false),
      m_redeclaredClass(false), m_derivedFromRedeclaring(false),
      m_argArrayId(-1) {

    if (m_nameExp &&
            m_nameExp->getKindOf() == Expression::KindOfScalarExpression) {
        ASSERT(m_name.empty());
        ScalarExpressionPtr c = dynamic_pointer_cast<ScalarExpression>(m_nameExp);
        m_origName = c->getString();
        c->toLower(true /* func call*/);
        m_name = c->getString();
        ASSERT(!m_name.empty());
    } else {
        m_origName = name;
        m_name = Util::toLower(name);
    }
}
开发者ID:kreshano,项目名称:hiphop-php,代码行数:25,代码来源:function_call.cpp

示例2: analyzeProgram

void BinaryOpExpression::analyzeProgram(AnalysisResultPtr ar) {
  if (m_op == T_INSTANCEOF && m_exp2->is(Expression::KindOfScalarExpression)) {
    ScalarExpressionPtr s = dynamic_pointer_cast<ScalarExpression>(m_exp2);
    addUserClass(ar, s->getString());
  }
  m_exp1->analyzeProgram(ar);
  m_exp2->analyzeProgram(ar);
}
开发者ID:jahankhanna,项目名称:hiphop-php,代码行数:8,代码来源:binary_op_expression.cpp

示例3: outputCPPProperty

void ObjectPropertyExpression::outputCPPProperty(CodeGenerator &cg,
        AnalysisResultPtr ar) {
    if (m_property->getKindOf() == Expression::KindOfScalarExpression) {
        ScalarExpressionPtr name =
            dynamic_pointer_cast<ScalarExpression>(m_property);
        cg_printString(name->getString(), ar, shared_from_this());
    } else {
        m_property->outputCPP(cg, ar);
    }
}
开发者ID:vitorgja,项目名称:hiphop-php,代码行数:10,代码来源:object_property_expression.cpp

示例4: getDynamicVariable

ExpressionPtr Parser::getDynamicVariable(ExpressionPtr exp, bool encap) {
  if (encap) {
    ConstantExpressionPtr var = dynamic_pointer_cast<ConstantExpression>(exp);
    if (var) {
      return NEW_EXP(SimpleVariable, var->getName());
    }
  } else {
    ScalarExpressionPtr var = dynamic_pointer_cast<ScalarExpression>(exp);
    if (var) {
      return NEW_EXP(SimpleVariable, var->getString());
    }
  }
  return createDynamicVariable(exp);
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:14,代码来源:parser.cpp

示例5: isNonPrivate

bool ObjectPropertyExpression::isNonPrivate(AnalysisResultPtr ar) {
    // To tell whether a property is declared as private in the context
    ClassScopePtr cls = getOriginalClass();
    if (!cls || !cls->getVariables()->hasNonStaticPrivate()) return true;
    if (m_property->getKindOf() != Expression::KindOfScalarExpression) {
        return false;
    }
    ScalarExpressionPtr name =
        dynamic_pointer_cast<ScalarExpression>(m_property);
    string propName = name->getString();
    Symbol *sym = cls->getVariables()->getSymbol(propName);
    if (!sym || sym->isStatic() || !sym->isPrivate()) return true;
    return false;
}
开发者ID:vitorgja,项目名称:hiphop-php,代码行数:14,代码来源:object_property_expression.cpp

示例6: getStrings

void ExpressionList::getStrings(std::vector<std::string> &strings) {
  for (unsigned int i = 0; i < m_exps.size(); i++) {
    ScalarExpressionPtr s = dynamic_pointer_cast<ScalarExpression>(m_exps[i]);
    strings.push_back(s->getString());
  }
}
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:6,代码来源:expression_list.cpp

示例7: outputCPPImpl

void ClassStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
  if (cg.getContext() == CodeGenerator::NoContext) {
    InterfaceStatement::outputCPPImpl(cg, ar);
    return;
  }

  ClassScopeRawPtr classScope = getClassScope();
  if (cg.getContext() != CodeGenerator::CppForwardDeclaration) {
    printSource(cg);
  }

  string clsNameStr = classScope->getId();
  const char *clsName = clsNameStr.c_str();

  switch (cg.getContext()) {
  case CodeGenerator::CppDeclaration:
    {
      if (Option::GenerateCPPMacros) {
        classScope->outputForwardDeclaration(cg);
      }
      classScope->outputCPPGlobalTableWrappersDecl(cg, ar);

      bool system = cg.getOutput() == CodeGenerator::SystemCPP;
      ClassScopePtr parCls;
      if (!m_parent.empty()) {
        parCls = ar->findClass(m_parent);
        if (parCls && parCls->isRedeclaring()) parCls.reset();
      }
      if (Option::GenerateCppLibCode) {
        cg.printDocComment(classScope->getDocComment());
      }
      cg_printf("class %s%s", Option::ClassPrefix, clsName);
      if (!m_parent.empty() && classScope->derivesDirectlyFrom(m_parent)) {
        if (!parCls) {
          cg_printf(" : public DynamicObjectData");
        } else {
          cg_printf(" : public %s%s", Option::ClassPrefix,
                    parCls->getId().c_str());
        }
      } else {
        if (classScope->derivesFromRedeclaring()) {
          cg_printf(" : public DynamicObjectData");
        } else if (system) {
          cg_printf(" : public ExtObjectData");
        } else {
          cg_printf(" : public ObjectData");
        }
      }
      if (m_base && Option::UseVirtualDispatch) {
        for (int i = 0; i < m_base->getCount(); i++) {
          ScalarExpressionPtr exp =
            dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
          const char *intf = exp->getString().c_str();
          ClassScopePtr intfClassScope = ar->findClass(intf);
          if (intfClassScope && !intfClassScope->isRedeclaring() &&
              classScope->derivesDirectlyFrom(intf) &&
              (!parCls || !parCls->derivesFrom(ar, intf, true, false))) {
            string id = intfClassScope->getId();
            cg_printf(", public %s%s", Option::ClassPrefix, id.c_str());
          }
        }
      }
      cg_indentBegin(" {\n");
      cg_printf("public:\n");

      cg.printSection("Properties");
      if (classScope->getVariables()->outputCPPPropertyDecl(
            cg, ar, classScope->derivesFromRedeclaring())) {
        cg.printSection("Destructor");
        cg_printf("~%s%s() NEVER_INLINE {}", Option::ClassPrefix, clsName);
      }

      if (Option::GenerateCppLibCode) {
        cg.printSection("Methods");
        classScope->outputMethodWrappers(cg, ar);
        cg.printSection(">>>>>>>>>> Internal Implementation <<<<<<<<<<");
        cg_printf("// NOTE: Anything below is subject to change. "
                  "Use everything above instead.\n");
      }

      cg.printSection("Class Map");

      bool hasEmitCppCtor = false;
      bool needsCppCtor = classScope->needsCppCtor();
      bool needsInit    = classScope->needsInitMethod();

      bool disableDestructor =
        !classScope->canSkipCreateMethod(ar) ||
        (!classScope->derivesFromRedeclaring() &&
         !classScope->hasAttribute(ClassScope::HasDestructor, ar));

      if (Option::GenerateCPPMacros) {
        bool dyn = classScope->derivesFromRedeclaring() ==
          ClassScope::DirectFromRedeclared;
        bool idyn = parCls && classScope->derivesFromRedeclaring() ==
          ClassScope::IndirectFromRedeclared;
        bool redec = classScope->isRedeclaring();

        if (!parCls && !m_parent.empty()) {
          assert(dyn);
//.........这里部分代码省略.........
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:101,代码来源:class_statement.cpp

示例8: outputCPPImpl

void InterfaceStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
  ClassScopeRawPtr classScope = getClassScope();
  if (cg.getContext() == CodeGenerator::NoContext) {
    if (classScope->isVolatile()) {
      cg_printf("g->CDEC(%s) = true;\n", cg.formatLabel(m_name).c_str());
    }
    return;
  }

  string clsNameStr = classScope->getId(cg);
  const char *clsName = clsNameStr.c_str();

  switch (cg.getContext()) {
  case CodeGenerator::CppForwardDeclaration:
    if (Option::GenerateCPPMacros) {
      if (!Option::UseVirtualDispatch ||
          classScope->isRedeclaring()) {
        cg_printf("FORWARD_DECLARE_GENERIC_INTERFACE(%s);\n", clsName);
      } else {
        cg_printf("FORWARD_DECLARE_INTERFACE(%s);\n", clsName);
      }
    }
    break;
  case CodeGenerator::CppDeclaration:
    {
      printSource(cg);
      cg_printf("class %s%s", Option::ClassPrefix, clsName);
      if (m_base && Option::UseVirtualDispatch &&
          !classScope->isRedeclaring()) {
        const char *sep = " :";
        for (int i = 0; i < m_base->getCount(); i++) {
          ScalarExpressionPtr exp =
            dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
          const char *intf = exp->getString().c_str();
          ClassScopePtr intfClassScope = ar->findClass(intf);
          if (intfClassScope && !intfClassScope->isRedeclaring() &&
              classScope->derivesDirectlyFrom(ar, intf)) {
            string id = intfClassScope->getId(cg);
            cg_printf("%s public %s%s", sep, Option::ClassPrefix, id.c_str());
            sep = ",";
          }
        }
      }
      cg_indentBegin(" {\n");
      if (m_stmt) m_stmt->outputCPP(cg, ar);
      cg_indentEnd("};\n");
    }
    break;
  case CodeGenerator::CppImplementation:
    // do nothing
    break;
  case CodeGenerator::CppFFIDecl:
  case CodeGenerator::CppFFIImpl:
    // do nothing
    break;
  case CodeGenerator::JavaFFI:
    {
      // TODO support PHP namespaces, once HPHP supports it
      string packageName = Option::JavaFFIRootPackage;
      string packageDir = packageName;
      Util::replaceAll(packageDir, ".", "/");

      string outputDir = ar->getOutputPath() + "/" + Option::FFIFilePrefix +
        packageDir + "/";
      Util::mkdir(outputDir);

      // uses a different cg to generate a separate file for each PHP class
      string clsFile = outputDir + getOriginalName() + ".java";
      ofstream fcls(clsFile.c_str());
      CodeGenerator cgCls(&fcls, CodeGenerator::FileCPP);
      cgCls.setContext(CodeGenerator::JavaFFIInterface);

      cgCls.printf("package %s;\n\n", packageName.c_str());
      cgCls.printf("import hphp.*;\n\n");

      cgCls.printf("public interface %s", getOriginalName().c_str());
      if (m_base) {
        bool first = true;
        for (int i = 0; i < m_base->getCount(); i++) {
          ScalarExpressionPtr exp =
            dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
          const char *intf = exp->getString().c_str();
          ClassScopePtr intfClassScope = ar->findClass(intf);
          if (intfClassScope && classScope->derivesFrom(ar, intf, false, false)
           && intfClassScope->isUserClass()) {
            if (first) {
              cgCls.printf(" extends ");
              first = false;
            }
            else {
              cgCls.printf(", ");
            }
            cgCls.printf(intfClassScope->getOriginalName().c_str());
          }
        }
      }

      cgCls.indentBegin(" {\n");
      if (m_stmt) m_stmt->outputCPP(cgCls, ar);
      cgCls.indentEnd("}\n");
//.........这里部分代码省略.........
开发者ID:dipjyotighosh,项目名称:hiphop-php,代码行数:101,代码来源:interface_statement.cpp

示例9: outputCPP

void ClassStatement::outputCPP(CodeGenerator &cg, AnalysisResultPtr ar) {
  ClassScopePtr classScope = m_classScope.lock();
  if (cg.getContext() == CodeGenerator::NoContext) {
    if (classScope->isRedeclaring()) {
      cg.printf("g->%s%s = ClassStaticsPtr(NEW(%s%s)());\n",
                Option::ClassStaticsObjectPrefix, m_name.c_str(),
                Option::ClassStaticsPrefix, classScope->getId().c_str());
    }
    if (classScope->isVolatile()) {
      cg.printf("g->declareClass(\"%s\");\n",
                m_name.c_str());
    }
    return;
  }

  if (cg.getContext() != CodeGenerator::CppForwardDeclaration) {
    printSource(cg);
  }

  ar->pushScope(classScope);
  string clsNameStr = classScope->getId();
  const char *clsName = clsNameStr.c_str();
  bool redeclared = classScope->isRedeclaring();
  switch (cg.getContext()) {
  case CodeGenerator::CppForwardDeclaration:
    if (Option::GenerateCPPMacros) {
      cg.printf("FORWARD_DECLARE_CLASS(%s)\n", clsName);
      if (redeclared) {
        cg.printf("FORWARD_DECLARE_REDECLARED_CLASS(%s)\n", clsName);
      }
    }
    if (m_stmt) {
      cg.setContext(CodeGenerator::CppClassConstantsDecl);
      m_stmt->outputCPP(cg, ar);
      cg.setContext(CodeGenerator::CppForwardDeclaration);
    }
    break;
  case CodeGenerator::CppDeclaration:
    {
      ClassScopePtr parCls;
      if (!m_parent.empty()) parCls = ar->findClass(m_parent);
      cg.printf("class %s%s", Option::ClassPrefix, clsName);
      bool derived = false;
      if (!m_parent.empty() && classScope->derivesFrom(ar, m_parent)) {
        if (parCls->isRedeclaring()) {
          cg.printf(" : public DynamicObjectData");
        } else {
          cg.printf(" : virtual public %s%s", Option::ClassPrefix,
                    parCls->getId().c_str());
        }
        derived = true;
      }
      if (m_base) {
        for (int i = 0; i < m_base->getCount(); i++) {
          ScalarExpressionPtr exp =
            dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
          const char *intf = exp->getString().c_str();
          ClassScopePtr intfClassScope = ar->findClass(intf);
          if (intfClassScope && classScope->derivesFrom(ar, intf)) {
            // temporary fix for inheriting from a re-declaring class
            string id = intfClassScope->getId();
            if (!derived) {
              derived = true;
              cg.printf(" :");
            } else {
              cg.printf(",");
            }
            cg.printf(" virtual public %s%s", Option::ClassPrefix, id.c_str());
          }
        }
      }
      if (!derived) {
        const char *op = derived ? "," : " :";
        if (classScope->derivesFromRedeclaring()) {
          cg.printf("%s public DynamicObjectData", op);
        } else {
          cg.printf("%s virtual public ObjectData", op);
        }
      }
      cg.indentBegin(" {\n");

      if (Option::GenerateCPPMacros) {
        vector<string> bases;
        getAllParents(ar, bases);

        cg.indentBegin("BEGIN_CLASS_MAP(%s)\n", clsName);
        for (unsigned int i = 0; i < bases.size(); i++) {
          cg.printf("PARENT_CLASS(%s)\n", bases[i].c_str());
        }
        cg.indentEnd("END_CLASS_MAP(%s)\n", clsName);
      }

      if (Option::GenerateCPPMacros) {
        bool dyn = classScope->derivesFromRedeclaring() ==
          ClassScope::DirectFromRedeclared;
        bool idyn = classScope->derivesFromRedeclaring() ==
          ClassScope::IndirectFromRedeclared;
        bool redec = classScope->isRedeclaring();
        if (!classScope->derivesFromRedeclaring()) {
          cg.printf("DECLARE_CLASS(%s, %s, %s)\n", clsName,
//.........这里部分代码省略.........
开发者ID:Neomeng,项目名称:hiphop-php,代码行数:101,代码来源:class_statement.cpp

示例10: outputCPPObjProperty

void ObjectPropertyExpression::outputCPPObjProperty(CodeGenerator &cg,
                                                    AnalysisResultPtr ar,
                                                    bool directVariant,
                                                    int doExist) {
  bool bThis = m_object->isThis();
  bool useGetThis = false;
  FunctionScopePtr funcScope = ar->getFunctionScope();
  if (bThis) {
    if (funcScope && funcScope->isStatic()) {
      cg_printf("GET_THIS_ARROW()");
    } else {
      // in order for __set() and __get() to be called
      useGetThis = true;
    }
  }

  const char *op = ".";
  string func = Option::ObjectPrefix;
  const char *error = ", true";
  ClassScopePtr cls = ar->getClassScope();
  const char *context = "";
  if (cg.getOutput() != CodeGenerator::SystemCPP) {
    if (cls) {
      context = ", s_class_name";
    } else if (funcScope && !funcScope->inPseudoMain()) {
      context = ", empty_string";
    }
  }
  if (doExist) {
    func = doExist > 0 ? "doIsSet" : "doEmpty";
    error = "";
  } else {
    if (bThis && funcScope && funcScope->isStatic()) {
      func = Option::ObjectStaticPrefix;
      error = "";
      context = "";
    } else if (m_context & ExistContext) {
      error = ", false";
    }
    if (m_context & (LValue | RefValue | UnsetContext)) {
      func += "lval";
      error = "";
    } else {
      func += "get";
    }
  }

  if (m_property->getKindOf() == Expression::KindOfScalarExpression) {
    ScalarExpressionPtr name =
      dynamic_pointer_cast<ScalarExpression>(m_property);
    const char *propName = name->getString().c_str();
    if (m_valid && m_object->getType()->isSpecificObject()) {
      if (m_static) {
        if (!bThis) {
          ASSERT(m_class);
          if (doExist) cg_printf(doExist > 0 ? "isset(" : "empty(");
          cg_printf("g->%s%s%s%s",
                    Option::StaticPropertyPrefix, m_class->getName().c_str(),
                    Option::IdPrefix.c_str(), propName);
          if (doExist) cg_printf(")");
        } else {
          // if $val is a class static variable (static $val), then $val
          // cannot be declared as a class variable (var $val), $this->val
          // refers to a non-static class variable and has to use get/lval.
          if (useGetThis) cg_printf("GET_THIS_DOT()");
          cg_printf("%s(", func.c_str());
          cg_printString(propName, ar);
          cg_printf("%s%s)", error, context);
        }
      } else {
        if (doExist) cg_printf(doExist > 0 ? "isset(" : "empty(");
        if (!bThis) {
          ASSERT(!directVariant);
          m_object->outputCPP(cg, ar);
          cg_printf("->");
        }
        cg_printf("%s%s", Option::PropertyPrefix, propName);
        if (doExist) cg_printf(")");
      }
    } else {
      if (!bThis) {
        if (directVariant) {
          TypePtr expectedType = m_object->getExpectedType();
          ASSERT(expectedType->is(Type::KindOfObject));
          // Clear m_expectedType to avoid type cast (toObject).
          m_object->setExpectedType(TypePtr());
          m_object->outputCPP(cg, ar);
          m_object->setExpectedType(expectedType);
        } else {
          m_object->outputCPP(cg, ar);
        }
        cg_printf(op);
      } else {
        if (useGetThis) cg_printf("GET_THIS_DOT()");
      }
      cg_printf("%s(", func.c_str());
      cg_printString(propName, ar);
      cg_printf("%s%s)", error, context);
    }
  } else {
//.........这里部分代码省略.........
开发者ID:leonhong,项目名称:hiphop-php,代码行数:101,代码来源:object_property_expression.cpp

示例11: outputCPPObjProperty

void ObjectPropertyExpression::outputCPPObjProperty(CodeGenerator &cg,
        AnalysisResultPtr ar,
        int doExist) {
    string func = Option::ObjectPrefix;
    const char *error = ", true";
    std::string context = "";
    bool doUnset = m_context & LValue && m_context & UnsetContext;
    bool needTemp = false;

    if (cg.getOutput() != CodeGenerator::SystemCPP) {
        context = originalClassName(cg, true);
    }
    if (doUnset) {
        func = "o_unset";
        error = "";
    } else if (doExist) {
        func = doExist > 0 ? "o_isset" : "o_empty";
        error = "";
    } else {
        if (m_context & ExistContext) {
            error = ", false";
        }
        if (m_context & InvokeArgument) {
            ASSERT(cg.callInfoTop() != -1);
            func += "argval";
        } else if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
            if (m_context & UnsetContext) {
                assert(!(m_context & LValue)); // handled by doUnset
                func += "unsetLval";
            } else {
                func += "lval";
            }
            error = "";
            needTemp = true;
        } else {
            func += "get";
            if (isNonPrivate(ar)) {
                func += "Public";
                context = "";
            }
        }
    }

    if (m_valid && doExist) cg_printf(doExist > 0 ? "isset(" : "empty(");
    bool flag = outputCPPObject(cg, ar, doUnset || (!m_valid && doExist));
    if (flag) {
        cg_printf("id(");
        outputCPPProperty(cg, ar);
        cg_printf(")");
        if (doExist) cg_printf(", %s", doExist > 0 ? "false" : "true");
        cg_printf(")");
    } else if (!doUnset && m_valid) {
        assert(m_object->getType()->isSpecificObject());
        ScalarExpressionPtr name =
            dynamic_pointer_cast<ScalarExpression>(m_property);
        cg_printf("%s%s", Option::PropertyPrefix, name->getString().c_str());
        if (doExist) cg_printf(")");
    } else {
        cg_printf("%s(", func.c_str());
        if (hasContext(InvokeArgument)) {
            cg_printf("cit%d->isRef(%d), ", cg.callInfoTop(), m_argNum);
        }
        outputCPPProperty(cg, ar);
        if (needTemp) {
            const string &tmp = cg.getReferenceTemp();
            context = ", " + (tmp.empty() ? "Variant()" : tmp) + context;
        }
        cg_printf("%s%s)", error, context.c_str());
    }
}
开发者ID:vitorgja,项目名称:hiphop-php,代码行数:70,代码来源:object_property_expression.cpp

示例12: inferTypes

TypePtr ObjectPropertyExpression::inferTypes(AnalysisResultPtr ar,
        TypePtr type, bool coerce) {
    m_valid = false;

    ConstructPtr self = shared_from_this();
    TypePtr objectType = m_object->inferAndCheck(ar, Type::Some, false);

    if (!m_property->is(Expression::KindOfScalarExpression)) {
        m_property->inferAndCheck(ar, Type::String, false);

        // we also lost track of which class variable an expression is about, hence
        // any type inference could be wrong. Instead, we just force variants on
        // all class variables.
        if (m_context & (LValue | RefValue)) {
            ar->forceClassVariants(getOriginalClass(), false, true);
        }

        return Type::Variant; // we have to use a variant to hold dynamic value
    }

    ScalarExpressionPtr exp = dynamic_pointer_cast<ScalarExpression>(m_property);
    const string &name = exp->getString();
    ASSERT(!name.empty());

    m_property->inferAndCheck(ar, Type::String, false);

    ClassScopePtr cls;
    if (objectType && !objectType->getName().empty()) {
        // what object-> has told us
        cls = ar->findExactClass(shared_from_this(), objectType->getName());
    } else {
        if ((m_context & LValue) && objectType &&
                !objectType->is(Type::KindOfObject) &&
                !objectType->is(Type::KindOfVariant) &&
                !objectType->is(Type::KindOfSome) &&
                !objectType->is(Type::KindOfAny)) {
            m_object->inferAndCheck(ar, Type::Object, true);
        }
    }

    if (!cls) {
        if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
            ar->forceClassVariants(name, getOriginalClass(), false, true);
        }
        return Type::Variant;
    }

    // resolved to this class
    if (m_context & RefValue) {
        type = Type::Variant;
        coerce = true;
    }

    // use $this inside a static function
    if (m_object->isThis()) {
        FunctionScopePtr func = m_object->getOriginalFunction();
        if (!func || func->isStatic()) {
            if (getScope()->isFirstPass()) {
                Compiler::Error(Compiler::MissingObjectContext, self);
            }
            m_actualType = Type::Variant;
            return m_actualType;
        }
    }

    ASSERT(cls);
    if (!m_propSym || cls != m_objectClass.lock()) {
        m_objectClass = cls;
        ClassScopePtr parent;
        m_propSym = cls->findProperty(parent, name, ar);
        if (m_propSym) {
            if (!parent) {
                parent = cls;
            }
            m_symOwner = parent;
            assert(m_propSym->isPresent());
            m_propSymValid =
                (!m_propSym->isPrivate() || getOriginalClass() == parent) &&
                !m_propSym->isStatic();

            if (m_propSymValid) {
                m_symOwner->addUse(getScope(),
                                   BlockScope::GetNonStaticRefUseKind(
                                       m_propSym->getHash()));
            }
        }
    }

    TypePtr ret;
    if (m_propSymValid && (!cls->derivesFromRedeclaring() ||
                           m_propSym->isPrivate())) {
        assert(m_symOwner);
        TypePtr t(m_propSym->getType());
        if (t && t->is(Type::KindOfVariant)) {
            // only check property if we could possibly do some work
            ret = t;
        } else {
            ASSERT(getScope()->is(BlockScope::FunctionScope));
            GET_LOCK(m_symOwner);
            ret = m_symOwner->checkProperty(getScope(), m_propSym, type, coerce, ar);
//.........这里部分代码省略.........
开发者ID:vitorgja,项目名称:hiphop-php,代码行数:101,代码来源:object_property_expression.cpp

示例13: outputCPPObjProperty

void ObjectPropertyExpression::outputCPPObjProperty(CodeGenerator &cg,
        AnalysisResultPtr ar,
        int doExist) {
    if (m_valid) {
        TypePtr type = m_object->getActualType();
        if (type->isSpecificObject()) {
            ClassScopePtr cls(type->getClass(ar, getScope()));
            if (cls) getFileScope()->addUsedClassFullHeader(cls);
        }
    }

    string func = Option::ObjectPrefix;
    const char *error = ", true";
    std::string context = "";
    bool doUnset = m_context & LValue && m_context & UnsetContext;
    bool needTemp = false;

    if (cg.getOutput() != CodeGenerator::SystemCPP) {
        context = originalClassName(cg, true);
    }
    if (doUnset) {
        func = "o_unset";
        error = "";
    } else if (doExist) {
        func = doExist > 0 ? "o_isset" : "o_empty";
        error = "";
    } else {
        if (m_context & ExistContext) {
            error = ", false";
        }
        if (m_context & InvokeArgument) {
            if (cg.callInfoTop() != -1) {
                func += "argval";
            } else {
                func += "get";
            }
        } else if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
            if (m_context & UnsetContext) {
                always_assert(!(m_context & LValue)); // handled by doUnset
                func += "unsetLval";
            } else {
                func += "lval";
            }
            error = "";
            needTemp = true;
        } else {
            func += "get";
            if (isNonPrivate(ar)) {
                func += "Public";
                context = "";
            }
        }
    }

    if (m_valid && !m_object->isThis() &&
            (!m_object->is(KindOfSimpleVariable) ||
             !static_pointer_cast<SimpleVariable>(m_object)->isGuarded())) {
        cg_printf("(obj_tmp = ");
        outputCPPValidObject(cg, ar, false);
        bool write_context = hasAnyContext(LValue | RefValue | DeepReference |
                                           UnsetContext | OprLValue |
                                           DeepOprLValue | DeepAssignmentLHS |
                                           AssignmentLHS) && !doUnset;
        cg_printf(", LIKELY(obj_tmp != 0) %s ", write_context ? "||" : "?");
        always_assert(m_property->is(KindOfScalarExpression));
        ScalarExpressionPtr name =
            static_pointer_cast<ScalarExpression>(m_property);
        if (doExist || doUnset) {
            cg_printf(doUnset ? "unset" : doExist > 0 ? "isset" : "empty");
        }
        ClassScopePtr cls =
            ar->findExactClass(shared_from_this(),
                               m_object->getActualType()->getName());

        if (write_context) {
            cg_printf("(throw_null_object_prop(),false),");
        }
        cg_printf("(((%s%s*)obj_tmp)->%s%s)",
                  Option::ClassPrefix, cls->getId().c_str(),
                  Option::PropertyPrefix, name->getString().c_str());

        if (!write_context) {
            cg_printf(" : (raise_null_object_prop(),%s)",
                      doUnset ? "null_variant" :
                      doExist ? doExist > 0 ? "false" : "true" :
                      nullName(ar, getCPPType()).c_str());
        }
        cg_printf(")");
        return;
    }

    if (m_valid && (doExist || doUnset)) {
        cg_printf(doUnset ? "unset(" : doExist > 0 ? "isset(" : "empty(");
    }
    bool flag = outputCPPObject(cg, ar, !m_valid && (doUnset || doExist));
    if (flag) {
        cg_printf("id(");
        outputCPPProperty(cg, ar);
        cg_printf(")");
        if (doExist) cg_printf(", %s", doExist > 0 ? "false" : "true");
//.........这里部分代码省略.........
开发者ID:jlvhangzhou,项目名称:hiphop-php,代码行数:101,代码来源:object_property_expression.cpp

示例14: outputCPPImpl

void InterfaceStatement::outputCPPImpl(CodeGenerator &cg,
                                       AnalysisResultPtr ar) {
  ClassScopeRawPtr classScope = getClassScope();
  if (cg.getContext() == CodeGenerator::NoContext) {
    if (classScope->isVolatile()) {
      const vector<string> &bases = classScope->getBases();
      for (unsigned i = 0; i < bases.size(); ++i) {
        const string &name = bases[i];
        if (cg.checkHoistedClass(name) ||
            classScope->hasKnownBase(i)) {
          continue;
        }
        ClassScopePtr base = ar->findClass(name);
        if (base && base->isVolatile()) {
          cg_printf("checkClassExistsThrow(");
          cg_printString(name, ar, shared_from_this());
          cg_printf(", &%s->CDEC(%s));\n",
                    cg.getGlobals(ar),
                    CodeGenerator::FormatLabel(base->getName()).c_str());
        }
      }
      classScope->outputCPPDef(cg);
      cg.addHoistedClass(m_name);
    }
    return;
  }

  string clsNameStr = classScope->getId();
  const char *clsName = clsNameStr.c_str();

  switch (cg.getContext()) {
  case CodeGenerator::CppDeclaration:
    {
      printSource(cg);
      if (Option::GenerateCPPMacros) {
        classScope->outputForwardDeclaration(cg);
      }
      if (classScope->isRedeclaring()) {
        classScope->outputCPPGlobalTableWrappersDecl(cg, ar);
      }
      cg_printf("class %s%s", Option::ClassPrefix, clsName);
      if (m_base && Option::UseVirtualDispatch &&
          !classScope->isRedeclaring()) {
        const char *sep = " :";
        for (int i = 0; i < m_base->getCount(); i++) {
          ScalarExpressionPtr exp =
            dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
          const char *intf = exp->getString().c_str();
          ClassScopePtr intfClassScope = ar->findClass(intf);
          if (intfClassScope && !intfClassScope->isRedeclaring() &&
              classScope->derivesDirectlyFrom(intf)) {
            string id = intfClassScope->getId();
            cg_printf("%s public %s%s", sep, Option::ClassPrefix, id.c_str());
            sep = ",";
          }
        }
      }
      cg_indentBegin(" {\n");
      if (m_stmt) m_stmt->outputCPP(cg, ar);

      bool hasPropTable = classScope->checkHasPropTable(ar);
      if (hasPropTable) {
        cg_printf("public: static const ClassPropTable %sprop_table;\n",
                  Option::ObjectStaticPrefix);
      }

      cg_indentEnd("};\n");
      if (hasPropTable) {
        classScope->outputCPPGlobalTableWrappersDecl(cg, ar);
      }
      if (m_stmt) {
        cg.setContext(CodeGenerator::CppClassConstantsDecl);
        m_stmt->outputCPP(cg, ar);
        cg.setContext(CodeGenerator::CppDeclaration);
      }
    }
    break;
  case CodeGenerator::CppImplementation:
    {
      if (m_stmt) {
        cg.setContext(CodeGenerator::CppClassConstantsImpl);
        m_stmt->outputCPP(cg, ar);
        cg.setContext(CodeGenerator::CppImplementation);
      }

      cg.addClass(getClassScope()->getName(), getClassScope());

      if (classScope->isRedeclaring() || classScope->checkHasPropTable(ar)) {
        classScope->outputCPPGlobalTableWrappersImpl(cg, ar);
      }
    }
    break;
  case CodeGenerator::CppFFIDecl:
  case CodeGenerator::CppFFIImpl:
    // do nothing
    break;
  case CodeGenerator::JavaFFI:
    {
      // TODO support PHP namespaces, once HPHP supports it
      string packageName = Option::JavaFFIRootPackage;
//.........这里部分代码省略.........
开发者ID:Bathrisyah,项目名称:hiphop-php,代码行数:101,代码来源:interface_statement.cpp

示例15: inferTypes

TypePtr ObjectPropertyExpression::inferTypes(AnalysisResultPtr ar,
                                             TypePtr type, bool coerce) {
  m_valid = false;

  ConstructPtr self = shared_from_this();
  TypePtr objectType = m_object->inferAndCheck(ar, Type::Some, false);

  if (!m_property->is(Expression::KindOfScalarExpression)) {
    m_property->inferAndCheck(ar, Type::String, false);

    // we also lost track of which class variable an expression is about, hence
    // any type inference could be wrong. Instead, we just force variants on
    // all class variables.
    if (m_context & (LValue | RefValue)) {
      ar->forceClassVariants(getOriginalClass(), false);
    }

    return Type::Variant; // we have to use a variant to hold dynamic value
  }

  ScalarExpressionPtr exp = dynamic_pointer_cast<ScalarExpression>(m_property);
  string name = exp->getString();
  ASSERT(!name.empty());

  m_property->inferAndCheck(ar, Type::String, false);

  ClassScopePtr cls;
  if (objectType && !objectType->getName().empty()) {
    // what object-> has told us
    cls = ar->findExactClass(shared_from_this(), objectType->getName());
  } else {
    if ((m_context & LValue) && objectType &&
        !objectType->is(Type::KindOfObject) &&
        !objectType->is(Type::KindOfVariant) &&
        !objectType->is(Type::KindOfSome) &&
        !objectType->is(Type::KindOfAny)) {
      m_object->inferAndCheck(ar, Type::Object, true);
    }
  }

  if (!cls) {
    if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
      ar->forceClassVariants(name, getOriginalClass(), false);
    }
    return Type::Variant;
  }

  int prop = hasContext(AssignmentLHS) ? ClassScope::MayHaveUnknownPropSetter :
    hasContext(ExistContext) ? ClassScope::MayHaveUnknownPropTester :
    hasContext(UnsetContext) && hasContext(LValue) ?
    ClassScope::MayHavePropUnsetter : ClassScope::MayHaveUnknownPropGetter;
  if ((m_context & (AssignmentLHS|OprLValue)) ||
      !cls->implementsAccessor(prop)) {
    clearEffect(AccessorEffect);
  }

  // resolved to this class
  if (m_context & RefValue) {
    type = Type::Variant;
    coerce = true;
  }

  // use $this inside a static function
  if (m_object->isThis()) {
    FunctionScopePtr func = m_object->getOriginalFunction();
    if (!func || func->isStatic()) {
      if (getScope()->isFirstPass()) {
        Compiler::Error(Compiler::MissingObjectContext, self);
      }
      m_actualType = Type::Variant;
      return m_actualType;
    }
  }

  if (!m_propSym || cls != m_objectClass.lock()) {
    m_objectClass = cls;
    ClassScopePtr parent;
    m_propSym = cls->findProperty(parent, name, ar, self);
    assert(m_propSym);
    if (!parent) {
      parent = cls;
    }
    m_propSymValid = m_propSym->isPresent() &&
      (!m_propSym->isPrivate() ||
       getOriginalClass() == parent) &&
      !m_propSym->isStatic();

    if (m_propSymValid) {
      parent->addUse(getScope(), BlockScope::UseKindNonStaticRef);
    }
  }

  TypePtr ret;
  if (m_propSymValid && (!cls->derivesFromRedeclaring() ||
                         m_propSym->isPrivate())) {
    ret = cls->checkProperty(m_propSym, type, coerce, ar);
    assert(m_object->getType()->isSpecificObject());
    m_valid = true;

    clearEffect(AccessorEffect);
//.........这里部分代码省略.........
开发者ID:akia,项目名称:hiphop-php,代码行数:101,代码来源:object_property_expression.cpp


注:本文中的ScalarExpressionPtr::getString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。