Exemplo n.º 1
0
    BsonTreeModel::BsonTreeModel(const std::vector<MongoDocumentPtr> &documents, QObject *parent) :
        BaseClass(parent),
        _root(new BsonTreeItem(this))
    {
        for (int i = 0; i < documents.size(); ++i) {
            MongoDocumentPtr doc = documents[i]; 
            BsonTreeItem *child = new BsonTreeItem(doc->bsonObj(), _root);
            parseDocument(child, doc->bsonObj(), doc->bsonObj().isArray());

            QString idValue;
            BsonTreeItem *idItem = child->childByKey("_id");
            if (idItem) {
                idValue = idItem->value();
            }

            child->setKey(QString("(%1) %2").arg(i + 1).arg(idValue));

            int count = BsonUtils::elementsCount(doc->bsonObj());

            if (doc->bsonObj().isArray()) {
                child->setValue(arrayValue(count));
                child->setType(mongo::Array);
            } else {
                child->setValue(objectValue(count));
                child->setType(mongo::Object);
            }
            _root->addChild(child);
        }
    }
Exemplo n.º 2
0
void PrintHandler::startArray()
{
	arrayValue();
	_out << '[' << endLine();
	_tab.append(indent(), ' ');
	++_array;
	_objStart = true;
}
Exemplo n.º 3
0
void PrintHandler::startObject()
{
	arrayValue();
	_out << '{';
	_out << endLine();
	_tab.append(indent(), ' ');
	_objStart = true;
}
Exemplo n.º 4
0
void SuperastCPP::ensureSonIsArray() {
  if (!sonValue.IsArray()) {
    rapidjson::Value arrayValue(rapidjson::kArrayType);
    if (!sonValue.IsNull()) {
      arrayValue.PushBack(sonValue, allocator);
    }
    sonValue = arrayValue;
  }
}
Exemplo n.º 5
0
bool
WriteStructuredCloneImageData(JSContext* aCx, JSStructuredCloneWriter* aWriter,
                              ImageData* aImageData)
{
  uint32_t width = aImageData->Width();
  uint32_t height = aImageData->Height();
  JS::Rooted<JSObject*> dataArray(aCx, aImageData->GetDataObject());

  JSAutoCompartment ac(aCx, dataArray);
  JS::Rooted<JS::Value> arrayValue(aCx, JS::ObjectValue(*dataArray));
  return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) &&
         JS_WriteUint32Pair(aWriter, width, height) &&
         JS_WriteTypedArray(aWriter, arrayValue);
}
Exemplo n.º 6
0
// COMPOUND STATEMENTS, A block of statements in clangAST
bool SuperastCPP::TraverseCompoundStmt(clang::CompoundStmt* compoundStmt) {
  rapidjson::Value arrayValue(rapidjson::kArrayType);
  // Traverse each statement and append it to the array
  for (clang::Stmt* stmt : compoundStmt->body()) {
    TRY_TO(TraverseStmt(stmt));
    if (sonValue.IsArray()) {
      addElemsToArray(arrayValue, sonValue);
    }
    else {
      arrayValue.PushBack(sonValue, allocator);
    }
  }
  sonValue = arrayValue;
  return true;
}
Exemplo n.º 7
0
// DECLSTMT Allows mix of decl and statements
bool SuperastCPP::TraverseDeclStmt(clang::DeclStmt* declStmt) {
  if (declStmt->isSingleDecl()) {
    TRY_TO(TraverseDecl(declStmt->getSingleDecl()));
  }
  else {
    // Group of  declStmt
    rapidjson::Value arrayValue(rapidjson::kArrayType);
    const clang::DeclGroupRef declGroup = declStmt->getDeclGroup();
    for (auto iterator = declGroup.begin(); iterator != declGroup.end(); ++iterator) {
      TRY_TO(TraverseDecl(*iterator));
      arrayValue.PushBack(sonValue, allocator);
    }
    sonValue = arrayValue;
  }
  return true;
}
Exemplo n.º 8
0
// CXX CLASS MEMBER CALL, with dot operator ('.')
bool SuperastCPP::TraverseCXXMemberCallExpr(
    clang::CXXMemberCallExpr* memberCall) {
  // Method Decl
  clang::CXXMethodDecl* methodDecl = memberCall->getMethodDecl();
  // Implicit obj
  clang::Expr* objectExpr = memberCall->getImplicitObjectArgument();
  // If this is an implicitCast, get the subExpr
  if (clang::ImplicitCastExpr* implicitExpr = 
      llvm::dyn_cast<clang::ImplicitCastExpr>(objectExpr)) {
    objectExpr = implicitExpr->getSubExpr();
  }

  const std::string& methodName = methodDecl->getNameInfo().getAsString();
  //const clang::Type* type = methodDecl->getReturnType().getTypePtr();

  rapidjson::Value rightValue(rapidjson::kObjectType);
  addId(rightValue);
  addPos(rightValue, memberCall);
  rightValue.AddMember("type", "function-call", allocator);
  rightValue.AddMember("name",
                      rapidjson::Value().SetString(methodName.c_str(),
                                                   methodName.size(),
                                                   allocator),
                      allocator);

  // For each argument
  rapidjson::Value arrayValue(rapidjson::kArrayType);
  for (auto arg : memberCall->arguments()) {
    TRY_TO(TraverseStmt(arg));
    arrayValue.PushBack(sonValue, allocator);
  }
  rightValue.AddMember("arguments", arrayValue, allocator);

  // Uncomment to add the type
  //rightValue.AddMember("return-type", createTypeValue(type), allocator);
  
  TRY_TO(TraverseStmt(objectExpr));
  // Object from which the method is called
  rapidjson::Value memberCallValue = createBinOpValue(".", sonValue, rightValue);
  addPos(memberCallValue, memberCall);

  sonValue = memberCallValue;
  return true;
}
Exemplo n.º 9
0
int main(){

	int value = 1;
	std::cout << "before passValue " << value << "\n";
	passValue(value);
	std::cout << "after passValue " << value << "\n";
	
	int prime[5] = {2,3,5,7,11};
	std::cout << "before arrayValue " << prime[0] << " " << prime[1] << " " << prime[2] << " " << prime[3] << " " << prime[4] << "\n";
	arrayValue(prime);
	std::cout << "after arrayValue " << prime[0] << " " << prime[1] << " " << prime[2] << " " <<  prime[3] << " " << prime[4] << "\n";

	int dabba[5] = {1,2,3,4,5};
	int total = 0;
	for (int i=0; i<5; ++i){
		total = total + dabba[i];
	}
	std::cout << "total sum " << total << "\n";

	return 0;

}
Exemplo n.º 10
0
void PrintHandler::value(unsigned v)
{
	arrayValue();
	_out << v;
	_value = true;
}
Exemplo n.º 11
0
void PrintHandler::value(double d)
{
	arrayValue();
	_out << d;
	_objStart = false;
}
Exemplo n.º 12
0
void PrintHandler::value(const std::string& value)
{
	arrayValue();
	Stringifier::formatString(value, _out);
	_value = true;
}
Exemplo n.º 13
0
void PrintHandler::value(UInt64 v)
{
	arrayValue();
	_out << v;
	_value = true;
}
Exemplo n.º 14
0
bool SuperastCPP::TraverseCXXOperatorCallExpr(clang::CXXOperatorCallExpr* operatorCallExpr) {
  // IF THERE IS A PRINT
  auto decl = llvm::dyn_cast<clang::FunctionDecl>(operatorCallExpr->getCalleeDecl());
  if (!decl) {
    std::cerr << "Unknown function in CXXOperatorCallExpr" << std::endl;
    return true;
  }
  const std::string functionName = decl->getNameInfo().getAsString();
  if (functionName == PRINT_NAME || functionName == READ_NAME) {
    bool isFirst = false;
    if (!iofunctionStarted) {
      isFirst = true;
      iofunctionStarted = true;
    }

    rapidjson::Value arrayValue(rapidjson::kArrayType);
    for (unsigned i = 0; i < operatorCallExpr->getNumArgs(); ++i) {
      TRY_TO(TraverseStmt(operatorCallExpr->getArg(i)));
      if (i == 0) {
        // If sonValue is not an array, is because it reached the begin of
        // call, which is the cout/cerr/stream class
        if (sonValue.IsArray()) {
          arrayValue = sonValue;
        }
      }
      else {
        arrayValue.PushBack(sonValue, allocator);
      }
    }
    
    if (!isFirst) {
      sonValue = arrayValue;
    }
    else {
      iofunctionStarted = false;

      rapidjson::Value functionValue(rapidjson::kObjectType);
      addId(functionValue);
      addPos(functionValue, operatorCallExpr);
      functionValue.AddMember("type", "function-call", allocator);
      if (functionName == PRINT_NAME) 
        functionValue.AddMember("name", "print", allocator);
      else functionValue.AddMember("name", "read", allocator);
      functionValue.AddMember("arguments", arrayValue, allocator);
      sonValue = functionValue;
    }
  }
  else if (functionName == VECTOR_POS_NAME) {
    // Operator []
    TRY_TO(TraverseStmt(operatorCallExpr->getArg(0)));
    rapidjson::Value leftValue(rapidjson::kObjectType);
    leftValue = sonValue;
    TRY_TO(TraverseStmt(operatorCallExpr->getArg(1)));
    rapidjson::Value rightValue(rapidjson::kObjectType);
    rightValue = sonValue;
    sonValue = createBinOpValue("[]", leftValue, rightValue);
  }
  else {
    std::cerr << "Operator call not defined: " << functionName << std::endl;
  }
    return true;
}
Exemplo n.º 15
0
void PrintHandler::value(double d)
{
	arrayValue();
	_out << d;
	_value = true;
}
Exemplo n.º 16
0
void PrintHandler::null()
{
	arrayValue();
	_out << "null";
	_objStart = false;
}
Exemplo n.º 17
0
void PrintHandler::value(bool b)
{
	arrayValue();
	_out << b;
	_value = true;
}
Exemplo n.º 18
0
void PrintHandler::value(unsigned v)
{
	arrayValue();
	_out << v;
	_objStart = false;
}
Exemplo n.º 19
0
void PrintHandler::value(bool b)
{
	arrayValue();
	_out << b;
	_objStart = false;
}
Exemplo n.º 20
0
void PrintHandler::null()
{
	arrayValue();
	_out << "null";
	_value = true;
}
Exemplo n.º 21
0
void PrintHandler::value(const std::string& value)
{
	arrayValue();
	Stringifier::formatString(value, _out);
	_objStart = false;
}
Exemplo n.º 22
0
void PrintHandler::value(UInt64 v)
{
	arrayValue();
	_out << v;
	_objStart = false;
}