# HG changeset patch # User Anders Johnsen # Date 1216976356 -7200 # Node ID 8ea749b7da9102b6b9566a5949a693088f35a021 # Parent 4e703658eca009c6b352b67cb1264b7146942685 Fixed a few errors so that two more tests passes. Also, now you only need a type in a function param. diff -r 4e703658eca0 -r 8ea749b7da91 ast/Exp.d --- a/ast/Exp.d Fri Jul 25 01:40:08 2008 +0200 +++ b/ast/Exp.d Fri Jul 25 10:59:16 2008 +0200 @@ -296,6 +296,8 @@ override DType type() { + if (_type) + return _type; return exp.type().asPointer().pointerOf; } @@ -304,6 +306,7 @@ return SourceRange(loc) + exp.sourceRange; } + DType _type; public Exp exp; } diff -r 4e703658eca0 -r 8ea749b7da91 ast/Stmt.d --- a/ast/Stmt.d Fri Jul 25 01:40:08 2008 +0200 +++ b/ast/Stmt.d Fri Jul 25 10:59:16 2008 +0200 @@ -194,7 +194,8 @@ override void simplify() { - cond = cond.simplify(); + if (cond) + cond = cond.simplify(); forBody.simplify(); } diff -r 4e703658eca0 -r 8ea749b7da91 basic/Messages.d --- a/basic/Messages.d Fri Jul 25 01:40:08 2008 +0200 +++ b/basic/Messages.d Fri Jul 25 10:59:16 2008 +0200 @@ -43,6 +43,8 @@ CandidateNr, NoMethodByName, NoMachingMethod, + CannotReassignSArray, + CanOnlyDerefPointers, // Strings InvalidStrPrefix, @@ -124,6 +126,8 @@ : E(Err, "Can't have multiple cases with the same value." " Values appearing in multiple cases: %0"), InvalidCaseValue : E(Err, "Case values must be integers"), + CannotReassignSArray: E(Err, "Cannot reassign static arrays"), + CanOnlyDerefPointers: E(Err, "Can only deref pointers, not '%0'"), // literals InvalidStrPrefix : E(Err, "Invalid string literal prefix"), diff -r 4e703658eca0 -r 8ea749b7da91 gen/CodeGen.d --- a/gen/CodeGen.d Fri Jul 25 01:40:08 2008 +0200 +++ b/gen/CodeGen.d Fri Jul 25 10:59:16 2008 +0200 @@ -95,23 +95,22 @@ (FuncDecl fd) { Type[] param_types; - foreach (i, p; fd.funcArgs) + foreach (i, p; fd.type.params) { - DType t = p.identifier.type; - if (auto st = t.asStruct()) + if (auto st = p.asStruct()) { Type pointer = PointerType.Get(llvm(st)); param_types ~= pointer; } - else if (auto ar = t.asArray()) + else if (auto ar = p.asArray()) { Type pointer = PointerType.Get(llvm(ar)); param_types ~= pointer; } else - param_types ~= llvm(t); + param_types ~= llvm(p); } - auto ret_t = fd.identifier.type; + auto ret_t = fd.type.returnType; if(auto st = cast(DStruct)ret_t) ret_t = DType.Void; else if(auto f = cast(DFunction)ret_t) @@ -124,7 +123,7 @@ if(i == 0 && fd.sret) llfunc.addParamAttr(0, ParamAttr.StructRet); - DType t = p.identifier.type; + DType t = fd.type.params[i]; if (auto st = t.asStruct) { if (i == 0 && fd.sret) @@ -598,9 +597,24 @@ +/ case StmtType.For: auto fStmt = cast(ForStmt)stmt; - genStmt(fStmt.init); - scope inc = new ExpStmt(fStmt.incre); - genLoop(stmt.env, fStmt.cond, false, fStmt.forBody, inc); + Stmt[] stmts; + if(fStmt.init) + genStmt(fStmt.init); + ExpStmt inc; + if(fStmt.incre) + stmts ~= new ExpStmt(fStmt.incre); + Exp cond; + if(fStmt.cond) + cond = fStmt.cond; + else + { + auto i = new IntegerLit(fStmt.loc,"1"); + i.number.type = NumberType.Int; + i.number.integer = 1; + cond = i; + } + stmts ~= fStmt.forBody; + genLoop(stmt.env, cond, false, stmts); break; case StmtType.Switch: auto sw = cast(SwitchStmt)stmt; diff -r 4e703658eca0 -r 8ea749b7da91 parser/Parser.d --- a/parser/Parser.d Fri Jul 25 01:40:08 2008 +0200 +++ b/parser/Parser.d Fri Jul 25 10:59:16 2008 +0200 @@ -167,8 +167,9 @@ messages.report(UnexpectedLinkType, t.location); } - require(Tok.CloseParentheses); - + if (!isa(Tok.CloseParentheses)) + messages.report(UnexpectedTokSingle, peek.location); + return e; } diff -r 4e703658eca0 -r 8ea749b7da91 sema/TypeCheck.d --- a/sema/TypeCheck.d Fri Jul 25 01:40:08 2008 +0200 +++ b/sema/TypeCheck.d Fri Jul 25 10:59:16 2008 +0200 @@ -82,6 +82,24 @@ } } } + if (exp.op >= Operator.LeftShift && + exp.op <= Operator.UnsignedRightShift) + {} // FIXME: When we have const-system we need to check for + // right site being larger then the bitsize of the + // left + } + + override void visitDerefExp(DerefExp exp) + { + if (!exp.exp.type.isPointer) + { + messages.report(CanOnlyDerefPointers, + [exp.exp.sourceRange][], + [exp.loc]) + .arg(exp.exp.type.toString); + + exp._type = DType.Int; + } } override void visitCallExp(CallExp exp) @@ -333,6 +351,11 @@ castExp.env = exp.exp.env; exp.exp = castExp; } + + if (expType.isStaticArray) + messages.report(CannotReassignSArray, + [exp.identifier.sourceRange, exp.exp.sourceRange][], + [exp.loc]); } override void visitReturnStmt(ReturnStmt stmt) diff -r 4e703658eca0 -r 8ea749b7da91 tests/code/function_pointer_2.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/code/function_pointer_2.d Fri Jul 25 10:59:16 2008 +0200 @@ -0,0 +1,10 @@ + +int main() +{ + int function(int) f = &foo; + f(); +} + +int foo(int x) +{ +} diff -r 4e703658eca0 -r 8ea749b7da91 tests/parser/for_2.d --- a/tests/parser/for_2.d Fri Jul 25 01:40:08 2008 +0200 +++ b/tests/parser/for_2.d Fri Jul 25 10:59:16 2008 +0200 @@ -1,6 +1,5 @@ - -int main() +void main() { for( ; ; ) { diff -r 4e703658eca0 -r 8ea749b7da91 tests/sema/shift_1.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sema/shift_1.d Fri Jul 25 10:59:16 2008 +0200 @@ -0,0 +1,6 @@ + +int main() +{ + int c; + c << 33; +} diff -r 4e703658eca0 -r 8ea749b7da91 tests/sema/type_check_1.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sema/type_check_1.d Fri Jul 25 10:59:16 2008 +0200 @@ -0,0 +1,7 @@ +//fail +int main() +{ + int function(int s) m; + m = &main; +} +