/* Compare the first N bytes of S1 and S2 without regard to the case. */
int
-Port::memicmp (const char *s1, const char *s2, size_t n)
+Port::memicmp (const char *s1, const char *s2, d_size_t n)
{
int result = 0;
- for (size_t i = 0; i < n; i++)
+ for (d_size_t i = 0; i < n; i++)
{
char c1 = s1[i];
char c2 = s2[i];
/* Write an SZ-byte sized VALUE to BUFFER, ignoring endian-ness. */
void
-Port::valcpy (void *buffer, uint64_t value, size_t sz)
+Port::valcpy (void *buffer, uint64_t value, d_size_t sz)
{
- gcc_assert (((size_t) buffer) % sz == 0);
+ gcc_assert (((d_size_t) buffer) % sz == 0);
switch (sz)
{
goto Lexp;
case TOK.leftParenthesis:
- {
- /* If tokens look like a function call, assume it is one,
- * As any type-name won't be resolved until semantic, this
- * could be rewritten later.
- */
- auto tk = &token;
- if (isFunctionCall(tk))
- goto Lexp;
- goto default;
- }
+ if (auto pt = lookupTypedef(token.ident))
+ {
+ if (*pt)
+ goto Ldeclaration;
+ }
+ goto Lexp; // function call
default:
{
*/
if (token.value == TOK.semicolon)
{
- nextToken();
if (!tspec)
+ {
+ nextToken();
return; // accept empty declaration as an extension
+ }
+
+ if (auto ti = tspec.isTypeIdentifier())
+ {
+ // C11 6.7.2-2
+ error("type-specifier missing for declaration of `%s`", ti.ident.toChars());
+ nextToken();
+ return;
+ }
+ nextToken();
auto tt = tspec.isTypeTag();
if (!tt ||
!tt.id && (tt.tok == TOK.struct_ || tt.tok == TOK.union_))
specifier.mod &= ~MOD.xnone; // 'used' it
}
+ void scanPastSemicolon()
+ {
+ while (token.value != TOK.semicolon && token.value != TOK.endOfFile)
+ nextToken();
+ nextToken();
+ }
+
+ if (token.value == TOK.assign && tspec && tspec.isTypeIdentifier())
+ {
+ /* C11 6.7.2-2
+ * Special check for `const b = 1;` because some compilers allow it
+ */
+ error("type-specifier omitted for declaration of `%s`", tspec.isTypeIdentifier().ident.toChars());
+ return scanPastSemicolon();
+ }
+
bool first = true;
while (1)
{
default:
error("`=`, `;` or `,` expected to end declaration instead of `%s`", token.toChars());
Lend:
- while (token.value != TOK.semicolon && token.value != TOK.endOfFile)
- nextToken();
- nextToken();
- return;
+ return scanPastSemicolon();
}
}
}
default:
if (declarator == DTR.xdirect)
{
- error("identifier or `(` expected"); // )
+ if (!t || t.isTypeIdentifier())
+ {
+ // const arr[1];
+ error("no type-specifier for declarator");
+ t = AST.Type.tint32;
+ }
+ else
+ error("identifier or `(` expected"); // )
panic();
}
ts = t;
Specifier specifier;
specifier.packalign.setDefault();
auto tspec = cparseSpecifierQualifierList(LVL.global, specifier);
+ if (!tspec)
+ {
+ error("type-specifier is missing");
+ tspec = AST.Type.tint32;
+ }
if (tspec && specifier.mod & MOD.xconst)
{
tspec = toConst(tspec);
Specifier specifier;
specifier.packalign.setDefault();
auto tspec = cparseDeclarationSpecifiers(LVL.prototype, specifier);
- if (tspec && specifier.mod & MOD.xconst)
+ if (!tspec)
{
+ error("no type-specifier for parameter");
+ tspec = AST.Type.tint32;
+ }
+
+ if (specifier.mod & MOD.xconst)
+ {
+ if ((token.value == TOK.rightParenthesis || token.value == TOK.comma) &&
+ tspec.isTypeIdentifier())
+ error("type-specifier omitted for parameter `%s`", tspec.isTypeIdentifier().ident.toChars());
+
tspec = toConst(tspec);
specifier.mod = MOD.xnone; // 'used' it
}
Specifier specifier;
specifier.packalign = this.packalign;
auto tspec = cparseSpecifierQualifierList(LVL.member, specifier);
- if (tspec && specifier.mod & MOD.xconst)
+ if (!tspec)
+ {
+ error("no type-specifier for struct member");
+ tspec = AST.Type.tint32;
+ }
+ if (specifier.mod & MOD.xconst)
{
tspec = toConst(tspec);
specifier.mod = MOD.xnone; // 'used' it
nextToken();
auto tt = tspec.isTypeTag();
if (!tt)
+ {
+ if (auto ti = tspec.isTypeIdentifier())
+ {
+ error("type-specifier omitted before declaration of `%s`", ti.ident.toChars());
+ }
return; // legal but meaningless empty declaration
+ }
/* If anonymous struct declaration
* struct { ... members ... };
AST.Type dt;
if (token.value == TOK.colon)
{
+ if (auto ti = tspec.isTypeIdentifier())
+ {
+ error("type-specifier omitted before bit field declaration of `%s`", ti.ident.toChars());
+ tspec = AST.Type.tint32;
+ }
+
// C11 6.7.2.1-12 unnamed bit-field
id = Identifier.generateAnonymousId("BitField");
dt = tspec;
OwnedBy ownedByCtfe;
static StringExp *create(const Loc &loc, const char *s);
- static StringExp *create(const Loc &loc, const void *s, size_t len);
+ static StringExp *create(const Loc &loc, const void *s, d_size_t len);
static void emplace(UnionExp *pue, const Loc &loc, const char *s);
bool equals(const RootObject *o) const;
- char32_t getCodeUnit(size_t i) const;
- void setCodeUnit(size_t i, char32_t c);
+ char32_t getCodeUnit(d_size_t i) const;
+ void setCodeUnit(d_size_t i, char32_t c);
StringExp *toStringExp();
StringExp *toUTF8(Scope *sc);
Optional<bool> toBool();
if (s.ident)
{
VarDeclaration v = s.isVarDeclaration();
- if (v && !(sc.flags & SCOPE.Cfile))
+ if (v)
{
- /* Do semantic() on initializer first so this will be illegal:
- * int a = a;
- */
- e.declaration.dsymbolSemantic(sc);
- s.parent = sc.parent;
+ if (sc.flags & SCOPE.Cfile)
+ {
+ /* Do semantic() on the type before inserting v into the symbol table
+ */
+ if (!v.originalType)
+ v.originalType = v.type.syntaxCopy();
+ Scope* sc2 = sc.push();
+ sc2.stc |= v.storage_class & STC.FUNCATTR;
+ sc2.linkage = LINK.c; // account for the extern(C) in front of the declaration
+ v.inuse++;
+ v.type = v.type.typeSemantic(v.loc, sc2);
+ v.inuse--;
+ sc2.pop();
+ }
+ else
+ {
+ /* Do semantic() on initializer first so this will be illegal:
+ * int a = a;
+ */
+ e.declaration.dsymbolSemantic(sc);
+ s.parent = sc.parent;
+ }
}
if (!sc.insert(s))
// The idea is to minimize #ifdef's in the app code.
#include "dsystem.h"
+#include "dcompat.h"
typedef unsigned char utf8_t;
struct Port
{
- static int memicmp(const char *s1, const char *s2, size_t n);
+ static int memicmp(const char *s1, const char *s2, d_size_t n);
static char *strupr(char *s);
static bool isFloat32LiteralOutOfRange(const char *s);
static unsigned readlongBE(const void *buffer);
static unsigned readwordLE(const void *buffer);
static unsigned readwordBE(const void *buffer);
- static void valcpy(void *dst, uint64_t val, size_t size);
+ static void valcpy(void *dst, uint64_t val, d_size_t size);
};