Example #1
0
void ClassScope::serialize(JSON::DocTarget::OutputStream &out) const {
  // TODO(stephentu): fix this hack
  ClassScopeRawPtr self(const_cast<ClassScope*>(this));

  JSON::DocTarget::MapStream ms(out);

  ms.add("name", getDocName());
  ms.add("line", getStmt() ? getStmt()->line0() : 0);
  ms.add("docs", m_docComment);

  ms.add("parent");
  if (m_parent.empty()) {
    out << JSON::Null();
  } else {
    out << GetDocName(out.analysisResult(), self, m_parent);
  }

  vector<string> ifaces;
  getInterfaces(out.analysisResult(), ifaces, true);
  vector<string> origIfaces;
  origIfaces.resize(ifaces.size());
  transform(ifaces.begin(), ifaces.end(), origIfaces.begin(),
            GetDocNameFunctor(out.analysisResult(), self));
  ms.add("interfaces", origIfaces);

  int mods = 0;
  switch (m_kindOf) {
    case KindOf::AbstractClass: mods |= ClassInfo::IsAbstract; break;
    case KindOf::Enum:
    case KindOf::FinalClass:
      mods |= ClassInfo::IsFinal; break;
    case KindOf::UtilClass:
      mods |= ClassInfo::IsFinal | ClassInfo::IsAbstract; break;
    case KindOf::Interface:     mods |= ClassInfo::IsInterface; break;
    case KindOf::Trait:         mods |= ClassInfo::IsTrait; break;
    case KindOf::ObjectClass:
      break;
  }
  ms.add("modifiers", mods);

  FunctionScopePtrVec funcs;
  getFunctionsFlattened(0, funcs);
  ms.add("methods", funcs);

  vector<Symbol*> rawSymbols;
  getVariables()->getSymbols(rawSymbols, true);
  vector<SymClassVarWrapper> wrappedSymbols;
  for (vector<Symbol*>::iterator it = rawSymbols.begin();
       it != rawSymbols.end(); ++it) {
    wrappedSymbols.push_back(SymClassVarWrapper(*it));
  }
  ms.add("properties", wrappedSymbols);

  // TODO: constants

  ms.done();
}
Example #2
0
void Symbol::serializeClassVar(JSON::DocTarget::OutputStream &out) const {
  assert(!isParameter());

  JSON::DocTarget::MapStream ms(out);
  ms.add("name", m_name);
  ms.add("line", m_declaration ? m_declaration->getLocation()->line0 : 0);

  int mods = 0;
  if (isPublic())    mods |= ClassInfo::IsPublic;
  if (isProtected()) mods |= ClassInfo::IsProtected;
  if (isPrivate())   mods |= ClassInfo::IsPrivate;
  if (isStatic())    mods |= ClassInfo::IsStatic;
  ms.add("modifiers", mods);

  ms.add("type", getFinalType());

  ms.add("initializer");
  if (m_initVal) {
    ExpressionPtr initExp(
      dynamic_pointer_cast<Expression>(m_initVal));
    assert(initExp);
    const string &init = ExtractInitializer(out.analysisResult(), initExp);
    if (!init.empty()) out << init;
    else               out << JSON::Null();
  } else {
    out << JSON::Null();
  }

  const string &docs = ExtractDocComment(
      m_declaration ?
        dynamic_pointer_cast<Expression>(m_declaration) : ExpressionPtr());
  ms.add("docs", docs);

  ms.done();
}
Example #3
0
void Type::serialize(JSON::DocTarget::OutputStream &out) const {
  string s("any");
  switch (m_kindOf) {
  case KindOfBoolean:     s = "boolean"; break;
  case KindOfInt32:
  case KindOfInt64:       s = "integer"; break;
  case KindOfDouble:      s = "double"; break;
  case KindOfString:      s = "string"; break;
  case KindOfArray:       s = "array"; break;
  case KindOfVariant:
  case KindOfSome:
  case KindOfAny:         s = "any"; break;
  case KindOfObject:
  {
    if (m_name.empty()) s = "object";
    else {
      ClassScopePtr c(getClass(out.analysisResult(), BlockScopeRawPtr()));
      if (c) {
        s = c->getOriginalName();
      } else {
        s = "object";
      }
    }
    break;
  }
  case KindOfNumeric:     s = "numeric"; break;
  case KindOfPrimitive:   s = "primitive"; break;
  case KindOfPlusOperand: s = "any"; break;
  case KindOfSequence:    s = "sequence"; break;
  }
  out << s;
}
Example #4
0
void Symbol::serializeParam(JSON::DocTarget::OutputStream &out) const {
  assert(isParameter());

  JSON::DocTarget::MapStream ms(out);
  ms.add("name",       m_name);
  ms.add("initializer");
  if (m_value) {
    auto valueExp = dynamic_pointer_cast<Expression>(m_value);
    assert(valueExp);
    auto const init = ExtractInitializer(out.analysisResult(), valueExp);
    if (!init.empty()) out << init;
    else               out << JSON::Null();
  } else {
    out << JSON::Null();
  }

  ms.done();
}
Example #5
0
void Symbol::serializeParam(JSON::DocTarget::OutputStream &out) const {
  assert(isParameter());

  JSON::DocTarget::MapStream ms(out);
  ms.add("name",       m_name);
  ms.add("type",       getFinalType());
  ms.add("referenced", isReferenced());

  ms.add("initializer");
  if (m_value) {
    ExpressionPtr valueExp(
      dynamic_pointer_cast<Expression>(m_value));
    assert(valueExp);
    const string &init = ExtractInitializer(out.analysisResult(), valueExp);
    if (!init.empty()) out << init;
    else               out << JSON::Null();
  } else {
    out << JSON::Null();
  }

  ms.done();
}