Skip to content

Commit

Permalink
release R2012
Browse files Browse the repository at this point in the history
  • Loading branch information
maierkomor committed Jan 1, 2021
1 parent f16bb68 commit ac967d3
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 83 deletions.
4 changes: 4 additions & 0 deletions .hg_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
repo: 74e97a8352b0714d95edee6a4e88879188f84695
node: a2d2aa9abec9dc3cd59e7e5649c1d49829674352
branch: default
tag: R2012
25 changes: 0 additions & 25 deletions .hgignore

This file was deleted.

13 changes: 0 additions & 13 deletions .hgtags

This file was deleted.

5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Release R2012:
==============
- fix: usage=obsolete produces uncompilable code
- fix: resolved compile issues related to array.h

Release R2011:
==============
- enhancement: AString should be suitable for bytes type
Expand Down
149 changes: 118 additions & 31 deletions include/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
#include <stdint.h>
#include <string.h>

#include <type_traits>

#ifdef __AVR__
typedef uint16_t size_t;
typedef int16_t ssize_t;
#endif

template <typename T, size_t maxsize>
class array;

template <typename T,size_t arraysize>
bool operator != (const array<T,arraysize> &l, const array<T,arraysize> &r);

template <typename T, size_t maxsize>
template <typename T, size_t maxsize, bool pod = std::is_trivially_copyable<T>::value>
class array
{
public:
Expand Down Expand Up @@ -114,43 +110,134 @@ class array
bool empty() const
{ return n == 0; }

public:
void erase(T *x)
{
int i = x - data;
assert((i >= 0) & (i < n));
if (std::is_trivial<T>::value) {
memmove(data+i,data+i+1,sizeof(T)*(n-i-1));
} else {
while (i+1 < n) {
data[i] = data[i+1];
++i;
}
size_t i = x - data;
assert(i < n);
while (i+1 < n) {
data[i] = data[i+1];
++i;
}
--n;
}

bool operator != (const array &r) const
{
if (n != r.n)
return true;
for (size_t i = 0; i < n; ++i) {
if (data[i] != r.data[i])
return true;
}
return false;
}

private:
size_t n;
T data[maxsize];

friend bool operator != <T,maxsize>(const array<T,maxsize> &,const array<T,maxsize> &);
};


template <typename T,size_t arraysize>
bool operator != (const array<T,arraysize> &l, const array<T,arraysize> &r)
template <typename T, size_t maxsize>
class array<T,maxsize,true>
{
if (l.n != r.n)
return true;
if (std::is_trivial<T>::value) {
return 0 != memcmp(l.data,r.data,sizeof(T)*l.n);
} else {
for (size_t i = 0; i < l.n; ++i) {
if (l.data[i] != r.data[i])
return true;
}
public:
array()
: n(0)
, data()
{ }

void clear()
{ n = 0; }

size_t size() const
{ return n; }

void resize(size_t ns)
{
assert(ns <= maxsize);
n = ns;
}

void push_back(const T &d)
{
assert(n < maxsize);
data[n++] = d;
}

void emplace_back(const T &d)
{
assert(n < maxsize);
data[n++] = d;
}

template <typename... Args>
void emplace_back(const Args&... args)
{
assert(n < maxsize);
data[n++] = T(args...);
}

const T& operator [] (size_t x) const
{
assert(x < n);
return data[x];
}

T& operator [] (size_t x)
{
assert(x < n);
return data[x];
}

const T& back() const
{
assert(n != 0);
return data[n-1];
}

T& back()
{
assert(n != 0);
return data[n-1];
}

T *begin()
{ return data; }

T *end()
{ return data+maxsize; }

const T *begin() const
{ return data; }

const T *end() const
{ return data+maxsize; }

bool empty() const
{ return n == 0; }

void erase(T *x)
{
size_t i = x - data;
assert(i < n);
--n;
memmove(data+i,data+i+1,sizeof(T)*(n-i));
}
return false;
}

bool operator != (const array &r) const
{
if (n != r.n)
return true;
return n ? memcmp(data,r.data,sizeof(T)*n) : false;
}

private:
size_t n;
T data[maxsize];
};


#endif

19 changes: 14 additions & 5 deletions src/CppGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ void CppGenerator::writeSetByName(Generator &G, Message *m)
unsigned n = 0;
for (auto i : m->getFields()) {
Field *f = i.second;
if ((f == 0) || !f->isUsed())
if ((f == 0) || !f->isUsed() || f->isObsolete())
continue;
uint32_t t = f->getType();
if ((t == ft_bytes) || (t == ft_cptr))
Expand Down Expand Up @@ -2045,7 +2045,7 @@ void CppGenerator::writeCalcSize(Generator &G, Field *f)
const char *packed = "";
if (quan != q_required) {
char buf[32];
sprintf(buf," + %d /* tag(id) 0x%x */",ts,f->getId()<<3);
sprintf(buf," + %d /* tag($fname) 0x%x */",ts,f->getId()<<3);
tstr = buf;
}
if (quan == q_repeated) {
Expand Down Expand Up @@ -2292,7 +2292,7 @@ void CppGenerator::writeCalcSize(Generator &G, Message *m)
size_t n = 0;
for (auto i : m->getFields()) {
Field *f = i.second;
if (f == 0)
if ((f == 0) || (!f->isUsed()) || f->isObsolete())
continue;
if (f->getQuantifier() == 1) {
size_t ts = f->getTagSize();
Expand Down Expand Up @@ -2500,6 +2500,8 @@ void CppGenerator::writeFromMemory(Generator &G, Field *f)
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;
}
if (f->isPacked()) {
G.setVariableHex("field_tag",(int64_t)id<<3|2);
Expand Down Expand Up @@ -3649,7 +3651,7 @@ void CppGenerator::writeUnequal(Generator &G, Message *m)
"{\n";
for (auto i : m->getFields()) {
Field *f = i.second;
if ((f == 0) || (!f->isUsed()))
if ((f == 0) || (!f->isUsed()) || f->isObsolete())
continue;
G.setField(f);
quant_t q = f->getQuantifier();
Expand Down Expand Up @@ -3712,6 +3714,11 @@ void CppGenerator::writeEqual(Generator &G, Message *m)
if ((f == 0) || (!f->isUsed()))
continue;
G.setField(f);
if (f->isObsolete()) {
G << "// nothing to do for obsolete $fname\n";
G.setField(0);
continue;
}
quant_t q = f->getQuantifier();
if (f->isVirtual()) {
G << "if ($(field_value)() != r.$(field_value)())\n"
Expand Down Expand Up @@ -4271,9 +4278,11 @@ void CppGenerator::writeFromMemory_early(Generator &G, Field *f)
G.setField(f);
uint32_t type = f->getTypeClass();
uint32_t id = f->getId();
if (!f->isUsed()) {
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;
}
if (f->isPacked()) {
G.setVariableHex("field_tag",(int64_t)id<<3|2);
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2017-2019, Thomas Maier-Komor
# Copyright (C) 2017-2020, Thomas Maier-Komor
#
# This source file belongs to Wire-Format-Compiler.
#
Expand Down
3 changes: 2 additions & 1 deletion src/mkversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ elif [ -f ../.hg_archival.txt ]; then
else
# Bail out with an error, if no version information an be gathered.
echo no version information available
exit 1
VER="<unknown>"
echo "#define VERSION \"$VER\"" > version.h.new
fi

echo version $VER
Expand Down
14 changes: 11 additions & 3 deletions src/wfc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const char *InstallDir = 0;

void printVersion(ostream &out)
{
out << "Wire Format Compiler (WFC), Version " VERSION "\nCopyright 2015-2020, Thomas Maier-Komor\n";
out << "Wire Format Compiler (WFC), Version " VERSION "\n"
"Copyright 2015-2020, Thomas Maier-Komor\n"
"License: GPLv3 (see file LICENSE for details)\n";
}


Expand Down Expand Up @@ -254,7 +256,7 @@ int main(int argc, char *argv[])
setenv("POSIXLY_CORRECT","1",1);
#endif
while (optind < argc) {
int opt = getopt(argc,argv,PCORRECT "d:f:ghI:lm:O:o:p:st:Vvx:y");
int opt = getopt(argc,argv,PCORRECT ":d:f:ghI:lm:O:o:p:st:Vvx:y");
if (opt == -1) {
if (optind == argc)
break;
Expand Down Expand Up @@ -326,8 +328,14 @@ int main(int argc, char *argv[])
case 'y':
yydebug = true;
break;
case ':':
fatal("missing argument to option %s",argv[optind-1]);
break;
case '?':
fatal("unknown option %s",argv[optind-1]);
break;
default:
fatal("unknown option -%c",opt);
fatal("unhandled option -%c",opt);
}
}
string sharedir0 = InstallDir;
Expand Down
6 changes: 5 additions & 1 deletion testsuite/genwfc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WFCSRCS = testcases/empty_elements.wfc testcases/enumtest.wfc testcases/validbit
testcases/inv_def.wfc testcases/arraycheck.wfc


CXXSRCS = $(WFCSRCS:testcases/%.wfc=$(ODIR)/%.cpp)
CXXSRCS = $(WFCSRCS:testcases/%.wfc=$(ODIR)/%.cpp) $(ODIR)/referencev2.cpp

$(ODIR)/%.cpp: testcases/%.wfc
"$(WFC)" $(WFCFLAGS) $< -o $(@:.cpp=)
Expand All @@ -37,6 +37,7 @@ $(ODIR)/%.cpp: testcases/%.wfc
all: $(CXXSRCS) $(ODIR)/skip_s.cpp $(ODIR)/comp_v1.cpp $(ODIR)/comp_v2.cpp



$(ODIR)/hostscope.cpp: testcases/hostscope.wfc
"$(WFC)" $(WFCFLAGS) -fno-asserts $< -o $(@:.cpp=)

Expand All @@ -54,3 +55,6 @@ $(ODIR)/comp_v1.cpp: testcases/compatibility.wfc

$(ODIR)/comp_v2.cpp: testcases/compatibility.wfc
"$(WFC)" $(WFCFLAGS) -tV2 -o $(ODIR)/comp_v2 testcases/compatibility.wfc

$(ODIR)/referencev2.cpp: testcases/reference.wfc
"$(WFC)" $(WFCFLAGS) -trev2 -o $(ODIR)/referencev2 $^
Loading

0 comments on commit ac967d3

Please sign in to comment.