# HG changeset patch # User Aziz K?ksal # Date 1204074779 -3600 # Node ID 05dfe88dd3bbb59fc40aca8d3e0736e9e5b1359a # Parent 5fe89bb8cbdd12035fa6af83a291b6fb22dd2982 Added new module TypeRules. diff -r 5fe89bb8cbdd -r 05dfe88dd3bb trunk/src/TypeRules.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/TypeRules.d Wed Feb 27 02:12:59 2008 +0100 @@ -0,0 +1,99 @@ +/++ + Author: Aziz Köksal + License: GPL3 ++/ +module TypeRules; + +import common; + +template ExpressionType(char[] T1, char[] T2, char[] expression) +{ + mixin("alias "~T1~" X;"); + mixin("alias "~T2~" Y;"); + X x; + Y y; + static if(is(typeof(mixin(expression)) ResultType)) + const char[] result = ResultType.stringof; + else + const char[] result = "Error"; +} +alias ExpressionType EType; + +// pragma(msg, EType!("char", "int", "&x").result); + +static const string[] basicTypes = [ + "char"[], "wchar", "dchar", "bool", + "byte", "ubyte", "short", "ushort", + "int", "uint", "long", "ulong", + /+"cent", "ucent",+/ + "float", "double", "real", + "ifloat", "idouble", "ireal", + "cfloat", "cdouble", "creal"/+, "void"+/ +]; + +static const string[] unaExpressions = [ + "!x", + "&x", + "~x", + "+x", + "-x", + "++x", + "--x", + "x++", + "x--", +]; + +static const string[] binExpressions = [ + "x!<>=y", + "x!<>y", + "x!<=y", + "x!=y", + "x!>y", + "x<>=y", + "x<>y", + + "x=y", "x==y", "x!=y", + "x<=y", "x=y", "x>y", + "x<<=y", "x<>=y","x>>y", + "x>>>=y", "x>>>y", + "x|=y", "x||y", "x|y", + "x&=y", "x&&y", "x&y", + "x+=y", "x+y", + "x-=y", "x-y", + "x/=y", "x/y", + "x*=y", "x*y", + "x%=y", "x%y", + "x^=y", "x^y", + "x~=y", + "x~y", + "x,y" +]; + +char[] genBinExpArray(char[] expression) +{ + char[] result = "[\n"; + foreach (t1; basicTypes) + { + result ~= "[\n"; + foreach (t2; basicTypes) + result ~= `EType!("`~t1~`", "`~t2~`", "`~expression~`").result,`\n; + result[result.length-2] = ']'; // Overwrite last comma. + result[result.length-1] = ','; // Overwrite last \n. + } + result[result.length-1] = ']'; // Overwrite last comma. + return result; +} + +char[] genUnaExpArray(char[] expression) +{ + char[] result = "[\n"; + foreach (t1; basicTypes) + result ~= `EType!("`~t1~`", "int", "`~expression~`").result,`\n; + result[result.length-2] = ']'; // Overwrite last comma. + return result; +} + +// pragma(msg, mixin(genBinExpArray("x+y")).stringof); diff -r 5fe89bb8cbdd -r 05dfe88dd3bb trunk/src/dil/ast/Node.d --- a/trunk/src/dil/ast/Node.d Tue Feb 26 20:13:41 2008 +0100 +++ b/trunk/src/dil/ast/Node.d Wed Feb 27 02:12:59 2008 +0100 @@ -91,8 +91,8 @@ byte_t[] data = (cast(byte_t*)this)[0..size].dup; return cast(Node)data.ptr; } + + /// This string is mixed into the constructor of a class that inherits + /// from Node. It sets the member kind. + const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; } - -/// This string is mixed into the constructor of a class that inherits -/// from Node. It sets the member kind. -const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; diff -r 5fe89bb8cbdd -r 05dfe88dd3bb trunk/src/main.d --- a/trunk/src/main.d Tue Feb 26 20:13:41 2008 +0100 +++ b/trunk/src/main.d Wed Feb 27 02:12:59 2008 +0100 @@ -31,6 +31,7 @@ import Settings; import SettingsLoader; +// import TypeRules; import common; import Integer = tango.text.convert.Integer; @@ -468,7 +469,7 @@ The directory of file.d is implicitly added to the list of import paths. Format: - --dot : generate a dot document + --dot : generate a dot document (default) Options related to --dot: -gbp : Group modules by package names -gbf : Group modules by full package name @@ -493,7 +494,8 @@ -i : include unlocatable modules Example: - dil igraph src/main.d`; + dil igraph src/main.d --list + dil igraph src/main.d | dot -Tpng > main.png`; break; case "tok", "tokenize": msg = `Print the tokens of a D source file.