Ver código fonte

Move def-type-alias into Cakelisp

It now supports global vs. local
GeneralDependencyResolver
Macoy Madson 3 meses atrás
pai
commit
68106675d2
2 arquivos alterados com 70 adições e 22 exclusões
  1. +23
    -22
      runtime/Macros.cake
  2. +47
    -0
      src/Generators.cpp

+ 23
- 22
runtime/Macros.cake Ver arquivo

@ -39,32 +39,33 @@
(return true))
;; The first significant generator written in Cakelisp!
(defgenerator def-type-alias ()
(destructure-arguments name-index type-index)
(quick-token-at name-token name-index)
(quick-token-at invocation-token (+ 1 startTokenIndex))
;; Now built-in
;; (defgenerator def-type-alias ()
;; (destructure-arguments name-index type-index)
;; (quick-token-at name-token name-index)
;; (quick-token-at invocation-token (+ 1 startTokenIndex))
;; Make sure the type is valid before outputting anything
(var type-output (<> std::vector StringOutput))
(var type-after-name-output (<> std::vector StringOutput))
(unless (tokenizedCTypeToString_Recursive tokens type-index true type-output type-after-name-output)
(return false))
(addModifierToStringOutput (on-call type-output back) StringOutMod_SpaceAfter)
;; ;; Make sure the type is valid before outputting anything
;; (var type-output (<> std::vector StringOutput))
;; (var type-after-name-output (<> std::vector StringOutput))
;; (unless (tokenizedCTypeToString_Recursive tokens type-index true type-output type-after-name-output)
;; (return false))
;; (addModifierToStringOutput (on-call type-output back) StringOutMod_SpaceAfter)
(addStringOutput (field output source) "typedef" StringOutMod_SpaceAfter (addr invocation-token))
;; TODO: Add ability to define typedefs in header
(PushBackAll (field output source) type-output)
;; (addStringOutput (field output source) "typedef" StringOutMod_SpaceAfter (addr invocation-token))
;; ;; TODO: Add ability to define typedefs in header
;; (PushBackAll (field output source) type-output)
;; Evaluate name
(var expressionContext EvaluatorContext context)
(set (field expressionContext scope) EvaluatorScope_ExpressionsOnly)
(unless (= 0 (EvaluateGenerate_Recursive environment expressionContext tokens name-index output))
(return false))
;; ;; Evaluate name
;; (var expressionContext EvaluatorContext context)
;; (set (field expressionContext scope) EvaluatorScope_ExpressionsOnly)
;; (unless (= 0 (EvaluateGenerate_Recursive environment expressionContext tokens name-index output))
;; (return false))
;; Yep, believe it or not, C typedefs have the length of the array after the new type name
(PushBackAll (field output source) type-after-name-output)
(addLangTokenOutput (field output source) StringOutMod_EndStatement (addr invocation-token))
(return true))
;; ;; Yep, believe it or not, C typedefs have the length of the array after the new type name
;; (PushBackAll (field output source) type-after-name-output)
;; (addLangTokenOutput (field output source) StringOutMod_EndStatement (addr invocation-token))
;; (return true))
(defmacro array-size ()
(destructure-arguments array-index)


+ 47
- 0
src/Generators.cpp Ver arquivo

@ -927,6 +927,50 @@ bool ObjectPathGenerator(EvaluatorEnvironment& environment, const EvaluatorConte
return true;
}
static bool DefTypeAliasGenerator(EvaluatorEnvironment& environment,
const EvaluatorContext& context, const std::vector<Token>& tokens,
int startTokenIndex, GeneratorOutput& output)
{
int destrEndInvocationIndex = FindCloseParenTokenIndex(tokens, startTokenIndex);
int nameIndex =
getExpectedArgument("name-index", tokens, startTokenIndex, 1, destrEndInvocationIndex);
if (-1 == nameIndex)
return false;
int typeIndex =
getExpectedArgument("type-index", tokens, startTokenIndex, 2, destrEndInvocationIndex);
if (-1 == typeIndex)
return false;
const Token& nameToken = tokens[nameIndex];
const Token& invocationToken = tokens[1 + startTokenIndex];
bool isGlobal = invocationToken.contents.compare("def-type-alias-global") == 0;
std::vector<StringOutput> typeOutput;
std::vector<StringOutput> typeAfterNameOutput;
if (!(tokenizedCTypeToString_Recursive(tokens, typeIndex, true, typeOutput,
typeAfterNameOutput)))
{
return false;
}
addModifierToStringOutput(typeOutput.back(), StringOutMod_SpaceAfter);
std::vector<StringOutput>& outputDest = isGlobal ? output.header : output.source;
addStringOutput(outputDest, "typedef", StringOutMod_SpaceAfter, &invocationToken);
PushBackAll(outputDest, typeOutput);
EvaluatorContext expressionContext = context;
expressionContext.scope = EvaluatorScope_ExpressionsOnly;
int numErrors =
EvaluateGenerate_Recursive(environment, expressionContext, tokens, nameIndex, output);
if (numErrors)
return false;
PushBackAll(outputDest, typeAfterNameOutput);
addLangTokenOutput(outputDest, StringOutMod_EndStatement, &invocationToken);
return true;
}
// I'm not too happy with this
static void tokenizeGenerateStringTokenize(const char* outputVarName, const Token& triggerToken,
const char* stringToTokenize, GeneratorOutput& output)
@ -1549,6 +1593,9 @@ void importFundamentalGenerators(EvaluatorEnvironment& environment)
environment.generators["def-function-signature"] = DefFunctionSignatureGenerator;
environment.generators["def-function-signature-local"] = DefFunctionSignatureGenerator;
environment.generators["def-type-alias"] = DefTypeAliasGenerator;
environment.generators["def-type-alias-global"] = DefTypeAliasGenerator;
environment.generators["defmacro"] = DefMacroGenerator;
environment.generators["defgenerator"] = DefGeneratorGenerator;


Carregando…
Cancelar
Salvar