Esempio n. 1
0
template < class AttributeType > QString dumpIndexed ( AttributeContainer* container, QString name, int indent = 0 ) {
    QString result = "";
    result += indenter ( indent ) + name + " = [\n";
    for ( int i = 0 ; i < container->getSize < AttributeType > ( name ) ; i ++ )
        result += indenter ( indent + 1 ) + " - " + toString < AttributeType > ( container->get < AttributeType > ( name, i ), indent + 2 ) + "\n";
    result += indenter ( indent ) + "]\n";
    return result;
}
Esempio n. 2
0
bool ParseNamedDefinition::init(Parser& parser) {
  TraceIndenter indenter(parser, "definition:", &name_);

  if (!rule_) {
    parser.validationError() <<
      "Syntax rule " << name_  << " has not been defined.\n";
    return false;
  }

  ParseNamedDefinition* existingName = parser.findDefinition(name_);
  if (!existingName) {
    parser.validationError() <<
      "Syntax rule " << name_ << " is not defined in the parser.";
    return false;
  }
  if (existingName != this) {
    parser.validationError() <<
      "Syntax rule " << name_ << " is already defined.";
    return false;
  }

  // Push arguments onto stack.
  parser.abstractStack_.clear();
  for (unsigned i=0, n=argNames_.size(); i<n; ++i) {
    parser.abstractStack_.push_back(&argNames_[i]);
  }
  bool success = parser.initRule(rule_);

  if (parser.abstractStack_.size() != 1) {
    parser.validationError()
      << "A top-level named definition must return a result.";
  }
  return success;
}
Esempio n. 3
0
/* return code is the exit status of the pipe */
static int free_pipe(struct pipe *pi, int indent) {
	char **p;
	struct child_prog *child;
	int a, i, ret_code = 0;
	char *ind = indenter(indent);

	for (i = 0; i < pi->num_progs; i++) {
		child = &pi->progs[i];
		final_printf("%s  command %d:\n", ind, i);
		if (child->argv) {
			for (a = 0, p = child->argv; *p; a++, p++) {
				final_printf("%s   argv[%d] = %s\n", ind, a, *p);
			}
			for (a = child->argc; a >= 0; a--) {
				free(child->argv[a]);
			}
			free(child->argv);
			child->argc = 0;
			child->argv = NULL;
		} else if (child->group) {
			ret_code = free_pipe_list(child->group, indent + 3);
			final_printf("%s   end group\n", ind);
		} else {
			final_printf("%s   (nil)\n", ind);
		}
	}
	free(pi->progs); /* children are an array, they get freed all at once */
	pi->progs = NULL;
	return ret_code;
}
Esempio n. 4
0
bool ParseAction::init(Parser& parser) {
  TraceIndenter indenter(parser, "action");

  if (!node_) {
    parser.validationError() << "Invalid action.";
    return false;
  }

  // Argument indices are computed relative to the current stack frame.
  frameSize_ = parser.abstractStack_.size();

  // Actions which occur in a tail position are responsible for dropping
  // items off the stack.
  drop_ = parser.abstractStack_.localSize();

  ASTIndexVisitor visitor(&parser);
  bool success = visitor.traverse(node_);
  if (!success)
    return false;

  // Drop everything in the current lexical scope off of the abstract stack.
  parser.abstractStack_.rewind();

  // Actions will return a single value.
  parser.abstractStack_.push_back(nullptr);
  return true;
}
Esempio n. 5
0
QString dump ( Assets::GameEntityPtr cell, int indent = 0 )
{
    QString result = "";
    result += indenter ( indent ) + cell->getName() + " " + cell->getUUID().toString () + "\n";
    result += dump < QString > ( cell.data(), "_RealName", indent + 1 );
    result += dumpIndexed < QString > ( cell.data(), "Semantics", indent + 1 );
    result += dumpIndexed < Assets::GameEntityElement* > ( cell.data(), "Elements", indent + 1 );
    return result;
}
Esempio n. 6
0
////////// Init
OP_STATUS
UIReader::Init(const OpStringC8& node_name, const OpStringC& file_path, OpFileFolder folder, const OpStringC& logfile)
{
	if (logfile.HasContent())
	{
		RETURN_IF_ERROR(m_logger.Init(logfile));
		m_logger.StartLogging();
	}

	m_ui_document.SetLogger(&m_logger);
	RETURN_IF_ERROR(m_ui_document.Init(file_path, folder));

	ParserLogger::AutoIndenter indenter(m_logger, "Reading %s definitions into map", node_name);

	ParserNodeMapping node;
	if (!m_ui_document.GetRootNode(node))
	{
		m_logger.OutputEntry("ERROR: could not retrieve the document's root node");
		return OpStatus::OK;
	}

	// read first hash level: retrieve the '<node_name>' node
	ParserNodeSequence relevant_node;
	if (!node.GetChildNodeByID(node.FindValueForKey(node_name), relevant_node))
	{
		m_logger.OutputEntry("ERROR: document doesn't contain a '%s' top-level node", node_name);
		return OpStatus::OK;
	}
	// traverse all nodes under 'node_name', get their name
	// store name and YAML node ID in a hash
	for (ParserSequenceIterator it(relevant_node); it; ++it)
	{
		ParserNodeMapping ui_element;
		if (!m_ui_document.GetNodeByID(it.Get(), ui_element))
		{
			m_logger.OutputEntry("WARNING: Couldn't retrieve node in '%s' sequence. It is probably not of type 'MAPPING'. Ignoring entry.", node_name);
			continue;
		}
		ParserNodeScalar name_node;
		if (!ui_element.GetChildNodeByID(ui_element.FindValueForKey("name"), name_node))
		{
			m_logger.OutputEntry("ERROR: %s node doesn't have a child node called 'name'. Ignoring...", node_name);
			continue;
		}
		OpAutoPtr<ParserNodeIDTableData> data (OP_NEW(ParserNodeIDTableData, (it.Get())));
		RETURN_OOM_IF_NULL(data.get());

		RETURN_IF_ERROR(m_logger.Evaluate(name_node.GetString(data->key), "ERROR retrieving string from name node"));
		RETURN_IF_ERROR(m_ui_element_hash.Add(data->key.CStr(), data.get()));
		m_logger.OutputEntry("Read '%s'", data->key);
		data.release();
	}
	
	indenter.Done();

	return OpStatus::OK;
}
Esempio n. 7
0
void Immediate::repr(int indentlevel){
	std::string indenter(indentlevel, '\t');
	clog << indenter << "<Immediate>" << endl;
	if (m_data.size() == 0)
		clog << indenter << "\t<value>uninitialized</value>"<<endl;	
	else
		clog << indenter << "\t<value>" << hex2str(&m_data[0], m_data.size()) << "</value>"<< endl;
//		clog << indenter << "\t<accessmode>" << accessmodeLUT[(uint8_t)Operand::getAccessMode() >> 2] << "</accessmode>" <<  endl;
	clog << indenter << "</Immediate>" << endl;
}
Esempio n. 8
0
bool ParseNone::init(Parser& parser) {
  TraceIndenter indenter(parser, "none");

  // None doesn't know how to unwind the stack.
  if (parser.abstractStack_.lexicalSize() > 0) {
    parser.validationError() << "Sequence cannot end with none.";
    return false;
  }
  return true;
}
Esempio n. 9
0
QString dump ( Assets::SpawnPoint* spawn, int indent )
{
    QString result = "";
    result += indenter ( indent ) + spawn->getName() + "\n";
    result += dump < QString > ( spawn, "_RealName", indent + 1 );
    result += dump < QUuid > ( spawn, "World", indent + 1 );
    result += dump < Vector3d > ( spawn, "Location", indent + 1 );
    result += dump < float > ( spawn, "Size", indent + 1 );
    result += dumpIndexed < QString > ( spawn, "Semantics", indent + 1 );
    return result;
}
Esempio n. 10
0
QString dump ( Assets::WorldPtr world, int indent = 0 )
{
    QString result = "";
    result += indenter ( indent ) + world->getName() + " " + world->getUUID().toString () + "\n";
    result += dump < QString > ( world.data(), "_RealName", indent + 1 );
    result += dump < Vector3d > ( world.data(), "Extents", indent + 1 );
    result += dump < Vector2ui > ( world.data(), "Subdivision", indent + 1 );
    result += dumpIndexed < Assets::SpawnPoint* > ( world.data(), "SpawnPoints", indent + 1 );
    result += dumpIndexed < QString > ( world.data(), "Semantics", indent + 1 );
    result += dumpIndexed < QUuid > ( world.data(), "Cells", indent + 1 );
    return result;
}
Esempio n. 11
0
QString dump ( Assets::WorldCellPtr cell, int indent = 0 )
{
    QString result = "";
    result += indenter ( indent ) + cell->getName() + " " + cell->getUUID().toString () + "\n";
    result += dump < QString > ( cell.data(), "_RealName", indent + 1 );
    result += dump < QUuid > ( cell.data(), "World", indent + 1 );
    result += dump < Vector2ui > ( cell.data(), "Indices", indent + 1 );
    result += dump < Vector3d > ( cell.data(), "Extents", indent + 1 );
    result += dump < Vector3d > ( cell.data(), "Position", indent + 1 );
    result += dumpIndexed < QUuid > ( cell.data(), "GameObjects", indent + 1 );
    return result;
}
Esempio n. 12
0
int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
    QTextBlock block = cursor.block();
    const QString text = block.text().trimmed();
    if (text == "end"
            || text == "else"
            || text.startsWith("elsif")
            || text.startsWith("rescue")
            || text == "ensure") {
        Indenter indenter(const_cast<QTextDocument*>(block.document()));
        indenter.indentBlock(block, QChar(), tabSettings());
    }

    return 0;
    // This implementation is buggy
