public BasicCppMacro(Token token) { Add (token); }
private void ParseCppMessage(Token directive, bool fatal) { var message = new TokenList (ConsumeCppDirective ()); LogWarning (directive, message.ToString ()); if (fatal) { throw new ApplicationException ("#error directive reached"); } }
private void UnexpectedToken(TokenType expected, Token got) { throw new ApplicationException (String.Format ("Unexpected token {0} at [{1}:{2}]; expected {3}", got.Type, got.SourceLine, got.SourceColumn, expected)); }
private void ParseCppDefine(Token define) { CppMacro old_macro = null; var new_name_token = CheckScan (TokenType.Identifier); var name = (string)new_name_token.Value; var new_macro = new CppMacro (ConsumeCppDirective ()) { Parent = new_name_token, InputName = InputName }; if (ParserState.CppDefines.TryGetValue (name, out old_macro)) { LogWarning (define, String.Format ("\"{0}\" redefined", name)); LogWarning (old_macro.InputName, old_macro.Parent, "this is the location of the previous definition"); ParserState.CppDefines[name] = new_macro; } else { ParserState.CppDefines.Add (name, new_macro); } }
private void LogWarning(string inputFile, Token offender, string message) { Console.Error.WriteLine ("{0}:{1}:{2}: warning: {3}", PwdRelativePath (inputFile) ?? "Unknown", offender.SourceLine, offender.SourceColumn, message); }
private void LogWarning(Token offender, string message) { LogWarning (InputName, offender, message); }
private IEnumerable<Token> ExpandToken(Token token) { if (token.Type != TokenType.Identifier) { yield return token; } else { CppMacro macro = null; if (ParserState.CppDefines.TryGetValue ((string)token.Value, out macro)) { foreach (var node in macro) { foreach (var expanded_node in ExpandToken (node)) { yield return expanded_node; } } } else { yield return token; } } }
public void SetBasicMacro(string name, Token value) { SetBasicMacro (name, new BasicCppMacro (value)); }