//not handling function-like macros yet public void invokeMacro(Macro macro) { //Macro.setCurrentMacro(macro, null); }
public static void initMacros() { macroTable = new Dictionary <string, Macro>(); macroList = new List <Macro>(); curMacro = null; }
//- pp token stream handling ------------------------------------------ //handles macro expansion & eof in include files //handle directives in the scanner's fragment stream, will be sent to tokenizer as EOLN fragments public PPToken getPPToken() { PPToken tok = null; while (true) { tok = source.getPPToken(); //Console.WriteLine("pp token = " + tok.ToString()); //check for directive as first non-space frag at start of line if (atLineStart) { if ((tok.type == PPTokenType.PUNCT) && (tok.str[0] == '#')) { handleDirective(); tok = new PPToken(PPTokenType.EOLN, "<eoln>"); //cur pp token will be left as the EOLN at end of directive line } else { atLineStart = (tok.type == PPTokenType.SPACE || tok.type == PPTokenType.COMMENT); } } if ((tok.type == PPTokenType.EOLN) || (tok.type == PPTokenType.EOF)) { atLineStart = true; } //check for a macro if not skipping tokens if (tok.type == PPTokenType.WORD && !skippingTokens) { Macro macro = Macro.lookupMacro(tok.str); if (macro != null) { //invokeMacro(macro); //start macro running continue; //and loop around to get first macro token (if not empty) } } //check if we've hit the end of macro. if this is a macro, pull it off the stack //and resume scanning at the point we stopped in the previous source //note: check for macro end first because a file can contain a macro, but a macro can't include a file if ((tok.type == PPTokenType.EOF) && (macroStack.Count > 0)) { macroStack.RemoveAt(macroStack.Count - 1); if (macroStack.Count > 0) { source = macroStack[macroStack.Count - 1]; } else { source = sourceStack[sourceStack.Count - 1]; } continue; //get next token from including source } //check if we've hit the end of file. if this is an include file, pull it off the stack //and resume scanning at the point we stopped in the including file //we return the EOF token from the main file only if ((tok.type == PPTokenType.EOF) && (sourceStack.Count > 1)) { //Console.WriteLine("closing include file " + sourceStack[sourceStack.Count - 1].filename); sourceStack.RemoveAt(sourceStack.Count - 1); source = sourceStack[sourceStack.Count - 1]; continue; //get next token from including source if not at main file } if (!skippingTokens) { break; } } return(tok); }