Mercurial > projects > dil
changeset 837:110f741dab45
Consolidated type rules table generation code into one file.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Thu, 14 Aug 2008 03:14:43 +0200 |
parents | e7cb5e38d567 |
children | 1ecf05e680ba |
files | README src/TypeRules.d src/TypeRulesData.d src/TypeRulesGenerator.d |
diffstat | 4 files changed, 148 insertions(+), 241 deletions(-) [+] |
line wrap: on
line diff
--- a/README Tue Aug 12 21:25:14 2008 +0200 +++ b/README Thu Aug 14 03:14:43 2008 +0200 @@ -11,7 +11,7 @@ How To Compile dil ================== In order to compile dil you need to have: - *) DMD 1.033 (http://www.digitalmars.com/d/1.0/changelog.html) + *) DMD 1.034 (http://www.digitalmars.com/d/1.0/changelog.html) *) Tango 0.99.7 (http://dsource.org/projects/tango/) *) DSSS 0.75 (http://dsource.org/projects/dsss/)
--- a/src/TypeRules.d Tue Aug 12 21:25:14 2008 +0200 +++ b/src/TypeRules.d Thu Aug 14 03:14:43 2008 +0200 @@ -1,73 +1,14 @@ -#! /usr/bin/rdmd +#!/usr/bin/rdmd /++ Author: Aziz Köksal License: GPL3 +/ module TypeRules; -import TypeRulesData; -import cmd.Highlight : xml_escape; - -import common; +import tango.io.Stdout; void main(char[][] args) { - genHTMLTypeRulesTables(); -} - -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[] unaryExpressions = [ - "!x", - "&x", - "~x", - "+x", - "-x", - "++x", - "--x", - "x++", - "x--", -]; - -static const string[] binaryExpressions = [ - "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", - "x~=y", - "x~y", - "x,y" -]; - -void genHTMLTypeRulesTables() -{ Stdout( `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">`\n `<html>`\n @@ -82,10 +23,11 @@ ` </style>`\n `</head>`\n `<body>`\n - `<p>The following tables show the type results of different expressions. Compiler used: ` ~ - compilerNameVersion ~ `.` + `<p>The following tables show the type results of different expressions. Compiler used: ` ); + Stdout.format("{} {}.{,:d3}.</p>\n", __VENDOR__, __VERSION__/1000, __VERSION__%1000); + Stdout.format("<table>\n<tr><th colspan=\"{}\">Unary Expressions</th></tr>\n", unaryExpressions.length); Stdout("<tr><td><!--typecol--></td>"); foreach (unaryExpression; unaryExpressions) @@ -134,3 +76,145 @@ "\n</html>" ); } + +/// Escapes the characters '<', '>' and '&' with named character entities. +/// Taken from module cmd.Highlight; +char[] xml_escape(char[] text) +{ + char[] result; + foreach(c; text) + switch(c) + { + case '<': result ~= "<"; break; + case '>': result ~= ">"; break; + case '&': result ~= "&"; break; + default: result ~= c; + } + if (result.length != text.length) + return result; + // Nothing escaped. Return original text. + delete result; + return text; +} + +char char_; wchar wchar_; dchar dchar_; bool bool_; +byte byte_; ubyte ubyte_; short short_; ushort ushort_; +int int_; uint uint_; long long_; ulong ulong_; +/+cent cent_; ucent ucent_;+/ +float float_; double double_; real real_; +ifloat ifloat_; idouble idouble_; ireal ireal_; +cfloat cfloat_; cdouble cdouble_; creal creal_; + +static const char[][] 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 char[][] unaryExpressions = [ + "!x", + "&x", + "~x", + "+x", + "-x", + "++x", + "--x", + "x++", + "x--", +]; + +static const char[][] binaryExpressions = [ + "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", + "x~=y", + "x~y", + "x,y" +]; + +template ExpressionType(alias x, alias y, char[] expression) +{ + static if(is(typeof(mixin(expression)) ResultType)) + const char[] result = ResultType.stringof; + else + const char[] result = "Error"; +} +alias ExpressionType EType; + +char[] genBinaryExpArray(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; +} +// pragma(msg, mixin(genBinaryExpArray("x%y")).stringof); + +char[] genBinaryExpsArray() +{ + char[] result = "[\n"; + foreach (expression; binaryExpressions) + { + result ~= genBinaryExpArray(expression); + result ~= ",\n"; + } + result[result.length-2] = ']'; + return result; +} + +// pragma(msg, mixin(genBinaryExpsArray()).stringof); + +char[] genUnaryExpArray(char[] expression) +{ + char[] result = "[\n"; + foreach (t1; basicTypes) + result ~= `EType!(`~t1~`_, int_, "`~expression~`").result,`\n; + result[result.length-2] = ']'; // Overwrite last comma. + return result; +} + +char[] genUnaryExpsArray() +{ + char[] result = "[\n"; + foreach (expression; unaryExpressions) + result ~= genUnaryExpArray(expression) ~ ",\n"; + result[result.length-2] = ']'; + return result; +} + +// pragma(msg, mixin(genUnaryExpsArray()).stringof); + +auto unaryExpsResults = mixin(genUnaryExpsArray()); +auto binaryExpsResults = mixin(genBinaryExpsArray()); +
--- a/src/TypeRulesData.d Tue Aug 12 21:25:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -// Run TypeRulesGenerator.d
--- a/src/TypeRulesGenerator.d Tue Aug 12 21:25:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -#! /usr/bin/rdmd -/++ - Author: Aziz Köksal - License: GPL3 -+/ -module TypeRulesGenerator; - -import tango.io.File; -import tango.io.FilePath; -import common; - -alias char[] string; - -void main(char[][] args) -{ - char[] text = "/// Generated by TypeRulesGenerator.d\n" - "module TypeRulesData;\n\n"; - text ~= Format(`const char[] compilerNameVersion = "{} {}.{,:d3}";`\n\n, - __VENDOR__, __VERSION__/1000, __VERSION__%1000); - text ~= "char[][][] unaryExpsResults = [\n"; - foreach (results; unaryExpsResults) - { - text ~= " ["; - foreach (result; results) - text ~= '"' ~ result ~ `", `; - text.length = text.length - 2; - text ~= "],\n"; - } - text.length = text.length - 2; - text ~= "\n];\n\n"; - - text ~= "char[][][][] binaryExpsResults = [\n"; - foreach (expResults; binaryExpsResults) - { - text ~= " [\n"; - foreach (results; expResults) - { - text ~= " ["; - foreach (result; results) - text ~= '"' ~ result ~ `", `; - text.length = text.length - 2; - text ~= "],\n"; - } - text.length = text.length - 2; - text ~= "\n ],\n"; - } - text.length = text.length - 2; - text ~= "\n];\n"; - - // Write the text to a D module. - auto file = new File("TypeRulesData.d"); - file.write(text); -} - -template ExpressionType(alias x, alias y, char[] expression) -{ - 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"+/ -]; - -char char_; wchar wchar_; dchar dchar_; bool bool_; -byte byte_; ubyte ubyte_; short short_; ushort ushort_; -int int_; uint uint_; long long_; ulong ulong_; -/+cent cent_; ucent ucent_;+/ -float float_; double double_; real real_; -ifloat ifloat_; idouble idouble_; ireal ireal_; -cfloat cfloat_; cdouble cdouble_; creal creal_; - -static const string[] unaryExpressions = [ - "!x", - "&x", - "~x", - "+x", - "-x", - "++x", - "--x", - "x++", - "x--", -]; - -static const string[] binaryExpressions = [ - "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", - "x~=y", - "x~y", - "x,y" -]; - -char[] genBinaryExpArray(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; -} -// pragma(msg, mixin(genBinaryExpArray("x%y")).stringof); - -char[] genBinaryExpsArray() -{ - char[] result = "[\n"; - foreach (expression; binaryExpressions) - { - result ~= genBinaryExpArray(expression); - result ~= ",\n"; - } - result[result.length-2] = ']'; - return result; -} - -// pragma(msg, mixin(genBinaryExpsArray()).stringof); - -char[] genUnaryExpArray(char[] expression) -{ - char[] result = "[\n"; - foreach (t1; basicTypes) - result ~= `EType!(`~t1~`_, int_, "`~expression~`").result,`\n; - result[result.length-2] = ']'; // Overwrite last comma. - return result; -} - -char[] genUnaryExpsArray() -{ - char[] result = "[\n"; - foreach (expression; unaryExpressions) - result ~= genUnaryExpArray(expression) ~ ",\n"; - result[result.length-2] = ']'; - return result; -} - -// pragma(msg, mixin(genUnaryExpsArray()).stringof); - -auto unaryExpsResults = mixin(genUnaryExpsArray()); -auto binaryExpsResults = mixin(genBinaryExpsArray());