Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (59 sloc) 2.05 KB
#region License
// Copyright Jeremy Skinner ( and Contributors
// Licensed under the Microsoft Public License. You may
// obtain a copy of the license at:
// By using this source code in any fashion, you are agreeing
// to be bound by the terms of the Microsoft Public License.
// You must not remove this notice, or any other, from this software.
namespace Phantom.Core.Language {
using System.IO;
using System.Linq;
using Boo.Lang.Compiler.Ast;
using Boo.Lang.Compiler.Steps;
public class IncludeSupportStep : AbstractTransformerCompilerStep {
readonly IIncludeCompiler compiler;
public IncludeSupportStep(IIncludeCompiler compiler) {
this.compiler = compiler;
public override void Run() {
public override void OnMacroStatement(MacroStatement node) {
if (node.Name == "include")
void ExpandIncludeMacro(MacroStatement macro) {
if (macro.Arguments.Count != 1)
throw new ScriptParsingException("include requires a single literal string argument ('filename').");
var include = macro.Arguments[0] as StringLiteralExpression;
if (include == null)
throw new ScriptParsingException("include argument should be a literal string ('filename').");
var fullPath = Path.Combine(
var compiled = compiler.CompileInclude(fullPath).CompileUnit.Modules[0];
var module = macro.GetAncestor<Module>();
foreach (var import in compiled.Imports) {
var type = macro.GetAncestor<TypeDefinition>();
foreach (var member in compiled.Members) {
var parent = (Block) macro.ParentNode;
var currentPosition = parent.Statements.IndexOf(macro);
foreach (var global in compiled.Globals.Statements.Reverse()) {
parent.Insert(currentPosition, global);
You can’t perform that action at this time.