#if 0
    const QString textFromCursor = text.mid(cursor.positionInBlock()).trimmed();
    if (!textFromCursor.isEmpty())
        return 0;

    if (Language::symbolDefinition.indexIn(text) == -1
            && Language::startOfBlock.indexIn(text) == -1) {
        return 0;
    }

    int spaces = 0;
    for (const QChar c : text) {
        if (!c.isSpace())
            break;
        spaces++;
    }
    QString indent = text.left(spaces);

    QString line;
    QTextBlock nextBlock = block.next();
    while (nextBlock.isValid()) {
        line = nextBlock.text();
        if (Language::endKeyword.indexIn(line) != -1 && line.startsWith(indent))
            return 0;
        if (!line.trimmed().isEmpty())
            break;
        nextBlock = nextBlock.next();
    }

    int pos = cursor.position();
    cursor.insertBlock();
    cursor.insertText("end");
    cursor.setPosition(pos);

    return 1;
#endif
}
Esempio n. 13
0
QString dump ( Assets::GameEntityElement* elt, int indent )
{
    QString result = "";
    result += indenter ( indent ) + elt->getName() + "\n";
    //result += dump < QString > ( elt, "_RealName", indent + 1 );
    result += dump < QUuid > ( elt, "Entity", indent + 1 );
    result += dump < Vector3d > ( elt, "Position", indent + 1 );
    result += dump < Vector4d > ( elt, "Rotation", indent + 1 );
    result += dump < Vector3d > ( elt, "Scale", indent + 1 );
    result += dumpIndexed < QString > ( elt, "Semantics", indent + 1 );
    result += dumpIndexed < QUuid > ( elt, "Resources", indent + 1 );
    return result;
}
Esempio n. 14
0
QString dump ( Assets::GameObjectPtr cell, int indent = 0 )
{
    QString result = "";
    result += indenter ( indent ) + cell->getName() + " " + cell->getUUID().toString () + "\n";
    result += dump < QString > ( cell.data(), "_RealName", indent + 1 );
    result += dump < QUuid > ( cell.data(), "Cell", indent + 1 );
    result += dump < Vector3d > ( cell.data(), "Position", indent + 1 );
    result += dump < Vector4d > ( cell.data(), "Rotation", indent + 1 );
    result += dump < Vector3d > ( cell.data(), "Scale", indent + 1 );
    result += dump < QUuid > ( cell.data(), "Entity", indent + 1 );
    result += dumpIndexed < QString > ( cell.data(), "Semantics", indent + 1 );
    return result;
}
Esempio n. 15
0
static int free_pipe_list(struct pipe *head, int indent) {
	int rcode = 0; /* if list has no members */
	struct pipe *pi, *next;
	char *ind = indenter(indent);
	for (pi = head; pi; pi = next) {
		final_printf("%s pipe reserved mode %d\n", ind, pi->r_mode);
		rcode = free_pipe(pi, indent);
		final_printf("%s pipe followup code %d\n", ind, pi->followup);
		next = pi->next;
		pi->next = NULL;
		free(pi);
	}
	return rcode;
}
Esempio n. 16
0
bool ParseToken::init(Parser& parser) {
  TraceIndenter indenter(parser, "token");

  // Tokens don't know how to unwind the stack.
  if (parser.abstractStack_.lexicalSize() > 0) {
    parser.validationError() << "Sequence cannot end with a token.";
    return false;
  }

  if (skip_)
    return true;

  parser.abstractStack_.push_back(nullptr);
  return true;
}
Esempio n. 17
0
void Module::codegenMethodTable(std::ostream &out) const
{
	out << "static PyMethodDef methods[] = {\n";
	{
		IndentingOStreambuf indenter(out);
		for(const auto &e : exports())
		{
			e->codegenMethodTable(out);
		}

		out << "{0, 0, 0, 0}\n";
	}

	out << "};\n";
}
Esempio n. 18
0
bool ParseReference::init(Parser& parser) {
  TraceIndenter indenter(parser, "reference:", &name_);

  ParseNamedDefinition* def = parser.findDefinition(name_);
  if (!def) {
    parser.validationError() << "No syntax definition for " << name_;
    return false;
  }
  if (!definition_) {
    definition_ = def;
  } else if (definition_ != def) {
    parser.validationError() << "Inconsistent definitions for " << name_;
    return false;
  }

  // Calculate indices for named arguments.
  for (auto &name : argNames_) {
    unsigned idx = parser.abstractStack_.getIndex(name);
    if (idx == AbstractStack::InvalidIndex) {
      parser.validationError() << "Identifier " << name << " not found.";
      return false;
    }
    arguments_.push_back(idx);
  }

  if (arguments_.size() != definition_->numArguments()) {
    parser.validationError() <<
      "Reference to " << name_ << " has the wrong number of arguments.";
    return false;
  }

  // Argument indices are computed relative to the current stack frame.
  frameSize_ = parser.abstractStack_.size();

  // Calls which occur in a tail position are responsible for dropping items
  // off of the stack.
  drop_ = parser.abstractStack_.localSize();

  // Drop everything in the lexical scope off of the abstract stack.
  parser.abstractStack_.rewind();

  // Top-level rules must return a single value.
  parser.abstractStack_.push_back(nullptr);

  return true;
}
Esempio n. 19
0
void Module::codegenModuleDef(std::ostream &out) const 
{
	out << "static struct PyModuleDef module = {\n";
	{
		IndentingOStreambuf indenter(out);

		auto docstring = processDocString(_docstring);

		out  
			<< "PyModuleDef_HEAD_INIT,\n"
			<< "\"" << name() << "\",\n"
			<< "\"" << docstring << "\",\n"
			<< "-1,\n"
			<< "methods\n";
	}
	out << "};\n";
}
Esempio n. 20
0
	void expand(std::ostream &os, const ITemplateNamespace &ns) const
	{

		auto replacer = [&](const regex::smatch &m) {

			bool needsIndent = true;
			int index = m.position() - 1;
			for(; index >= 0; --index)
			{
				if(_fmt[index] == '\n') 
				{
					break;
				}
				else if(!std::isspace(_fmt[index]))
				{
					needsIndent = false;
					break;
				}
			}

			++index;

			std::stringstream ss;

			if(needsIndent && index != m.position())
			{
				IndentingOStreambuf indenter(ss, std::string(_fmt.begin() + index, _fmt.begin() + m.position()), false);
				ns.get(m[1]).write(ss);
			}
			else
			{
				ns.get(m[1]).write(ss);
			}

			return ss.str();
		};

		auto s = regex_replace(_fmt,
		                       templateRegex,
		                       replacer);


		os << s;

	}
