Very basic stuff working on linux 32-bit with dmd and phobos2.
This commit is contained in:
parent
f23eee9828
commit
67f0225e42
152 changed files with 113 additions and 0 deletions
130
tests/FullSkeleton/libraryA/mixins/BladeParse.d
Normal file
130
tests/FullSkeleton/libraryA/mixins/BladeParse.d
Normal file
|
@ -0,0 +1,130 @@
|
|||
/**
|
||||
*
|
||||
* BladeParse
|
||||
*
|
||||
* Thanks to the <a href="http://www.dsource.org/projects/mathextra/">mathextra</a> project for this!
|
||||
*
|
||||
* Original source <a href="http://www.dsource.org/projects/mathextra/browser/trunk/blade/BladeParse.d">here</a>.
|
||||
**/
|
||||
|
||||
module libraryA.mixins.BladeParse;
|
||||
|
||||
// General utilities.
|
||||
char [] itoa(T)(T x)
|
||||
{
|
||||
char [] s="";
|
||||
static if (is(T==byte)||is(T==short)||is(T==int)||is(T==long)) {
|
||||
if (x<0) {
|
||||
s = "-";
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
do {
|
||||
s = cast(char)('0' + (x%10)) ~ s;
|
||||
x/=10;
|
||||
} while (x>0);
|
||||
return s;
|
||||
}
|
||||
|
||||
bool isDigit(char c) { return c>='0' && c<='9'; }
|
||||
bool isHexDigit(char c) { return c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F'; }
|
||||
bool isAlpha(char c) {
|
||||
return (c>='a' && c<='z') || (c>='A' && c<='Z');
|
||||
}
|
||||
// Underscores allowed
|
||||
bool isUnderscoreDigit(char c) { return c=='_' || c>='0' && c<='9'; }
|
||||
bool isUnderscoreHexDigit(char c) { return c=='_' || c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F'; }
|
||||
bool isUnderscoreAlpha(char c) {
|
||||
return c=='_' || (c>='a' && c<='z') || (c>='A' && c<='Z');
|
||||
}
|
||||
|
||||
unittest {
|
||||
assert(isHexDigit('9'));
|
||||
}
|
||||
|
||||
// Extract a D identifier. Return the remainder of the string.
|
||||
char [] parseIdentifier(char [] s, out char [] rest)
|
||||
{
|
||||
int i=0;
|
||||
if (!isUnderscoreAlpha(s[0])) { assert(0, "Identifier expected"); }
|
||||
while (i<s.length && (isUnderscoreAlpha(s[i])||isDigit(s[i]))) ++i;
|
||||
char [] ident=s[0..i];
|
||||
while (i<s.length && s[i]==' ') ++i; // skip trailing spaces
|
||||
rest = s[i..$];
|
||||
return ident;
|
||||
}
|
||||
|
||||
char [] parseNumber(char [] s, out char[] rest)
|
||||
{
|
||||
int k=0;
|
||||
while(k<s.length && isDigit(s[k])) ++k;
|
||||
if (k<s.length-1 && s[k]=='.' && s[k+1]!='.') {
|
||||
++k;
|
||||
while(k<s.length && isDigit(s[k])) ++k;
|
||||
if (k<s.length && s[k]=='e') { ++k;
|
||||
if (k<s.length && (s[k]=='+' || s[k]=='-')) ++k;
|
||||
while(k<s.length && isDigit(s[k])) ++k;
|
||||
}
|
||||
if (k<s.length && (s[k]=='L' || s[k]=='f')) ++k;
|
||||
}
|
||||
char [] ident = s[0..k];
|
||||
int i=k;
|
||||
while (i<s.length && s[i]==' ') ++i; // skip trailing spaces
|
||||
rest = s[i..$];
|
||||
return ident;
|
||||
}
|
||||
|
||||
char [] parseOperator(char [] s, out char [] rest)
|
||||
{
|
||||
int i=1;
|
||||
if (s[0]=='+' || s[0]=='-' || s[0]=='*') {
|
||||
if (s.length>1 && s[1]=='=') ++i;
|
||||
int k=i;
|
||||
while (k<s.length && s[k]==' ') ++k; // skip trailing spaces
|
||||
rest = s[k..$];
|
||||
return s[0..i];
|
||||
} else {
|
||||
assert(0, `Operator expected, not "` ~ s~ `"`);
|
||||
}
|
||||
}
|
||||
|
||||
char [] parseQualifiedName(char [] s, out char[] rest)
|
||||
{
|
||||
char [] r;
|
||||
char [] id = parseIdentifier(s, r);
|
||||
while (r.length>0 && r[0]=='.') {
|
||||
int i;
|
||||
for (i=1; r[i]==' '; ++i) {}
|
||||
id ~= "." ~ parseIdentifier(r[i..$], r);
|
||||
}
|
||||
rest=r;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
// Some functions to grab information from the typestring.
|
||||
|
||||
// Return the first index in the tuple which is of vector type
|
||||
int findFirstVector(char [][] typelist)
|
||||
{
|
||||
for (int i=0; i< typelist.length;++i) {
|
||||
if (isVector(typelist[i])) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isVector(char [] typestr)
|
||||
{
|
||||
return (typestr[0]=='V' || typestr[0]=='Z');
|
||||
}
|
||||
|
||||
// Count the number of vectors in the typestring
|
||||
int countVectors(char [][] typelist)
|
||||
{
|
||||
int numVecs=0;
|
||||
for (int i=0; i<typelist.length; ++i) {
|
||||
if (isVector(typelist[i])) ++numVecs;
|
||||
}
|
||||
return numVecs;
|
||||
}
|
||||
|
44
tests/FullSkeleton/libraryA/mixins/HandyMixinHelpers.d
Normal file
44
tests/FullSkeleton/libraryA/mixins/HandyMixinHelpers.d
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
*
|
||||
* Handy Mixin Helpers
|
||||
*
|
||||
* Authors: Tim Burrell
|
||||
* Copyright: Copyright (c) 2007
|
||||
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
|
||||
*
|
||||
**/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Module
|
||||
///////////////////////////////////////
|
||||
|
||||
module libraryA.mixins.HandyMixinHelpers;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Imports
|
||||
///////////////////////////////////////
|
||||
|
||||
import libraryA.mixins.BladeParse;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Mixin Helpers (like not useful on their own)
|
||||
///////////////////////////////////////
|
||||
|
||||
/// for use with enumConditional
|
||||
char [] createEnumConditionalLoop(int Size) {
|
||||
char [] ret = "bool NeedsComma = false;\n";
|
||||
for (int lp = 1; lp < Size; lp += 2) {
|
||||
char [] curVal = itoa(lp);
|
||||
char [] curValMinus1 = itoa(lp - 1);
|
||||
ret ~= "if ( (T.length > " ~ curVal ~") && (T[" ~ curVal ~ "]) ) {";
|
||||
if (lp > 1) {
|
||||
ret ~= " if (NeedsComma) {"
|
||||
" ret ~= \",\n\";"
|
||||
" }";
|
||||
}
|
||||
ret ~= " ret ~= \"\t\" ~ T[" ~ curValMinus1 ~ "];"
|
||||
" NeedsComma = true;"
|
||||
"}";
|
||||
}
|
||||
return ret;
|
||||
}
|
103
tests/FullSkeleton/libraryA/mixins/HandyMixins.d
Normal file
103
tests/FullSkeleton/libraryA/mixins/HandyMixins.d
Normal file
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
*
|
||||
* Handy Mixins
|
||||
*
|
||||
* Authors: Tim Burrell
|
||||
* Copyright: Copyright (c) 2007
|
||||
* License: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
|
||||
*
|
||||
**/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Module
|
||||
///////////////////////////////////////
|
||||
|
||||
module libraryA.mixins.HandyMixins;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Imports
|
||||
///////////////////////////////////////
|
||||
|
||||
import libraryA.mixins.HandyMixinHelpers;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Mixins
|
||||
///////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Auto build class member
|
||||
*
|
||||
* Params: Type = Type of the property
|
||||
* Name = Name of the property
|
||||
* Returns: String containing the resulting property
|
||||
**/
|
||||
template prop(Type, char [] Name) {
|
||||
const char [] prop = "private " ~ Type.stringof ~ " " ~ Name ~ ";" ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto build setter
|
||||
*
|
||||
* Params: Type = Type of the property
|
||||
* Name = Name of the property
|
||||
* Returns: String containing the resulting property
|
||||
**/
|
||||
template propWrite(Type, char [] Name) {
|
||||
const char [] propWrite = "void set" ~ Name ~ "(inout " ~ Type.stringof ~ " The" ~ Name ~ ") { "
|
||||
~ Name ~ " = The" ~ Name ~ "; }; \n\n"
|
||||
~ prop!(Type, Name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto build getter
|
||||
*
|
||||
* Params: Type = Type of the property
|
||||
* Name = Name of the property
|
||||
* Returns: String containing the resulting property
|
||||
*
|
||||
* Bugs: Not Implemented!
|
||||
**/
|
||||
template propRead(Type, char [] Name) {
|
||||
const char [] propRead = "void set" ~ Name ~ "(inout " ~ Type.stringof ~ " The" ~ Name ~ ") { "
|
||||
~ Name ~ " = The" ~ Name ~ "; }; \n\n"
|
||||
~ prop!(Type, Name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally construct an enum
|
||||
*
|
||||
* Params: Name = Name of the enum
|
||||
* T = Enum elements and their conditions
|
||||
* Returns: String containing the resulting enum
|
||||
*
|
||||
* Example:
|
||||
* -------------------------------------------------------------------------
|
||||
* const char [] RENDERER_CURSES = "False";
|
||||
* const char [] RENDERER_VT102 = "True";
|
||||
* const char [] RENDERER_X11 = "True";
|
||||
*
|
||||
* mixin(enumConditional!("RendererClass",
|
||||
* "RendererCurses", RENDERER_CURSES == "True",
|
||||
* "RendererVT102", RENDERER_VT102 == "True",
|
||||
* "RendererX11", RENDERER_X11 == "True"
|
||||
* ).createEnum());
|
||||
* -------------------------------------------------------------------------
|
||||
* Would result in the following enum:
|
||||
* -------------------------------------------------------------------------
|
||||
* enum {
|
||||
* RendererVT102,
|
||||
* RendererX11
|
||||
* }
|
||||
* -------------------------------------------------------------------------
|
||||
* Obviously, this is all done at compile time.
|
||||
**/
|
||||
|
||||
template enumConditional(char [] Name, T...) {
|
||||
//alias T tupleof;
|
||||
char [] createEnum() {
|
||||
char [] ret = "enum " ~ Name ~ " {\n";
|
||||
mixin(createEnumConditionalLoop(T.length));
|
||||
return ret ~ "\n}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue