Permalink
Browse files

more verbose search correct proposals

- print protection and kind
- print fully qualified name
  • Loading branch information...
1 parent 696a468 commit f3513e6763af1a48f2d3d11cacf90594b133960a @MartinNowak committed Mar 19, 2012
Showing with 74 additions and 54 deletions.
  1. +6 −0 src/access.c
  2. +8 −9 src/attrib.c
  3. +1 −1 src/declaration.h
  4. +40 −28 src/dsymbol.c
  5. +4 −1 src/dsymbol.h
  6. +2 −3 src/expression.c
  7. +3 −3 src/func.c
  8. +1 −1 src/import.c
  9. +2 −2 src/init.c
  10. +6 −5 src/mtype.c
  11. +1 −1 src/template.c
View
@@ -411,6 +411,12 @@ void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d)
}
}
+const char *protectionToChars(enum PROT prot)
+{
+ static const char *names[] = {NULL, "none", "private", "package", "protected", "public", "export"};
+ return names[prot];
+}
+
enum PROT moduleVisibility(Module *from, Module *to)
{
if (from == to)
View
@@ -681,21 +681,20 @@ void ProtDeclaration::semantic(Scope *sc)
void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection)
{
- const char *p;
-
switch (protection)
{
- case PROTprivate: p = "private"; break;
- case PROTpackage: p = "package"; break;
- case PROTprotected: p = "protected"; break;
- case PROTpublic: p = "public"; break;
- case PROTexport: p = "export"; break;
+ case PROTprivate:
+ case PROTpackage:
+ case PROTprotected:
+ case PROTpublic:
+ case PROTexport:
+ buf->writestring(protectionToChars(protection));
+ buf->writeByte(' ');
+ break;
default:
assert(0);
break;
}
- buf->writestring(p);
- buf->writeByte(' ');
}
void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
View
@@ -640,7 +640,7 @@ struct FuncDeclaration : Declaration
void appendExp(Expression *e);
void appendState(Statement *s);
char *mangle();
- const char *toPrettyChars();
+ const char *toPrettyChars(bool verbose=false);
int isMain();
int isWinMain();
int isDllMain();
View
@@ -174,45 +174,57 @@ char *Dsymbol::toChars()
return ident ? ident->toChars() : (char *)"__anonymous";
}
-const char *Dsymbol::toPrettyChars()
-{ Dsymbol *p;
- char *s;
- char *q;
- size_t len;
+const char *Dsymbol::toPrettyChars(bool verbose)
+{
//printf("Dsymbol::toPrettyChars() '%s'\n", toChars());
- if (!parent)
+ if (!verbose && !parent)
return toChars();
- len = 0;
- for (p = this; p; p = p->parent)
+ OutBuffer buf;
+ if (verbose)
+ {
+ if (enum PROT p = prot())
+ {
+ buf.writestring(protectionToChars(p));
+ buf.writeByte(' ');
+ }
+ buf.writestring(kind());
+ buf.writeByte(' ');
+ }
+
+ size_t len = 0;
+ for (Dsymbol *p = this; p; p = p->parent)
len += strlen(p->toChars()) + 1;
- s = (char *)mem.malloc(len);
- q = s + len - 1;
+ buf.reserve(len);
+ char *q = (char*)buf.data + buf.offset + len - 1;
*q = 0;
- for (p = this; p; p = p->parent)
+ for (Dsymbol *p = this; p; p = p->parent)
{
+ if (p != this)
+ {
+ --q;
+#if TARGET_NET
+ if (AggregateDeclaration* ad = p->isAggregateDeclaration())
+ {
+ if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration())
+ {
+ *q = '/';
+ goto Lnodot;
+ }
+ }
+#endif
+ *q = '.';
+ }
+ Lnodot:
char *t = p->toChars();
len = strlen(t);
q -= len;
memcpy(q, t, len);
- if (q == s)
- break;
- q--;
-#if TARGET_NET
- if (AggregateDeclaration* ad = p->isAggregateDeclaration())
- {
- if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration())
- {
- *q = '/';
- continue;
- }
}
-#endif
- *q = '.';
- }
- return s;
+ assert(q == (char*)buf.data + buf.offset);
+ return buf.extractData();
}
char *Dsymbol::locToChars()
@@ -442,8 +454,8 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
{
sm = s->search_correct(id);
if (sm)
- error("template identifier '%s' is not a member of '%s %s', did you mean '%s %s'?",
- id->toChars(), s->kind(), s->toChars(), sm->kind(), sm->toChars());
+ error("template identifier '%s' is not a member of '%s %s', did you mean '%s'?",
+ id->toChars(), s->kind(), s->toChars(), sm->toPrettyChars(true));
else
error("template identifier '%s' is not a member of '%s %s'",
id->toChars(), s->kind(), s->toChars());
View
@@ -96,6 +96,9 @@ enum PROT
PROTexport,
};
+// access.c
+const char *protectionToChars(enum PROT prot);
+
/* State of symbol in winding its way through the passes of the compiler
*/
enum PASS
@@ -145,7 +148,7 @@ struct Dsymbol : Object
static Dsymbols *arraySyntaxCopy(Dsymbols *a);
- virtual const char *toPrettyChars();
+ virtual const char *toPrettyChars(bool verbose=false);
virtual const char *kind();
virtual Dsymbol *toAlias(); // resolve real symbol
virtual int apply(Dsymbol_apply_ft_t fp, void *param);
View
@@ -2556,7 +2556,7 @@ Expression *IdentifierExp::semantic(Scope *sc)
{
s = sc->search_correct(ident);
if (s)
- error("undefined identifier %s, did you mean %s %s?", ident->toChars(), s->kind(), s->toChars());
+ error("undefined identifier %s, did you mean '%s'?", ident->toChars(), s->toPrettyChars(true));
else
error("undefined identifier %s", ident->toChars());
}
@@ -6529,8 +6529,7 @@ Expression *DotIdExp::semantic(Scope *sc, int flag)
}
s = ie->sds->search_correct(ident);
if (s)
- error("undefined identifier '%s', did you mean '%s %s'?",
- ident->toChars(), s->kind(), s->toChars());
+ error("undefined identifier '%s', did you mean '%s'?", ident->toChars(), s->toPrettyChars(true));
else
error("undefined identifier '%s'", ident->toChars());
return new ErrorExp();
View
@@ -629,7 +629,7 @@ void FuncDeclaration::semantic(Scope *sc)
{
Dsymbol *s = cd->search_correct(ident);
if (s)
- error("does not override any function, did you mean '%s'", s->toPrettyChars());
+ error("does not override any function, did you mean '%s'", s->toPrettyChars(true));
else
error("does not override any function");
}
@@ -2689,12 +2689,12 @@ void FuncDeclaration::appendState(Statement *s)
}
}
-const char *FuncDeclaration::toPrettyChars()
+const char *FuncDeclaration::toPrettyChars(bool verbose)
{
if (isMain())
return "D main";
else
- return Dsymbol::toPrettyChars();
+ return Dsymbol::toPrettyChars(verbose);
}
int FuncDeclaration::isMain()
View
@@ -229,7 +229,7 @@ void Import::semantic(Scope *sc)
{
s = mod->search_correct(names[i]);
if (s)
- mod->error(loc, "import '%s' not found, did you mean '%s %s'?", names[i]->toChars(), s->kind(), s->toChars());
+ mod->error(loc, "import '%s' not found, did you mean '%s'?", names[i]->toChars(), s->toPrettyChars(true));
else
mod->error(loc, "import '%s' not found", names[i]->toChars());
}
View
@@ -188,8 +188,8 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
{
s = ad->search_correct(id);
if (s)
- error(loc, "'%s' is not a member of '%s', did you mean '%s %s'?",
- id->toChars(), t->toChars(), s->kind(), s->toChars());
+ error(loc, "'%s' is not a member of '%s', did you mean '%s'?",
+ id->toChars(), t->toChars(), s->toPrettyChars(true));
else
error(loc, "'%s' is not a member of '%s'", id->toChars(), t->toChars());
errors = 1;
View
@@ -1965,7 +1965,8 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
if (this != Type::terror)
{
if (s)
- error(loc, "no property '%s' for type '%s', did you mean '%s'?", ident->toChars(), toChars(), s->toChars());
+ error(loc, "no property '%s' for type '%s', did you mean '%s'?",
+ ident->toChars(), toChars(), s->toPrettyChars(true));
else
error(loc, "no property '%s' for type '%s'", ident->toChars(), toChars());
}
@@ -6329,8 +6330,8 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
{
sm = s->search_correct(id);
if (sm)
- error(loc, "identifier '%s' of '%s' is not defined, did you mean '%s %s'?",
- id->toChars(), toChars(), sm->kind(), sm->toChars());
+ error(loc, "identifier '%s' of '%s' is not defined, did you mean '%s'?",
+ id->toChars(), toChars(), sm->toPrettyChars(true));
else
error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars());
}
@@ -6430,9 +6431,9 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
Identifier *id = new Identifier(p, TOKidentifier);
s = sc->search_correct(id);
if (s)
- error(loc, "undefined identifier %s, did you mean %s %s?", p, s->kind(), s->toChars());
+ error(loc, "undefined identifier '%s', did you mean '%s'?", p, s->toPrettyChars(true));
else
- error(loc, "undefined identifier %s", p);
+ error(loc, "undefined identifier '%s'", p);
}
*pt = Type::terror;
}
View
@@ -5002,7 +5002,7 @@ TemplateDeclaration *TemplateInstance::findTemplateDeclaration(Scope *sc)
{
s = sc->search_correct(id);
if (s)
- error("template '%s' is not defined, did you mean %s?", id->toChars(), s->toChars());
+ error("template '%s' is not defined, did you mean '%s'?", id->toChars(), s->toPrettyChars(true));
else
error("template '%s' is not defined", id->toChars());
return NULL;

0 comments on commit f3513e6

Please sign in to comment.