public static CreateModifiedStatement ( Boo.Lang.Compiler.Ast.StatementModifier modifier, |
||
modifier | Boo.Lang.Compiler.Ast.StatementModifier | |
node | ||
리턴 |
private void ProcessMacro(Type actualType, MacroStatement node) { // HACK: workaround for mono if (-1 == Array.IndexOf(actualType.GetInterfaces(), typeof(IAstMacro))) // if (!typeof(IAstMacro).IsAssignableFrom(actualType)) { Errors.Add(CompilerErrorFactory.InvalidMacro(node, actualType.FullName)); return; } try { Statement replacement = ExpandMacro(actualType, node); if (null != node.Modifier) { replacement = NormalizeStatementModifiers.CreateModifiedStatement(node.Modifier, replacement); } ReplaceCurrentNode(replacement); } catch (Exception error) { Errors.Add(CompilerErrorFactory.MacroExpansionError(node, error)); } }
override public void OnMacroStatement(MacroStatement node) { Visit(node.Block); Visit(node.Arguments); Statement replacement = null; IEntity entity = NameResolutionService.ResolveQualifiedName(BuildMacroTypeName(node.Name)); if (null == entity) { entity = NameResolutionService.ResolveQualifiedName(node.Name); } if (null == entity) { Errors.Add(CompilerErrorFactory.UnknownMacro(node, node.Name)); } else { if (EntityType.Type != entity.EntityType) { Errors.Add(CompilerErrorFactory.InvalidMacro(node, node.Name)); } else { IType macroType = (IType)entity; ExternalType type = macroType as ExternalType; if (null == type) { Errors.Add(CompilerErrorFactory.AstMacroMustBeExternal(node, macroType.FullName)); } else { object macroInstance = Activator.CreateInstance(type.ActualType); if (!(macroInstance is IAstMacro)) { Errors.Add(CompilerErrorFactory.InvalidMacro(node, macroType.FullName)); } else { try { using (IAstMacro macro = ((IAstMacro)macroInstance)) { macro.Initialize(_context); replacement = macro.Expand(node); } } catch (Exception error) { Errors.Add(CompilerErrorFactory.MacroExpansionError(node, error)); } } } } } if (null != node.Modifier) { replacement = NormalizeStatementModifiers.CreateModifiedStatement(node.Modifier, replacement); } ReplaceCurrentNode(replacement); }