Skip to content

Commit

Permalink
[style] fix indent
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Nov 3, 2013
1 parent 8d2ac81 commit 71ef38e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 55 deletions.
64 changes: 42 additions & 22 deletions src/declaration.c
Expand Up @@ -837,7 +837,8 @@ void VarDeclaration::semantic(Scope *sc)

Scope *scx = NULL;
if (scope)
{ sc = scope;
{
sc = scope;
scx = sc;
scope = NULL;
}
Expand All @@ -858,7 +859,8 @@ void VarDeclaration::semantic(Scope *sc)
*/
int inferred = 0;
if (!type)
{ inuse++;
{
inuse++;

// Infering the type requires running semantic,
// so mark the scope as ctfe if required
Expand All @@ -868,7 +870,8 @@ void VarDeclaration::semantic(Scope *sc)
//printf("inferring type for %s with init %s\n", toChars(), init->toChars());
ArrayInitializer *ai = init->isArrayInitializer();
if (ai)
{ Expression *e;
{
Expression *e;
if (ai->isAssociativeArray())
e = ai->toAssocArrayLiteral();
else
Expand All @@ -895,7 +898,8 @@ void VarDeclaration::semantic(Scope *sc)
inferred = 1;

if (init->isArrayInitializer() && type->toBasetype()->ty == Tsarray)
{ // Prefer array literals to give a T[] type rather than a T[dim]
{
// Prefer array literals to give a T[] type rather than a T[dim]
type = type->toBasetype()->nextOf()->arrayOf();
}

Expand All @@ -906,7 +910,8 @@ void VarDeclaration::semantic(Scope *sc)
originalType = type->syntaxCopy();
}
else
{ if (!originalType)
{
if (!originalType)
originalType = type->syntaxCopy();
inuse++;
type = type->semantic(loc, sc);
Expand Down Expand Up @@ -978,13 +983,14 @@ void VarDeclaration::semantic(Scope *sc)
tb = type;
}
if (tb->ty == Tfunction)
{ error("cannot be declared to be a function");
{
error("cannot be declared to be a function");
type = Type::terror;
tb = type;
}
if (tb->ty == Tstruct)
{ TypeStruct *ts = (TypeStruct *)tb;

{
TypeStruct *ts = (TypeStruct *)tb;
if (!ts->sym->members)
{
error("no definition of struct %s", ts->toChars());
Expand All @@ -994,7 +1000,8 @@ void VarDeclaration::semantic(Scope *sc)
error("storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?");

if (tb->ty == Ttuple)
{ /* Instead, declare variables for each of the tuple elements
{
/* Instead, declare variables for each of the tuple elements
* and add those.
*/
TypeTuple *tt = (TypeTuple *)tb;
Expand Down Expand Up @@ -1097,7 +1104,8 @@ void VarDeclaration::semantic(Scope *sc)
TupleExp *te = (TupleExp *)ie;
size_t tedim = te->exps->dim;
if (tedim != nelems)
{ ::error(loc, "tuple of %d elements cannot be assigned to tuple of %d elements", (int)tedim, (int)nelems);
{
::error(loc, "tuple of %d elements cannot be assigned to tuple of %d elements", (int)tedim, (int)nelems);
for (size_t u = tedim; u < nelems; u++) // fill dummy expression
te->exps->push(new ErrorExp());
}
Expand Down Expand Up @@ -1137,7 +1145,8 @@ void VarDeclaration::semantic(Scope *sc)
v->semantic(sc);

if (sc->scopesym)
{ //printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
{
//printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
if (sc->scopesym->members)
sc->scopesym->members->push(v);
}
Expand Down Expand Up @@ -1377,7 +1386,8 @@ void VarDeclaration::semantic(Scope *sc)
}
else if (type->ty == Tstruct &&
((TypeStruct *)type)->sym->zeroInit == 1)
{ /* If a struct is all zeros, as a special case
{
/* If a struct is all zeros, as a special case
* set it's initializer to the integer 0.
* In AssignExp::toElem(), we check for this and issue
* a memset() to initialize the struct.
Expand All @@ -1392,9 +1402,11 @@ void VarDeclaration::semantic(Scope *sc)
goto Ldtor;
}
else if (type->ty == Ttypedef)
{ TypeTypedef *td = (TypeTypedef *)type;
{
TypeTypedef *td = (TypeTypedef *)type;
if (td->sym->init)
{ init = td->sym->init;
{
init = td->sym->init;
ExpInitializer *ie = init->isExpInitializer();
if (ie)
// Make copy so we can modify it
Expand Down Expand Up @@ -1429,17 +1441,20 @@ void VarDeclaration::semantic(Scope *sc)
{
// See if initializer is a NewExp that can be allocated on the stack
if (ei->exp->op == TOKnew)
{ NewExp *ne = (NewExp *)ei->exp;
{
NewExp *ne = (NewExp *)ei->exp;
if (!(ne->newargs && ne->newargs->dim))
{ ne->onstack = 1;
{
ne->onstack = 1;
onstack = 1;
if (type->isBaseOf(ne->newtype->semantic(loc, sc), NULL))
onstack = 2;
}
}
// or a delegate that doesn't escape a reference to the function
else if (ei->exp->op == TOKfunction)
{ FuncDeclaration *f = ((FuncExp *)ei->exp)->fd;
{
FuncDeclaration *f = ((FuncExp *)ei->exp)->fd;
f->tookAddressOf--;
}
}
Expand All @@ -1463,7 +1478,8 @@ void VarDeclaration::semantic(Scope *sc)
init = init->semantic(sc, type, INITnointerpret);
e = init->toExpression();
if (!e)
{ error("is not a static and cannot have static initializer");
{
error("is not a static and cannot have static initializer");
return;
}
}
Expand Down Expand Up @@ -1519,11 +1535,14 @@ void VarDeclaration::semantic(Scope *sc)
* *__ctmp.ctor(arguments...)
*/
if ((*pinit)->type->implicitConvTo(t))
{ CallExp *ce = (CallExp *)(*pinit);
{
CallExp *ce = (CallExp *)(*pinit);
if (ce->e1->op == TOKdotvar)
{ DotVarExp *dve = (DotVarExp *)ce->e1;
{
DotVarExp *dve = (DotVarExp *)ce->e1;
if (dve->var->isCtorDeclaration())
{ /* It's a constructor call, currently constructing
{
/* It's a constructor call, currently constructing
* a temporary __ctmp.
*/
/* Before calling the constructor, initialize
Expand Down Expand Up @@ -1610,7 +1629,8 @@ void VarDeclaration::semantic(Scope *sc)
/* Initializing with the same type is done differently
*/
!(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc)))
{ // Rewrite as e1.call(arguments)
{
// Rewrite as e1.call(arguments)
Expression *e = typeDotIdExp(ei->exp->loc, t, Id::call);
ei->exp = new CallExp(loc, e, ei->exp);
}
Expand Down
47 changes: 20 additions & 27 deletions src/e2ir.c
Expand Up @@ -2879,7 +2879,8 @@ elem *AssignExp::toElem(IRState *irs)

// which we do if the 'next' types match
if (ismemset)
{ // Do a memset for array[]=v
{
// Do a memset for array[]=v
//printf("Lpair %s\n", toChars());
elem *evalue;
elem *enbytes;
Expand Down Expand Up @@ -2928,22 +2929,14 @@ elem *AssignExp::toElem(IRState *irs)

#if 0
printf("sz = %d\n", sz);
printf("n1x\n");
elem_print(n1x);
printf("einit\n");
elem_print(einit);
printf("elwrx\n");
elem_print(elwrx);
printf("euprx\n");
elem_print(euprx);
printf("n1\n");
elem_print(n1);
printf("elwr\n");
elem_print(elwr);
printf("eupr\n");
elem_print(eupr);
printf("enbytes\n");
elem_print(enbytes);
printf("n1x\n"); elem_print(n1x);
printf("einit\n"); elem_print(einit);
printf("elwrx\n"); elem_print(elwrx);
printf("euprx\n"); elem_print(euprx);
printf("n1\n"); elem_print(n1);
printf("elwr\n"); elem_print(elwr);
printf("eupr\n"); elem_print(eupr);
printf("enbytes\n"); elem_print(enbytes);
#endif
einit = el_combine(n1x, einit);
einit = el_combine(einit, elwrx);
Expand All @@ -2952,10 +2945,8 @@ elem *AssignExp::toElem(IRState *irs)
evalue = this->e2->toElem(irs);

#if 0
printf("n1\n");
elem_print(n1);
printf("enbytes\n");
elem_print(enbytes);
printf("n1\n"); elem_print(n1);
printf("enbytes\n"); elem_print(enbytes);
#endif

if (irs->arrayBoundsCheck() && eupr && ta->ty != Tpointer)
Expand Down Expand Up @@ -3171,8 +3162,8 @@ elem *AssignExp::toElem(IRState *irs)
* function arguments, it'll fail.
*/
if (op == TOKconstruct && e2->op == TOKcall)
{ CallExp *ce = (CallExp *)e2;

{
CallExp *ce = (CallExp *)e2;
TypeFunction *tf = (TypeFunction *)ce->e1->type->toBasetype();
if (tf->ty == Tfunction && tf->retStyle() == RETstack)
{
Expand All @@ -3187,10 +3178,11 @@ elem *AssignExp::toElem(IRState *irs)
#endif
//if (op == TOKconstruct) printf("construct\n");
if (t1b->ty == Tstruct || t1b->ty == Tsarray)
{ elem *eleft = e1->toElem(irs);

{
elem *eleft = e1->toElem(irs);
if (e2->op == TOKint64)
{ /* Implement:
{
/* Implement:
* (struct = 0)
* with:
* memset(&struct, 0, struct.sizeof)
Expand Down Expand Up @@ -3230,7 +3222,8 @@ elem *AssignExp::toElem(IRState *irs)
ex = e1->E1;
if (this->e2->op == TOKstructliteral &&
ex->Eoper == OPvar && ex->EV.sp.Voffset == 0)
{ StructLiteralExp *se = (StructLiteralExp *)this->e2;
{
StructLiteralExp *se = (StructLiteralExp *)this->e2;

Symbol *symSave = se->sym;
size_t soffsetSave = se->soffset;
Expand Down
16 changes: 10 additions & 6 deletions src/expression.c
Expand Up @@ -11243,7 +11243,8 @@ Expression *AssignExp::semantic(Scope *sc)
return this;

if (e2->op == TOKcomma)
{ /* Rewrite to get rid of the comma from rvalue
{
/* Rewrite to get rid of the comma from rvalue
*/
AssignExp *ea = new AssignExp(loc, e1, ((CommaExp *)e2)->e2);
ea->op = op;
Expand Down Expand Up @@ -11854,7 +11855,8 @@ Expression *AssignExp::semantic(Scope *sc)
}
}
else
{ // Try to do a decent error message with the expression
{
// Try to do a decent error message with the expression
// before it got constant folded
if (e1->op != TOKvar)
e1 = e1->optimize(WANTvalue);
Expand All @@ -11877,7 +11879,8 @@ Expression *AssignExp::semantic(Scope *sc)
t1->nextOf() && (telem->ty != Tvoid || e2->op == TOKnull) &&
e2->implicitConvTo(t1->nextOf())
)
{ // memset
{
// memset
ismemset = 1; // make it easy for back end to tell what this is
e2 = e2->implicitCastTo(sc, t1->nextOf());
if (op != TOKblit && e2->isLvalue())
Expand All @@ -11897,8 +11900,8 @@ Expression *AssignExp::semantic(Scope *sc)
}
// Check element-wise assignment.
else if (e1->op == TOKslice &&
(t2->ty == Tarray || t2->ty == Tsarray) &&
t2->nextOf()->implicitConvTo(t1->nextOf()))
(t2->ty == Tarray || t2->ty == Tsarray) &&
t2->nextOf()->implicitConvTo(t1->nextOf()))
{
SliceExp *se1 = (SliceExp *)e1;
Type *tx1 = se1->e1->type->toBasetype();
Expand All @@ -11914,7 +11917,8 @@ Expression *AssignExp::semantic(Scope *sc)
goto Lsa;
}
if (tx2->ty == Tsarray)
{ // sa1[] = sa2[];
{
// sa1[] = sa2[];
// sa1[] = sa2;
// sa1[] = [ ... ];
dim2 = ((TypeSArray *)tx2)->dim->toInteger();
Expand Down

0 comments on commit 71ef38e

Please sign in to comment.