Beispiel #1
0
clutl::JSONError clutl::LoadJSON(clutl::JSONContext& ctx, void* object, const clcpp::Field* field)
{
	SetupTypeDispatchLUT();
	clutl::JSONToken t = LexerNextToken(ctx);
	ParserValue(ctx, t, (char*)object, field->type, field->qualifier.op, field);
	return ctx.GetError();
}
Beispiel #2
0
clutl::JSONError clutl::LoadJSON(ReadBuffer& in, void* object, const clcpp::Type* type)
{
	SetupTypeDispatchLUT();
	clutl::JSONContext ctx(in);
	clutl::JSONToken t = LexerNextToken(ctx);
	ParserObject(ctx, t, (char*)object, type);
	return ctx.GetError();
}
Beispiel #3
0
static bool CountTokens(const char *json, int *num_p) {
  LexerT lexer;
  TokenT token;

  LexerInit(&lexer, json);

  (*num_p) = 0;

  while (LexerNextToken(&lexer, &token))
    (*num_p)++;

  if (lexer.pos < lexer.end) {
    LOG("Error: %s at position %d.",
        lexer.errmsg, (int)(lexer.end - lexer.start));
    return false;
  }

  LOG("Read %d tokens.", (*num_p));
  return true;
}
bool clutl::BuildParameterObjectCache_JSON(clutl::ParameterObjectCache& poc, const clcpp::Function* function, clutl::ReadBuffer& parameter_source)
{
	// Reuse the incoming cache
	poc.Init(function);

	// A local cache of all function parameters in their sorted order
	const clcpp::Field* sorted_fields[ParameterData::MAX_NB_FIELDS];

	// Sort each parameter into its call order
	unsigned int nb_fields = function->parameters.size;
	for (unsigned int i = 0; i < nb_fields; i++)
	{
		const clcpp::Field* field = function->parameters[i];
		clcpp::internal::Assert(field->offset < ParameterData::MAX_NB_FIELDS);
		sorted_fields[field->offset] = field;
	}

	// Check for parameter opening list
	JSONContext ctx(parameter_source);
	JSONToken t = LexerNextToken(ctx);
	if (t.type != JSON_TOKEN_LBRACKET)
		return false;

	// Allocate parameters for each field
	for (unsigned i = 0; i < nb_fields; i++)
	{
		const clcpp::Field* field = sorted_fields[i];
		void* param_object = poc.AllocParameter(field);

		// Parse the JSON parameter and move onto the next one
		JSONError error = LoadJSON(ctx, param_object, field);
		if (error.code != clutl::JSONError::NONE)
			return false;
	}

	// TODO: What about patching up pointers?

	return true;
}
Beispiel #5
0
static TokenT *ReadTokens(const char *json, int num) {
  LexerT lexer;
  TokenT *tokens = NULL;
  int i;

  LexerInit(&lexer, json);

  if ((tokens = NewTable(TokenT, num))) {
    LexerInit(&lexer, json);

    for (i = 0; i < num; i++) {
      LexerNextToken(&lexer, &tokens[i]);
#ifdef DEBUG_LEXER
      printf("%4d: ", i);
      TokenPrint(&tokens[i]);
#endif
    }

    TokenAssignParents(tokens, num);
  }

  return tokens;
}