本文整理汇总了C#中Boo.Lang.Compiler.Ast.MacroStatement类的典型用法代码示例。如果您正苦于以下问题:C# MacroStatement类的具体用法?C# MacroStatement怎么用?C# MacroStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MacroStatement类属于Boo.Lang.Compiler.Ast命名空间,在下文中一共展示了MacroStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Expand
/// <summary>
/// Expands the specified macro.
/// </summary>
/// <param name="macro">The macro.</param>
/// <returns></returns>
public override Statement Expand(MacroStatement macro)
{
Property property = new Property(propertyName);
property.LexicalInfo = macro.LexicalInfo;
property.Getter = new Method();
if(macro.Arguments.Count==1)
{
property.Getter.Body.Add(
new ReturnStatement(macro.Arguments[0])
);
}
else if(
macro.Arguments.Count == 0 &&
macro.Body != null &&
macro.Body.IsEmpty == false)//use the macro block
{
property.Getter.Body = macro.Body;
}
else
{
CompilerErrorFactory.CustomError(macro.LexicalInfo,
macro.Name + " must have a single expression argument or a block");
return null;
}
ClassDefinition clazz = (ClassDefinition) macro.GetAncestor(NodeType.ClassDefinition);
clazz.Members.Add(property);
return null;
}
示例2: PromoteExtensions
protected static void PromoteExtensions(MacroStatement macro, MacroStatement parent)
{
ApplyExtensions(macro, delegate(Expression extension)
{
RegisterExtension(parent, extension);
});
}
示例3: OnMacroStatement
public override void OnMacroStatement(MacroStatement node)
{
using (enter()){
defaultProcess(node);
base.OnMacroStatement(node);
}
}
示例4: MacroCompilerIsTakenFromTheEnvironment
public void MacroCompilerIsTakenFromTheEnvironment()
{
var compiler = new Mock<MacroCompiler>(MockBehavior.Strict);
ActiveEnvironment.With(CompilerContextEnvironmentWith(compiler), ()=>
{
var module = CreateModule();
var macroApplication = new MacroStatement(new LexicalInfo("file.boo", 1, 1), "foo");
module.Globals.Add(macroApplication);
var macroDefinition = CreateClassOn(module, "FooMacro");
compiler.Setup(o => o.AlreadyCompiled(macroDefinition)).Returns(false);
compiler.Setup(o => o.Compile(macroDefinition)).Returns((Type)null);
var expander = My<MacroExpander>.Instance;
Assert.IsFalse(expander.ExpandAll());
var errors = CompilerErrors();
Assert.AreEqual(1, errors.Count);
Assert.AreEqual(CompilerErrorFactory.AstMacroMustBeExternal(macroApplication, (IType) macroDefinition.Entity).ToString(), errors[0].ToString());
});
compiler.VerifyAll();
}
示例5: UnescapeInitialAndClosingDoubleQuotes
private static void UnescapeInitialAndClosingDoubleQuotes(MacroStatement macro){
var value = macro.Arguments[0] as StringLiteralExpression;
if (value == null){
return;
}
value.Value = BrailPreProcessor.UnescapeInitialAndClosingDoubleQuotes(value.Value);
}
示例6: ExpandImpl
protected override Statement ExpandImpl(MacroStatement macro){
if (macro.Arguments.Count == 0){
Context.Errors.Add(new CompilerError(macro.LexicalInfo,
"sub macro requires at least one reference or string attribute for subview name"));
}
var call = new MethodInvocationExpression(AstUtil.CreateReferenceExpression("OutputSubView"));
int i = 0;
foreach (Expression argument in macro.Arguments){
i++;
Expression exp = argument;
if (i == 1){
//action and contrller parameters
if (argument is ReferenceExpression && !(argument is MemberReferenceExpression)){
if (argument.ToCodeString().StartsWith("@") || argument.ToCodeString().Contains(".")){
exp = AstUtil.CreateReferenceExpression(argument.ToCodeString().Substring(1));
}
else{
exp = new StringLiteralExpression(argument.ToCodeString());
}
}
}
call.Arguments.Add(exp);
}
return new ExpressionStatement(call);
}
示例7: ExpandIncludeMacro
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(
Path.GetDirectoryName(macro.LexicalInfo.FullPath),
include.Value
);
var compiled = compiler.CompileInclude(fullPath).CompileUnit.Modules[0];
var module = macro.GetAncestor<Module>();
foreach (var import in compiled.Imports) {
module.Imports.Add(import);
}
var type = macro.GetAncestor<TypeDefinition>();
foreach (var member in compiled.Members) {
type.Members.Add(member);
}
var parent = (Block) macro.ParentNode;
var currentPosition = parent.Statements.IndexOf(macro);
RemoveCurrentNode();
foreach (var global in compiled.Globals.Statements.Reverse()) {
parent.Insert(currentPosition, global);
}
}
示例8: ExpandImpl
protected override Statement ExpandImpl(MacroStatement macro){
string tagname = macro.Arguments[0].ToCodeString();
bool useend = macro.Arguments.Contains(x=>x.ToCodeString()=="___end");
bool usestart = macro.Arguments.Contains(x => x.ToCodeString() == "___start");
bool wastagmodifiers = useend||usestart;
if(!wastagmodifiers){
useend = true;
usestart = true;
}
IEnumerable<Expression> argsource = macro.Arguments.Skip(1).Where(x=>!(x.ToCodeString().StartsWith("___")));
StatementCollection statements = macro.Body.Statements;
Statement result = tryResolveTemplate(macro, tagname, argsource);
if (null == result){
result = expandBmlElement(tagname, argsource, statements, usestart,useend);
}
return result;
}
示例9: DoExpand
/// <summary>
/// Perform the actual expansion of the macro
/// </summary>
/// <param name="macro">The macro.</param>
/// <returns></returns>
protected override Statement DoExpand(MacroStatement macro)
{
if (macro.Arguments.Count != 0)
{
Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo,"No arguments allowed for action statement"));
return null;
}
Method mergeRowsMethod = new Method("MergeRows");
mergeRowsMethod.Modifiers = TypeMemberModifiers.Override;
mergeRowsMethod.Parameters.Add(new ParameterDeclaration("left", new SimpleTypeReference(typeof(Row).FullName)));
mergeRowsMethod.Parameters.Add(new ParameterDeclaration("right", new SimpleTypeReference(typeof(Row).FullName)));
CodeBuilder.DeclareLocal(mergeRowsMethod, "row", TypeSystemServices.Map(typeof(Row)));
mergeRowsMethod.Body.Add(
new BinaryExpression(BinaryOperatorType.Assign,
new ReferenceExpression("row"),
new MethodInvocationExpression(
AstUtil.CreateReferenceExpression(typeof(Row).FullName))
)
);
mergeRowsMethod.Body.Add(macro.Body);
mergeRowsMethod.Body.Add(new ReturnStatement(new ReferenceExpression("row")));
ParentMethods.Add(mergeRowsMethod);
return null;
}
示例10: OnMacroStatement
public override void OnMacroStatement(MacroStatement node)
{
base.OnMacroStatement(node);
if (node.Name == "include")
ExpandIncludeMacro(node);
}
示例11: ExpandImpl
protected override Statement ExpandImpl(MacroStatement macro){
if (macro.Arguments.Count == 0){
throw new Exception("output must be called with arguemnts");
}
UnescapeInitialAndClosingDoubleQuotes(macro);
return PrintMacroModule.expandPrintMacro(macro, output, output);
}
示例12: DoExpand
/// <summary>
/// Perform the actual expansion of the macro
/// </summary>
/// <param name="macro">The macro.</param>
/// <returns></returns>
protected override Statement DoExpand(MacroStatement macro)
{
List<string> columns = new List<string>();
if(macro.Block.HasStatements)
{
Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "GroupBy cannot contain statements"));
return null;
}
foreach (Expression argument in macro.Arguments)
{
ReferenceExpression expr = argument as ReferenceExpression;
if(expr==null)
{
Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "GroupBy arguments must be refernce expressions. Example: groupBy name, surname"));
return null;
}
columns.Add(expr.Name);
}
Method method = CreateGetColumnsToGroupByMethod(macro, columns);
ParentMethods.Add(method);
return null;
}
示例13: ForCoverage
public void ForCoverage()
{
var statement = new MacroStatement();
statement.Block.Statements.Add(new MacroStatement());
CodeBuilderHelper.CreateCallableFromMacroBody(new BooCodeBuilder(new TypeSystemServices()), statement);
}
示例14: Expand
/// <summary>
/// Expands the specified macro, validate that the parent is a valid parent,
/// leave the actual processing to a base class
/// </summary>
/// <param name="macro">The macro.</param>
/// <returns></returns>
public override Statement Expand(MacroStatement macro)
{
if (ValidateParent(macro, out parent) == false)
return null;
return DoExpand(macro);
}
示例15: Expand
public override Statement Expand(MacroStatement macro)
{
if (macro.Arguments.Count == 0)
throw new RailsException("output must be called with arguemnts");
UnescapeInitialAndClosingDoubleQuotes(macro);
return Expand(macro, output, output);
}