From e0af585ed57bdb5b1ea4f4a415fda13b5d99d2dc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 1 Aug 2012 18:52:25 +0300 Subject: [PATCH] Use negative integers for built-in statements for better extensibility --- source/binaryparser.cpp | 8 ++++---- source/binaryparser.h | 2 +- source/binarywriter.cpp | 8 ++++---- source/binarywriter.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index 5313128..81a86ea 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -24,8 +24,8 @@ BinaryParser::BinaryParser(Input &i, const string &s): ParserMode(i, s), first(true) { - dict[1] = DictEntry("__kwd", "iss"); - dict[2] = DictEntry("__str", "is"); + dict[-1] = DictEntry("__kwd", "iss"); + dict[-2] = DictEntry("__str", "is"); } Statement BinaryParser::parse() @@ -38,7 +38,7 @@ Statement BinaryParser::parse() if(st.args.size()!=3) throw bad_definition("__kwd"); - const unsigned id = st.args[0].get(); + const int id = st.args[0].get(); const string &kw = st.args[1].get(); const string &args = st.args[2].get(); dict[id] = DictEntry(kw, args); @@ -62,7 +62,7 @@ Statement BinaryParser::parse_statement() in.get(); first = false; - unsigned id = parse_int(); + int id = parse_int(); if(!in) return Statement(); diff --git a/source/binaryparser.h b/source/binaryparser.h index f9b8e54..b10d7b8 100644 --- a/source/binaryparser.h +++ b/source/binaryparser.h @@ -15,7 +15,7 @@ Parses data in binary format. class BinaryParser: public ParserMode { private: - typedef std::map Dictionary; + typedef std::map Dictionary; typedef std::map StringMap; Dictionary dict; diff --git a/source/binarywriter.cpp b/source/binarywriter.cpp index c1e53fb..9c9c893 100644 --- a/source/binarywriter.cpp +++ b/source/binarywriter.cpp @@ -9,11 +9,11 @@ namespace DataFile { BinaryWriter::BinaryWriter(IO::Base &o): WriterMode(o), - next_kwd_id(3), + next_kwd_id(1), next_str_id(1) { - dict[DictEntry("__kwd", "iss")] = 1; - dict[DictEntry("__str", "is")] = 2; + dict[DictEntry("__kwd", "iss")] = -1; + dict[DictEntry("__str", "is")] = -2; } void BinaryWriter::write(const Statement &st) @@ -24,7 +24,7 @@ void BinaryWriter::write(const Statement &st) void BinaryWriter::write_(const Statement &st) { - unsigned id = get_item(dict, DictEntry(st.keyword, st.get_signature())); + int id = get_item(dict, DictEntry(st.keyword, st.get_signature())); write_int(id); for(Statement::Arguments::const_iterator j = st.args.begin(); j!=st.args.end(); ++j) diff --git a/source/binarywriter.h b/source/binarywriter.h index 4d18196..1a11ae5 100644 --- a/source/binarywriter.h +++ b/source/binarywriter.h @@ -15,7 +15,7 @@ Writes data in binary format. class BinaryWriter: public WriterMode { private: - typedef std::map Dictionary; + typedef std::map Dictionary; typedef std::map StringMap; Dictionary dict; -- 2.43.0