Skip to content

Commit

Permalink
release R2101
Browse files Browse the repository at this point in the history
  • Loading branch information
maierkomor committed Jan 31, 2021
1 parent ac967d3 commit 0ba3902
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .hg_archival.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
repo: 74e97a8352b0714d95edee6a4e88879188f84695
node: a2d2aa9abec9dc3cd59e7e5649c1d49829674352
node: e4ffcdf1b68d181b4fd4053628f0039dd190aba7
branch: default
tag: R2012
tag: R2101
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#
# Copyright (C) 2020-2021, Thomas Maier-Komor
#
# This file belongs to Wire-Format-Compiler.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

cmake_minimum_required(VERSION 3.8.0)
project(wfc)

# version determination

Expand Down
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release R2101:
==============
- enhancement: support option used for messages
- fix: obsolete field handling with early decoding
- fix: yacc deprecation warning

Release R2012:
==============
- fix: usage=obsolete produces uncompilable code
Expand Down
6 changes: 3 additions & 3 deletions src/CodeGenerator.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2019, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -113,10 +113,10 @@ CodeGeneratorImpl::~CodeGeneratorImpl()
}


void CodeGenerator::init(const vector<string> &msgs)
void CodeGenerator::init()
{
assert(impl);
impl->init(msgs);
impl->init();
}


Expand Down
6 changes: 3 additions & 3 deletions src/CodeGenerator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2019, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -31,7 +31,7 @@ class CodeGeneratorImpl
{
public:
virtual ~CodeGeneratorImpl();
virtual void init(const std::vector<std::string> &) = 0;
virtual void init() = 0;
virtual void writeFiles(const char *basename = 0) = 0;
virtual void writeLib() = 0;
virtual void setTarget(const char *target) = 0;
Expand All @@ -48,7 +48,7 @@ class CodeGenerator
public:
CodeGenerator(PBFile *, Options *);

void init(const std::vector<std::string> &);
void init();
void writeFiles(const char *basename);
void writeLib(const char *basename = 0);
void setTarget(const char *);
Expand Down
62 changes: 30 additions & 32 deletions src/CppGenerator.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -237,10 +237,10 @@ void CppGenerator::applyNodeOption(const char *nodepath, KVPair *kvp)
if (nodepath[0] != '/')
error("invalid node path '%s'",nodepath);
const char *node = nodepath+1;
Message *m = 0;
const char *slash = strchr(node,'/');
while (slash) {
string msgname(node,slash);
Message *m = 0; // needed for '/message' case
do {
string msgname(node,slash?slash-node:strlen(node));
diag("appyNodeOption: msg %s",msgname.c_str());
if (m) {
m = m->getMessage(msgname.c_str());
Expand All @@ -251,25 +251,23 @@ void CppGenerator::applyNodeOption(const char *nodepath, KVPair *kvp)
warn("Ignoring unknwon message '%s' in nodepath '%s'",msgname.c_str(),nodepath);
return;
}
node = slash+1;
slash = strchr(slash+1,'/');
}
Enum *e = m ? m->getEnum(node) : file->getEnum(node);
if (e) {
if (slash) {
node = slash+1;
slash = strchr(slash+1,'/');
}
} while (slash);

if (Enum *e = m ? m->getEnum(node) : file->getEnum(node)) {
diag("appyNodeOption: enum %s",node);
e->setOption(kvp->getKey(),kvp->getValue());
return;
}
if ((m == 0) && (e == 0)) {
warn("Unable to resolve node path %s. Ignoring option %s",nodepath,kvp->getKey().c_str());
return;
}
if (Field *f = m->getField(node)) {
} else if (m == 0) {
warn("Unable to resolve node path %s. Ignoring option '%s'.",nodepath,kvp->getKey().c_str());
} else if (Field *f = m->getField(node)) {
diag("appyNodeOption: field %s",node);
f->setOption(kvp->getKey(),kvp->getValue());
return;
} else {
m->setOption(kvp->getKey().c_str(),kvp->getValue().c_str());
}
warn("Ignoring unknwon node '%s' in nodepath '%s'",node,nodepath);
}


Expand Down Expand Up @@ -460,27 +458,18 @@ void CppGenerator::initVBits(Message *m)
}


