Permalink
Browse files

Merged the last bits of dmdfe 2.059

  • Loading branch information...
2 parents 07bf68a + eadd5fb commit 3fb21f986eb092d0c1cae1f95d46b667c4f27777 @AlexeyProkhin AlexeyProkhin committed Apr 22, 2012
Showing with 295 additions and 55 deletions.
  1. +15 −3 dmd2/attrib.c
  2. +1 −0 dmd2/attrib.h
  3. +23 −6 dmd2/cond.c
  4. +2 −1 dmd2/cond.h
  5. +9 −2 dmd2/declaration.c
  6. +110 −31 dmd2/expression.c
  7. +2 −1 dmd2/expression.h
  8. +55 −0 dmd2/func.c
  9. +24 −4 dmd2/init.c
  10. +2 −1 dmd2/interpret.c
  11. +2 −0 dmd2/module.c
  12. +22 −1 dmd2/mtype.c
  13. +3 −1 dmd2/struct.c
  14. +18 −2 dmd2/template.c
  15. +5 −0 dmd2/traits.c
  16. +1 −1 runtime/druntime
  17. +1 −1 runtime/phobos
View
@@ -56,7 +56,7 @@ Dsymbols *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd)
int AttribDeclaration::apply(Dsymbol_apply_ft_t fp, void *param)
{
- Dsymbols *d = include(NULL, NULL);
+ Dsymbols *d = include(scope, NULL);
if (d)
{
@@ -1278,9 +1278,9 @@ void ConditionalDeclaration::emitComment(Scope *sc)
Dsymbols *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd)
{
- //printf("ConditionalDeclaration::include()\n");
+ //printf("ConditionalDeclaration::include(sc = %p) scope = %p\n", sc, scope);
assert(condition);
- return condition->include(sc, sd) ? decl : elsedecl;
+ return condition->include(scope ? scope : sc, sd) ? decl : elsedecl;
}
void ConditionalDeclaration::setScope(Scope *sc)
@@ -1440,6 +1440,9 @@ void StaticIfDeclaration::importAll(Scope *sc)
void StaticIfDeclaration::setScope(Scope *sc)
{
// do not evaluate condition before semantic pass
+
+ // But do set the scope, in case we need it for forward referencing
+ Dsymbol::setScope(sc);
}
void StaticIfDeclaration::semantic(Scope *sc)
@@ -1471,6 +1474,8 @@ const char *StaticIfDeclaration::kind()
/***************************** CompileDeclaration *****************************/
+// These are mixin declarations, like mixin("int x");
+
CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp)
: AttribDeclaration(NULL)
{
@@ -1544,3 +1549,10 @@ void CompileDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(");");
buf->writenl();
}
+
+const char *CompileDeclaration::kind()
+{
+ return "mixin";
+}
+
+
View
@@ -200,6 +200,7 @@ struct CompileDeclaration : AttribDeclaration
void compileIt(Scope *sc);
void semantic(Scope *sc);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
+ const char *kind();
};
#endif /* DMD_ATTRIB_H */
View
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
-// Copyright (c) 1999-2011 by Digital Mars
+// Copyright (c) 1999-2012 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -22,14 +22,15 @@
#include "lexer.h"
#include "mtype.h"
#include "scope.h"
+#include "arraytypes.h"
int findCondition(Strings *ids, Identifier *ident)
{
if (ids)
{
for (size_t i = 0; i < ids->dim; i++)
{
- const char *id = ids->tdata()[i];
+ const char *id = (*ids)[i];
if (strcmp(id, ident->toChars()) == 0)
return TRUE;
@@ -224,6 +225,7 @@ StaticIfCondition::StaticIfCondition(Loc loc, Expression *exp)
: Condition(loc)
{
this->exp = exp;
+ this->nest = 0;
}
Condition *StaticIfCondition::syntaxCopy()
@@ -234,28 +236,43 @@ Condition *StaticIfCondition::syntaxCopy()
int StaticIfCondition::include(Scope *sc, ScopeDsymbol *s)
{
#if 0
- printf("StaticIfCondition::include(sc = %p, s = %p)\n", sc, s);
+ printf("StaticIfCondition::include(sc = %p, s = %p) this=%p inc = %d\n", sc, s, this, inc);
if (s)
{
printf("\ts = '%s', kind = %s\n", s->toChars(), s->kind());
}
#endif
if (inc == 0)
{
+ if (exp->op == TOKerror || nest > 100)
+ {
+ error(loc, (nest > 1000) ? "unresolvable circular static if expression"
+ : "error evaluating static if expression");
+ if (!global.gag)
+ inc = 2; // so we don't see the error message again
+ return 0;
+ }
+
if (!sc)
{
error(loc, "static if conditional cannot be at global scope");
inc = 2;
return 0;
}
+ ++nest;
sc = sc->push(sc->scopesym);
sc->sd = s; // s gets any addMember()
sc->flags |= SCOPEstaticif;
Expression *e = exp->semantic(sc);
sc->pop();
e = e->optimize(WANTvalue | WANTinterpret);
- if (e->isBool(TRUE))
+ --nest;
+ if (e->op == TOKerror)
+ { exp = e;
+ inc = 0;
+ }
+ else if (e->isBool(TRUE))
inc = 1;
else if (e->isBool(FALSE))
inc = 2;
@@ -327,7 +344,7 @@ int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
TemplateParameters parameters;
parameters.setDim(1);
- parameters.tdata()[0] = &tp;
+ parameters[0] = &tp;
Objects dedtypes;
dedtypes.setDim(1);
@@ -339,7 +356,7 @@ int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
else
{
inc = 1;
- Type *tded = (Type *)dedtypes.tdata()[0];
+ Type *tded = (Type *)dedtypes[0];
if (!tded)
tded = targ;
Dsymbol *s = new AliasDeclaration(loc, id, tded);
View
@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
-// Copyright (c) 1999-2011 by Digital Mars
+// Copyright (c) 1999-2012 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -79,6 +79,7 @@ struct VersionCondition : DVCondition
struct StaticIfCondition : Condition
{
Expression *exp;
+ int nest; // limit circular dependencies
StaticIfCondition(Loc loc, Expression *exp);
Condition *syntaxCopy();
View
@@ -796,6 +796,7 @@ void VarDeclaration::semantic(Scope *sc)
if (!type)
{ inuse++;
+ //printf("inferring type for %s with init %s\n", toChars(), init->toChars());
ArrayInitializer *ai = init->isArrayInitializer();
if (ai)
{ Expression *e;
@@ -816,7 +817,6 @@ void VarDeclaration::semantic(Scope *sc)
else
type = init->inferType(sc);
-//printf("test2: %s, %s, %s\n", toChars(), type->toChars(), type->deco);
// type = type->semantic(loc, sc);
inuse--;
@@ -883,7 +883,14 @@ void VarDeclaration::semantic(Scope *sc)
Type *tb = type->toBasetype();
if (tb->ty == Tvoid && !(storage_class & STClazy))
- { error("voids have no value");
+ {
+ if (inferred)
+ {
+ error("type %s is inferred from initializer %s, and variables cannot be of type void",
+ type->toChars(), init->toChars());
+ }
+ else
+ error("variables cannot be of type void");
type = Type::terror;
tb = type;
}
Oops, something went wrong.

0 comments on commit 3fb21f9

Please sign in to comment.