Esempio n. 21
0
bool ParseRecurseLeft::init(Parser& parser) {
  TraceIndenter indenter(parser, "recurseLeft");

  if (!base_ || !rest_) {
    parser.validationError() << "Invalid recursive rule.";
  }

  // base_ is parsed in its own local block, so any actions at the end which
  // rewind the stack will only rewind to this point.
  unsigned localblock = parser.abstractStack_.enterLocalBlock();
  bool success = parser.initRule(base_);
  if (!success)
    return false;

  unsigned nvals = parser.abstractStack_.localSize();
  if (nvals > 1) {
    parser.validationError() << "Rule cannot return more than one value.";
    return false;
  }

  if (hasLetName()) {
    if (nvals == 1) {
      unsigned back = parser.abstractStack_.size()-1;
      parser.abstractStack_[back] = &letName_;
    }
    else {
      parser.validationError() << "Named subrule '" << letName_
        << "does not return a value.";
      return false;
    }
  }

  success = parser.initRule(rest_);
  if (!success)
    return false;

  if (parser.abstractStack_.localSize() != nvals) {
    parser.validationError() << "Recursion returns wrong number of values.";
    return false;
  }
  parser.abstractStack_.exitLocalBlock(localblock);

  return success;
}
Esempio n. 22
0
void Module::codegenInit(std::ostream &out) const
{
	out
		<< "PyMODINIT_FUNC PyInit_" << name() << "()\n"
		<< "{\n"
		<< "    PyObject *mod = PyModule_Create(&module);\n"
		<< "    if(!mod) return 0;\n";


	{
		IndentingOStreambuf indenter(out);
		for(const auto &e : exports())
		{
			e->codegenInit(out);
		}
	}


	out << "    return mod;\n}\n";
}
Esempio n. 23
0
bool SettingsFileWriter::write(
    const char*         filename,
    const Dictionary&   settings)
{
    FILE* file = fopen(filename, "wt");

    if (!file)
        return false;

    fprintf(file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    fprintf(file, "<settings>\n");

    Indenter indenter(4);
    write_dictionary(file, indenter, settings);

    fprintf(file, "</settings>\n");
    fclose(file);

    return true;
}
Esempio n. 24
0
bool ParseKeyword::init(Parser& parser) {
  TraceIndenter indenter(parser, "keyword");

  if (keywordStr_.length() == 0) {
    parser.validationError() << "Invalid keyword.";
    return false;
  }
  tokenID_ = parser.registerKeyword(keywordStr_);
  if (parser.traceValidate_) {
    parser.indent(std::cerr, parser.traceIndent_);
    std::cout << "-- registered keyword " << keywordStr_ << " as "
      << tokenID_ << "\n";
  }

  // Keywords don't know how to unwind the stack.
  if (parser.abstractStack_.lexicalSize() > 0) {
    parser.validationError() << "Sequence cannot end with keyword.";
    return false;
  }
  return true;
}
Esempio n. 25
0
bool ParseOption::init(Parser& parser) {
  TraceIndenter indenter(parser, "option");

  if (!left_ || !right_) {
    parser.validationError() << "Invalid option.";
    return false;
  }

  // Enter a new lexical scope.  Stack rewinds will only rewind back to
  // this point.
  unsigned scope = parser.abstractStack_.enterLexicalScope();

  bool success = parser.initRule(left_);
  if (!success)
    return false;
  unsigned leftSz = parser.abstractStack_.lexicalSize();

  parser.abstractStack_.rewind();
  success = parser.initRule(right_);
  if (!success)
    return false;
  unsigned rightSz = parser.abstractStack_.lexicalSize();

  parser.abstractStack_.exitLexicalScope(scope);

  if (leftSz != rightSz) {
    parser.validationError() <<
      "Different options must return the same number of results: " <<
      leftSz << "," << rightSz;
    return false;
  }

  // left and right have both rewound to here; we need to rewind to our caller.
  parser.abstractStack_.rewind();
  for (unsigned i=0; i < rightSz; ++i)
    parser.abstractStack_.push_back(0);
  return success;
}
Esempio n. 26
0
bool SettingsFileWriter::write(
    const char*         filename,
    const Dictionary&   settings)
{
    FILE* file = fopen(filename, "wt");

    if (!file)
        return false;

    fprintf(file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

    Indenter indenter(4);

    XMLElement settings_element("settings", file, indenter);
    settings_element.write(true);

    write_dictionary(settings, file, indenter);

    settings_element.close();

    fclose(file);

    return true;
}
Esempio n. 27
0
bool ParseSequence::init(Parser& parser) {
  TraceIndenter indenter(parser, "sequence");

  if (!first_ || !second_) {
    parser.validationError() << "Invalid sequence.";
    return false;
  }

  // first_ is parsed in its own local block, so any actions at the end which
  // rewind the stack will only rewind to this point.
  unsigned localblock = parser.abstractStack_.enterLocalBlock();
  bool success = parser.initRule(first_);
  if (!success)
    return false;

  unsigned nvals = parser.abstractStack_.localSize();
  if (nvals > 1) {
    parser.validationError() << "Rule cannot return more than one value.";
    return false;
  }
  parser.abstractStack_.exitLocalBlock(localblock);

  if (hasLetName()) {
    if (nvals == 1) {
      unsigned back = parser.abstractStack_.size()-1;
      parser.abstractStack_[back] = &letName_;
    }
    else {
      parser.validationError() << "Named subrule '" << letName_
        << "does not return a value.";
      return false;
    }
  }
  success = parser.initRule(second_);
  return success;
}
Esempio n. 28
0
template < class AttributeType > QString dump ( AttributeContainer* container, QString name, int indent = 0 ) {
    QString result = "";
    result += indenter ( indent ) + name + " = [" + toString ( container->get < AttributeType > ( name ), indent + 1 ) + "]\n";
    return result;
}