void CppGenerator::init(const vector<string> &msgs)
void CppGenerator::init()
{
bool all = msgs.empty();
usesArrays = false;
usesVectors = false;
usesBytes = false;
usesStringTypes = false;
for (unsigned i = 0, n = file->numMessages(); i != n; ++i) {
Message *m = file->getMessage(i);
m->setUsed(all);
m->setOptions(target);
initVBits(m);
initNames(m,"");
}
for (auto i = msgs.begin(), e = msgs.end(); i != e; ++i) {
const char *name = i->c_str();
if (Message *m = file->getMessage(name))
m->setUsed(true);
else
error("unable to select message %s for code generation: no such message",name);
}
}


Expand Down Expand Up @@ -1233,6 +1222,14 @@ void CppGenerator::writeStaticMembers(Generator &G, Message *m)

void CppGenerator::writeClass(Generator &G, Message *m)
{
if (!m->getGenerate()) {
G.setMessage(m);
if (m->isUsed())
error("message %s is subpressed for generation, but is used",m->getName().c_str());
G << "// message $msg_name is not used\n";
G.setMessage(0);
return;
}
if (!SubClasses) {
for (unsigned i = 0, e = m->numEnums(); i != e; ++i) {
Enum *en = m->getEnum(i);
Expand Down Expand Up @@ -1520,7 +1517,7 @@ void CppGenerator::writeHeader(const string &bn)
}
for (unsigned i = 0, n = file->numMessages(); i != n; ++i) {
Message *m = file->getMessage(i);
if (m->isUsed())
if (m->isUsed() || m->getGenerate())
writeClass(G,m);
}
if (target->getOption("wfclib") != "extern") {
Expand All @@ -1532,7 +1529,7 @@ void CppGenerator::writeHeader(const string &bn)
if (inlineGet || inlineHas || inlineClear || inlineSet || inlineSize || SinkToTemplate) {
for (unsigned i = 0, n = file->numMessages(); i != n; ++i) {
Message *m = file->getMessage(i);
if (m->isUsed())
if (m->isUsed() || m->getGenerate())
writeInlines(G,m);
}
}
Expand Down Expand Up @@ -3953,6 +3950,8 @@ void CppGenerator::writeConstructor(Generator &G, Message *m)

void CppGenerator::writeFunctions(Generator &G, Message *m)
{
if (!m->getGenerate() && !m->isUsed())
return;
G.setMessage(m);
writeStaticMembers(G,m);
writeConstructor(G,m);
Expand Down Expand Up @@ -4265,7 +4264,7 @@ void CppGenerator::writeBody(const string &bn)
writeEnumDefs(G,e);
for (unsigned i = 0, n = file->numMessages(); i != n; ++i) {
Message *m = file->getMessage(i);
if (m->isUsed())
if (m->isUsed()||m->getGenerate())
writeFunctions(G,m);
}
if (!ns.empty())
Expand All @@ -4280,7 +4279,6 @@ void CppGenerator::writeFromMemory_early(Generator &G, Field *f)
uint32_t id = f->getId();
if (!f->isUsed() || f->isObsolete()) {
G << "case $(field_tag):\t// $(fname) id $(field_id), type $typestr\n";
writeSkipContent(G,f->getEncoding());
G.setField(0);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/CppGenerator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -37,7 +37,7 @@ class CppGenerator : public CodeGeneratorImpl
public:
CppGenerator(PBFile *p, Options *);

void init(const std::vector<std::string> &);
void init();
void setTarget(const char *t = "");
void writeLib();
void writeFiles(const char * = 0);
Expand Down
37 changes: 37 additions & 0 deletions src/Message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Message::Message(const char *n, unsigned l, bool o)
, m_maxfid(0)
, m_numvalid(0)
, m_used(false)
, m_generate(false)
, m_storage(mem_regular)
, m_sorting(sort_unset)
{
Expand Down Expand Up @@ -189,6 +190,17 @@ void Message::setOption(const char *option, const char *value)
m_sorting = sort_none;
else
error("invalid sorting type %s",value);
} else if (!strcmp(option,"used")) {
if (!strcmp(value,"false"))
m_generate = false;
else if (!strcmp(value,"true"))
m_generate = true;
else if (!strcmp(value,"yes"))
m_generate = true;
else if (!strcmp(value,"no"))
m_generate = false;
else
error("invalid argument %s for message option 'used'",value);
} else {
error("invalid message option '%s'",option);
}
Expand Down Expand Up @@ -392,8 +404,33 @@ void Message::setOptions(Options *o)
}


void Message::setGenerate(bool g)
{
m_generate = g;
if (g) {
for (auto i(m_fields.begin()), e(m_fields.end()); i != e; ++i) {
Field *f = i->second;
if ((f == 0) || (!f->isUsed()))
continue;
unsigned type = f->getType();
if (ft_msg != (type & ft_filter))
continue;
Message *sm = Message::id2msg(type);
if (sm != this)
sm->setGenerate(true);
}
} else {
for (size_t i = 0, n = m_msgs.size(); i != n; ++i) {
m_msgs[i]->setGenerate(false);
}
}
}


void Message::setUsed(bool u)
{
if (u && !m_generate)
warn("message %s is used but requested to be suppressed during generation",m_name.c_str());
m_used = u;
if (u) {
for (auto i(m_fields.begin()), e(m_fields.end()); i != e; ++i) {
Expand Down
10 changes: 8 additions & 2 deletions src/Message.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -45,6 +45,7 @@ class Message
, m_maxfid(0)
, m_numvalid(0)
, m_used(false)
, m_generate(false)
, m_storage(mem_regular)
, m_sorting(sort_unset)
{ }
Expand Down Expand Up @@ -130,6 +131,11 @@ class Message
bool isUsed() const
{ return m_used; }

bool getGenerate() const
{ return m_generate; }

void setGenerate(bool g);

mem_inst_t getStorage() const
{ return m_storage; }

Expand All @@ -153,7 +159,7 @@ class Message
std::vector<Enum*> m_enums;
std::vector<unsigned> m_fieldseq;
std::vector< std::pair<unsigned,unsigned> > m_reservations;
bool m_used;
bool m_used, m_generate; // m_used is calculated by dependencies, m_generate is option/command-line setting
mem_inst_t m_storage;
msg_sorting_t m_sorting;
};
Expand Down
17 changes: 2 additions & 15 deletions src/XmlGenerator.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2018, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -44,21 +44,8 @@ XmlGenerator::XmlGenerator(class PBFile *f, class Options *o)
}


void XmlGenerator::init(const vector<string> &msgs)
void XmlGenerator::init()
{
bool all = msgs.empty();
for (unsigned i = 0, n = file->numMessages(); i != n; ++i) {
Message *m = file->getMessage(i);
m->setUsed(all);
}
for (auto i = msgs.begin(), e = msgs.end(); i != e; ++i) {
const char *name = i->c_str();
if (Message *m = file->getMessage(name))
m->setUsed(true);
else
error("unable to select message %s for code generation: no such message",name);
}

}

void XmlGenerator::setTarget(const char *target)
Expand Down
4 changes: 2 additions & 2 deletions src/XmlGenerator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2019, Thomas Maier-Komor
* Copyright (C) 2017-2021, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -28,7 +28,7 @@ class XmlGenerator : public CodeGeneratorImpl
{
public:
XmlGenerator(class PBFile *, class Options *);
void init(const std::vector<std::string> &);
void init();
void writeFiles(const char *basename = 0);
void writeLib();
void setTarget(const char *target);
Expand Down
Loading

0 comments on commit 0ba3902

Please sign in to comment.