public void TestEndKeywordAsIdentifier() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("end_identifier.boo"); ClassDefinition t = (ClassDefinition)module.Members[0]; Assert.AreEqual("T", t.Name); }
public static string CreateBooCode(CompilerErrorCollection errors, CompilerWarningCollection warnings, Module module, IList<ICSharpCode.NRefactory.ISpecial> specials) { using (StringWriter w = new StringWriter()) { foreach (CompilerError error in errors) { w.WriteLine("ERROR: " + error.ToString()); } if (errors.Count > 0) w.WriteLine(); foreach (CompilerWarning warning in warnings) { w.WriteLine("# WARNING: " + warning.ToString()); } if (warnings.Count > 0) w.WriteLine(); BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w); printer.OnModule(module); printer.Finish(); return w.ToString(); } }
public void TestIfElse1() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("if_else_1.boo"); StatementCollection stmts = module.Globals.Statements; Assert.AreEqual(1, stmts.Count); IfStatement s = (IfStatement)stmts[0]; BinaryExpression be = (BinaryExpression)s.Condition; Assert.AreEqual(BinaryOperatorType.Match, be.Operator); Assert.AreEqual("gets", ((ReferenceExpression)((MethodInvocationExpression)be.Left).Target).Name); Assert.AreEqual("/foo/", ((RELiteralExpression)be.Right).Value); Assert.AreEqual(3, s.TrueBlock.Statements.Count); Assert.IsNull(s.FalseBlock); s = (IfStatement)s.TrueBlock.Statements[2]; be = (BinaryExpression)s.Condition; Assert.AreEqual("/bar/", ((RELiteralExpression)be.Right).Value); Assert.AreEqual(1, s.TrueBlock.Statements.Count); Assert.IsNotNull(s.FalseBlock); Assert.AreEqual(1, s.FalseBlock.Statements.Count); Assert.AreEqual("foobar, eh?", ((StringLiteralExpression)((MethodInvocationExpression)((ExpressionStatement)s.TrueBlock.Statements[0]).Expression).Arguments[0]).Value); Assert.AreEqual("nah?", ((StringLiteralExpression)((MethodInvocationExpression)((ExpressionStatement)s.FalseBlock.Statements[0]).Expression).Arguments[0]).Value); }
public void TestInterface1() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("interface_1.boo"); Assert.AreEqual(1, module.Members.Count); InterfaceDefinition id = (InterfaceDefinition)module.Members[0]; Assert.AreEqual("IContentItem", id.Name); Assert.AreEqual(5, id.Members.Count); Property p = (Property)id.Members[0]; Assert.AreEqual("Parent", p.Name); Assert.AreEqual("IContentItem", ((SimpleTypeReference)p.Type).Name); Assert.IsNotNull(p.Getter, "Getter"); Assert.IsNull(p.Setter, "Setter"); p = (Property)id.Members[1]; Assert.AreEqual("Name", p.Name); Assert.AreEqual("string", ((SimpleTypeReference)p.Type).Name); Assert.IsNotNull(p.Getter, "Getter"); Assert.IsNotNull(p.Setter, "Setter"); Method m = (Method)id.Members[2]; Assert.AreEqual("SelectItem", m.Name); Assert.AreEqual("IContentItem", ((SimpleTypeReference)m.ReturnType).Name); Assert.AreEqual("expression", m.Parameters[0].Name); Assert.AreEqual("string", ((SimpleTypeReference)m.Parameters[0].Type).Name); Assert.AreEqual("Validate", ((Method)id.Members[3]).Name); Assert.AreEqual("OnRemove", ((Method)id.Members[4]).Name); }
override public void OnModule(Boo.Lang.Compiler.Ast.Module module) { EnterNamespace((INamespace)TypeSystemServices.GetEntity(module)); Visit(module.Members); Visit(module.Globals); LeaveNamespace(); }
/// <summary> /// Inspect a module to check if we need to add a namespace /// </summary> /// <param name="node">The node.</param> public override void OnModule(Module node) { if (node.Namespace != null) return; node.Namespace = new NamespaceDeclaration(node.FullName); }
private Module NewModule(string nameSpace, string moduleName) { Module module = CodeBuilder.CreateModule(moduleName, nameSpace); _context.CompileUnit.Modules.Add(module); return(module); }
override public void OnModule(Module module) { EnterNamespace(InternalModule.ScopeFor(module)); VisitTypeDefinitionBody(module); Visit(module.AssemblyAttributes); LeaveNamespace(); }
public void TestSimpleClassMethods() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("simple_class_methods.boo"); Assert.AreEqual("ITL.Content", module.Namespace.Name); Assert.AreEqual(1, module.Imports.Count); Import i = module.Imports[0]; Assert.AreEqual("System", i.Namespace); Assert.AreEqual(3, i.LexicalInfo.Line); Assert.AreEqual(1, module.Members.Count); ClassDefinition cd = (ClassDefinition)module.Members[0]; Assert.AreEqual("Article", cd.Name); Assert.AreEqual(3, cd.Members.Count); Method m = (Method)cd.Members[0]; Assert.AreEqual("getTitle", m.Name); Assert.IsNotNull(m.ReturnType, "ReturnType"); Assert.AreEqual("string", ((SimpleTypeReference)m.ReturnType).Name); m = (Method)cd.Members[1]; Assert.AreEqual("getBody", m.Name); Assert.IsNotNull(m.ReturnType, "ReturnType"); Assert.AreEqual("string", ((SimpleTypeReference)m.ReturnType).Name); m = (Method)cd.Members[2]; Assert.AreEqual("getTag", m.Name); Assert.IsNull(m.ReturnType, "methods without a return type must have ReturnType set to null!"); }
public object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { module = new B.Module(); module.LexicalInfo = new B.LexicalInfo(fileName, 1, 1); compilationUnit.AcceptChildren(this, data); if (entryPointMethod != null) { bool allMembersAreStatic = true; foreach (B.TypeMember member in entryPointMethod.DeclaringType.Members) { allMembersAreStatic &= member.IsStatic; } if (allMembersAreStatic) { entryPointMethod.DeclaringType.Attributes.Add(MakeAttribute(("module"))); } else { lastLexicalInfo = entryPointMethod.LexicalInfo; B.Expression expr = MakeReferenceExpression(entryPointMethod.DeclaringType.Name + ".Main"); B.MethodInvocationExpression mie = new B.MethodInvocationExpression(lastLexicalInfo, expr); if (entryPointMethod.Parameters.Count > 0) { mie.Arguments.Add(MakeReferenceExpression("argv")); } B.SimpleTypeReference ret = entryPointMethod.ReturnType as B.SimpleTypeReference; if (ret.Name == "void" || ret.Name == "System.Void") module.Globals.Add(new B.ExpressionStatement(mie)); else module.Globals.Add(new B.ReturnStatement(lastLexicalInfo, mie, null)); } } B.Module tmp = module; module = null; return tmp; }
protected virtual IType CreateConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType) { Module module = GetAnonymousTypesModule(); string name = string.Format("___callable{0}", module.Members.Count); ClassDefinition cd = CreateCallableDefinition(name); cd.Modifiers |= TypeMemberModifiers.Public; cd.LexicalInfo = sourceNode.LexicalInfo; cd.Members.Add(CreateInvokeMethod(anonymousType)); Method beginInvoke = CreateBeginInvokeMethod(anonymousType); cd.Members.Add(beginInvoke); // XXX: find an alternative way to support BeginInvoke overloads... if (Version1) { cd.Members.Add(CreateBeginInvokeCallbackOnlyOverload(anonymousType, beginInvoke)); cd.Members.Add(CreateBeginInvokeSimplerOverload(anonymousType, beginInvoke)); } cd.Members.Add(CreateEndInvokeMethod(anonymousType)); _anonymousTypesModule.Members.Add(cd); return((IType)cd.Entity); }
public override void OnModule(Module module) { replacecount = 0; dowork = module["isduck"]==null|| module["isduck"].toBool(); //NameResolutionService.Reset(); Console.WriteLine(""); Console.Write("[" + module.Members[0].Name.Replace("_0_","/") + "](" + (cnt++) + ")"); base.OnModule(module); if(replacecount==0) { if (dowork) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine(module.Members[0].Name.Replace("_0_", "/") + " can be NODUCK"); }else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(); Console.WriteLine(module.Members[0].Name.Replace("_0_", "/") + " is NODUCK"); } }else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); Console.WriteLine(module.Members[0].Name.Replace("_0_", "/") + " contains DUCKS"); } Console.ResetColor(); }
public void TestProperties1() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("properties_1.boo"); ClassDefinition cd = (ClassDefinition)module.Members[0]; Assert.AreEqual("Person", cd.Name); Assert.AreEqual("_id", cd.Members[0].Name); Assert.AreEqual("_name", cd.Members[1].Name); Property p = (Property)cd.Members[3]; Assert.AreEqual("ID", p.Name); Assert.AreEqual("string", ((SimpleTypeReference)p.Type).Name); Assert.IsNotNull(p.Getter, "Getter"); Assert.AreEqual(1, p.Getter.Body.Statements.Count); Assert.AreEqual("_id", ((ReferenceExpression)((ReturnStatement)p.Getter.Body.Statements[0]).Expression).Name); Assert.IsNull(p.Setter, "Setter"); p = (Property)cd.Members[4]; Assert.AreEqual("Name", p.Name); Assert.AreEqual("string", ((SimpleTypeReference)p.Type).Name); Assert.IsNotNull(p.Getter, "Getter "); Assert.AreEqual(1, p.Getter.Body.Statements.Count); Assert.AreEqual("_name", ((ReferenceExpression)((ReturnStatement)p.Getter.Body.Statements[0]).Expression).Name); Assert.IsNotNull(p.Setter, "Setter"); Assert.AreEqual(1, p.Setter.Body.Statements.Count); BinaryExpression a = (BinaryExpression)((ExpressionStatement)p.Setter.Body.Statements[0]).Expression; Assert.AreEqual(BinaryOperatorType.Assign, a.Operator); Assert.AreEqual("_name", ((ReferenceExpression)a.Left).Name); Assert.AreEqual("value", ((ReferenceExpression)a.Right).Name); }
override public void OnModule(Boo.Lang.Compiler.Ast.Module module) { EnterNamespace((INamespace)GetEntity(module)); VisitTypeDefinitionBody(module); Visit(module.AssemblyAttributes); LeaveNamespace(); }
public override void LeaveModule(AST.Module node) { if (_currentClass.Count != 0) { LeaveTypeDefinition(node); } base.LeaveModule(node); }
public Module GetCompilerGeneratedExtensionsModule() { if (null == _compilerGeneratedExtensionsModule) { _compilerGeneratedExtensionsModule = NewModule(null, "CompilerGeneratedExtensions"); } return(_compilerGeneratedExtensionsModule); }
/// <summary> /// Add the namespaces to the module /// </summary> public override void OnModule(Module node) { foreach (string ns in namespaces) { Import import = new Import(node.LexicalInfo, ns); node.Imports.Add(import); } }
public Module GetCompilerGeneratedTypesModule() { if (null == _compilerGeneratedTypesModule) { _compilerGeneratedTypesModule = NewModule("CompilerGenerated"); } return(_compilerGeneratedTypesModule); }
public override void OnModule(Module node){ bmlelements = new List<MacroStatement>(); exceptions = null; allowall = false; Visit(node.Members); Visit(node.Globals.Statements); collectTemplates(); }
public InternalModule(InternalTypeSystemProvider provider, Module module) { _provider = provider; _module = module; _namespace = SafeNamespace(module); _module.Imports.Changed += (sender, e) => _namespaceList = null; _module.Members.Changed += (sender, e) => _memberCache = null; }
private static Module CreateModule(TypeDefinition klass) { Module module = new Module(); module.Name = klass.Name; module.Members.Add(klass); return(module); }
public string Generate(XElement xml) { var m = new Module { Namespace = new NamespaceDeclaration(xml.Name.LocalName) }; foreach (var element in xml.Elements()) { generateElement(element, m.Globals); } return m.ToCodeString(); }
public ModuleEntity(NameResolutionService nameResolutionService, TypeSystemServices typeSystemServices, Module module) { _nameResolutionService = nameResolutionService; _typeSystemServices = typeSystemServices; _module = module; _namespace = SafeNamespace(module); }
public void ReifyIntoShouldFailWithAlreadyConnectedMember() { var module = new Module(); RunCompilerStepAfterExpressionResolutionOn(new CompileUnit(module), new ActionStep(() => { var klass = new ClassDefinition { Name = "Foo" }; module.Members.Add(klass); Exceptions.Expecting<ArgumentException>(() => CodeReifier().ReifyInto(module, klass)); })); }
public override void OnModule(Module node) { var imports = new[] { "UnityEngine", "System.Collections" }; foreach (var importName in imports) { var targetImport = new Import(LexicalInfo.Empty, importName); if (node.Imports.Contains(targetImport)) node.Imports.Add(targetImport); } }
public override bool EnterModule(AST.Module node) { HandleNamespaceDeclaration(node.Namespace); if (!_firstModule && node.Members.Count > 0) { EnterTypeDefinition(node, ClassType.Module); } _firstModule = false; return(base.EnterModule(node)); }
public void TestSimpleGlobalDefs() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("simple_global_defs.boo"); Assert.AreEqual("Math", module.Namespace.Name); Assert.AreEqual(3, module.Members.Count); Assert.AreEqual("Rational", module.Members[0].Name); Assert.AreEqual("pi", module.Members[1].Name); Assert.AreEqual("rationalPI", module.Members[2].Name); Assert.AreEqual(0, module.Globals.Statements.Count); }
override public void OnModule(Module node) { var existingModuleClass = FindModuleClass(node); var moduleClass = existingModuleClass ?? NewModuleClassFor(node); Method entryPoint = moduleClass.Members["Main"] as Method; int removed = 0; TypeMember[] members = node.Members.ToArray(); for (int i=0; i<members.Length; ++i) { TypeMember member = members[i]; if (member is TypeDefinition) continue; if (member.NodeType == NodeType.Method) { if (EntryPointMethodName == member.Name) { entryPoint = (Method)member; } member.Modifiers |= TypeMemberModifiers.Static; } node.Members.RemoveAt(i-removed); moduleClass.Members.Add(member); ++removed; } if (!node.Globals.IsEmpty) { Method method = new Method(); method.IsSynthetic = true; method.Parameters.Add(new ParameterDeclaration("argv", new ArrayTypeReference(new SimpleTypeReference("string")))); method.ReturnType = CodeBuilder.CreateTypeReference(TypeSystemServices.VoidType); method.Body = node.Globals; method.LexicalInfo = node.Globals.Statements[0].LexicalInfo; method.EndSourceLocation = node.EndSourceLocation; method.Name = EntryPointMethodName; method.Modifiers = TypeMemberModifiers.Static | TypeMemberModifiers.Private; moduleClass.Members.Add(method); node.Globals = null; entryPoint = method; } SetEntryPointIfNecessary(entryPoint); if (existingModuleClass != null || ForceModuleClass || (moduleClass.Members.Count > 0)) { if (moduleClass != existingModuleClass) { moduleClass.Members.Add(AstUtil.CreateConstructor(node, TypeMemberModifiers.Private)); node.Members.Add(moduleClass); } InitializeModuleClassEntity(node, moduleClass); } }
public void TestYieldStmt1() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("yield_stmt_1.boo"); Method m = (Method)module.Members[0]; ForStatement fs = (ForStatement)m.Body.Statements[0]; YieldStatement ys = (YieldStatement)fs.Block.Statements[0]; Assert.AreEqual("i", ((ReferenceExpression)ys.Expression).Name); Assert.AreEqual(StatementModifierType.If, ys.Modifier.Type); }
public void TestStmtModifiers2() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("stmt_modifiers_2.boo"); ExpressionStatement s = (ExpressionStatement)module.Globals.Statements[0]; BinaryExpression a = (BinaryExpression)s.Expression; Assert.AreEqual(BinaryOperatorType.Assign, a.Operator); Assert.AreEqual("f", ((ReferenceExpression)a.Left).Name); Assert.AreEqual(BinaryOperatorType.Division, ((BinaryExpression)a.Right).Operator); }
/// <summary> /// Extends the base class by placing the blocks of macros into methods on the base class /// of the same name. /// </summary> /// <example> /// MyMethod: /// PerformActions /// /// If an overridable method called MyMethod exists on <see cref="BaseClassCompilerStep.BaseClass"/>, then /// it is overridden as follows: /// <code> /// public override void MyMethod() { PerformActions(); } /// </code> /// </example> protected override void ExtendBaseClass(Module module, ClassDefinition definition) { List <MethodInfo> methodsThatAreOverridable = new List <MethodInfo>(); MethodInfo[] baseClassMethods = BaseClass.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod); foreach (MethodInfo method in baseClassMethods) { if (method.DeclaringType == typeof(object)) { continue; } if (method.IsVirtual || method.IsAbstract) { methodsThatAreOverridable.Add(method); } } MethodSubstitutionTransformer mst = new MethodSubstitutionTransformer(methodsThatAreOverridable.ToArray(), definition); mst.Visit(module); foreach (Statement statement in module.Globals.Statements) { ExpressionStatement es = statement as ExpressionStatement; if (es != null) { BinaryExpression be = es.Expression as BinaryExpression; if (be != null) { if (be.Left.NodeType == NodeType.ReferenceExpression && be.Operator == BinaryOperatorType.Assign) { ReferenceExpression refExp = be.Left as ReferenceExpression; Field field = new Field(refExp.LexicalInfo); field.Name = refExp.Name; field.Initializer = be.Right; definition.Members.Add(field); } } } } if (transformers != null) { foreach (DepthFirstTransformer transformer in transformers) { transformer.Visit(module); } } }
public Module GetAnonymousTypesModule() { if (null == _anonymousTypesModule) { _anonymousTypesModule = new Module(); _anonymousTypesModule.Entity = new ModuleEntity(_context.NameResolutionService, this, _anonymousTypesModule); _context.CompileUnit.Modules.Add(_anonymousTypesModule); } return(_anonymousTypesModule); }
// get the directory name where this script reside and create a property // that return this value. // this is used to calculate relative paths when loading subviews. private void ScriptDirectoryProperty(ClassDefinition macro, Module module) { Property p = new Property("ScriptDirectory"); p.Modifiers = TypeMemberModifiers.Override; p.Getter = new Method("getScriptDirectory"); p.Getter.Body.Add( new ReturnStatement( new StringLiteralExpression( Path.GetDirectoryName(module.LexicalInfo.FileName)))); macro.Members.Add(p); }
void ExpandOnModuleNamespace(Module module, Action <Module> action) { EnterModuleNamespace(module); try { action(module); } finally { LeaveNamespace(); } }
public void TestClass2() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("class_2.boo"); ClassDefinition cd = (ClassDefinition)module.Members[0]; Assert.AreEqual(6, cd.Members.Count); for (int i = 0; i < 5; ++i) { Assert.AreEqual(TypeMemberModifiers.None, cd.Members[i].Modifiers); } Assert.AreEqual(TypeMemberModifiers.Public | TypeMemberModifiers.Static, cd.Members[5].Modifiers); }
protected override CodeCompileUnit Parse() { LoggingService.Debug("BooDesignerLoader.Parse()"); try { CodeCompileUnit ccu = ParseForm(); LoggingService.Debug("BooDesignerLoader.Parse() finished"); // Clear the cached module after loading has finished this.parsedModule = null; return ccu; } catch (Boo.Lang.Compiler.CompilerError ex) { throw new FormsDesignerLoadException(ex.ToString(true)); } }
private Module NewModule(string nameSpace, string moduleName) { Module module = new Module(); module.Name = moduleName; if (null != nameSpace) { module.Namespace = new NamespaceDeclaration(nameSpace); } module.Entity = new ModuleEntity(_context.NameResolutionService, this, module); _context.CompileUnit.Modules.Add(module); return(module); }
public override void Initialize(CompilerContext context) { base.Initialize(context); _currentModule = null; _currentMethod = null; _methodStack = new Stack<InternalMethod>(); _memberStack = new Stack(); _callableResolutionService = new EnvironmentProvision<CallableResolutionService>(); _invocationTypeReferenceRules = new EnvironmentProvision<InvocationTypeInferenceRules>(); _typeChecker = new EnvironmentProvision<TypeChecker>(); _methodCache = new EnvironmentProvision<RuntimeMethodCache>(); }
public void TestRELiteral3() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("re_literal_3.boo"); StatementCollection stmts = module.Globals.Statements; Assert.AreEqual(2, stmts.Count); BinaryExpression ae = (BinaryExpression)((ExpressionStatement)stmts[0]).Expression; Assert.AreEqual(BinaryOperatorType.Assign, ae.Operator); Assert.AreEqual("/\\x2f\\u002f/", ((RELiteralExpression)ae.Right).Value); }
private Module Parse() { var module = new Module(); var globals = module.Globals; while (_position < _code.Length) { var expression = ParseNextExpression(); if (expression == null) break; globals.Add(expression); } return module; }
private void processModule(Module module) { var key = module.LexicalInfo.FileName; var source = sources.FirstOrDefault(x => x.Key == key); if (null == source) return; var type = module.Members[0] as ClassDefinition; type.Name = source.Key.Replace("/","_0_"); module.Namespace = null; var attr = new Attribute(); attr.Name = typeof (TimeStampAttribute).Name; attr.Arguments.Add(new StringLiteralExpression(source.LastModified.ToString("dd.MM.yyyy HH:mm:ss"))); type.Attributes.Add(attr); }
public static Module ParseModule(int tabSize, CompileUnit cu, string readerName, TextReader reader, ParserErrorHandler errorHandler) { if (Readers.IsEmpty(reader)) { Module emptyModule = new Module(new LexicalInfo(readerName), ModuleNameFrom(readerName)); cu.Modules.Add(emptyModule); return emptyModule; } Module module = CreateParser(tabSize, readerName, reader, errorHandler).start(cu); module.Name = ModuleNameFrom(readerName); return module; }
public override void OnModule(Module node) { var root = "root"; var name = node.Namespace; if(name!=null && (!string.IsNullOrWhiteSpace(name.Name))){ root = name.Name; } Target = new XElement(root); Current = Target; Visit(node.Members); Visit(node.Globals); }
public void TestWhileStmt1() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("while_stmt_1.boo"); WhileStatement ws = (WhileStatement)module.Globals.Statements[3]; Assert.AreEqual(true, ((BoolLiteralExpression)ws.Condition).Value); Assert.AreEqual(4, ws.Block.Statements.Count); BreakStatement bs = (BreakStatement)ws.Block.Statements[3]; BinaryExpression condition = (BinaryExpression)bs.Modifier.Condition; Assert.AreEqual(BinaryOperatorType.Equality, condition.Operator); }
private void VisitGlobalsAllowingCancellation(Module module) { var globals = module.Globals.Statements; foreach (var stmt in globals.ToArray()) { Node resultingNode; if (VisitAllowingCancellation(stmt, out resultingNode) && resultingNode != stmt) { globals.Replace(stmt, (Statement)resultingNode); } BubbleUpPendingTypeMembers(); } }
override public void OnModule(Boo.Lang.Compiler.Ast.Module module) { EnterNamespace((INamespace)TypeSystemServices.GetEntity(module)); try { Visit(module.Members); Visit(module.Globals); Visit(module.Attributes); Visit(module.AssemblyAttributes); } finally { LeaveNamespace(); } }
public void TestUnpackStmt1() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("unpack_stmt_1.boo"); UnpackStatement us = (UnpackStatement)module.Globals.Statements[0]; Assert.AreEqual(2, us.Declarations.Count); Assert.AreEqual("arg0", us.Declarations[0].Name); Assert.AreEqual("arg1", us.Declarations[1].Name); MethodInvocationExpression mce = (MethodInvocationExpression)us.Expression; MemberReferenceExpression mre = ((MemberReferenceExpression)mce.Target); Assert.AreEqual("GetCommandLineArgs", mre.Name); Assert.AreEqual("Environment", ((ReferenceExpression)mre.Target).Name); }
override public void OnModule(Module module) { EnterNamespace(InternalModule.ScopeFor(module)); try { Visit(module.Members); Visit(module.Globals); Visit(module.Attributes); Visit(module.AssemblyAttributes); } finally { LeaveNamespace(); } }
/// <summary> /// Allow a derived class to perform additional operations on the newly created type definition. /// </summary> protected override void ExtendBaseClass(Module module, ClassDefinition definition) { Method method = new Method(methodName); if (parameters != null) { foreach (ParameterDeclaration parameter in parameters) { method.Parameters.Add(parameter); } } method.Body = module.Globals; definition.Members.Add(method); ExtendBaseClass(definition); }
private static Module ModuleFor(TypeDefinition node) { var m = new Module { Namespace = SafeCleanClone(node.EnclosingModule.Namespace), Name = node.Name }; foreach (var i in node.EnclosingModule.Imports) { m.Imports.Add(i.CleanClone()); } m.Members.Add(node.CleanClone()); return(m); }
public void TestStaticMethod() { Boo.Lang.Compiler.Ast.Module module = ParseTestCase("static_method.boo"); Assert.AreEqual(1, module.Members.Count); ClassDefinition cd = (ClassDefinition)module.Members[0]; Assert.AreEqual("Math", cd.Name); Assert.AreEqual(1, cd.Members.Count); Method m = (Method)cd.Members[0]; Assert.AreEqual(TypeMemberModifiers.Static, m.Modifiers); Assert.AreEqual("square", m.Name); Assert.AreEqual("int", ((SimpleTypeReference)m.ReturnType).Name); }
/// <summary> /// Extends the base class by placing the blocks of macros into methods on the base class /// of the same name. /// </summary> /// <example> /// MyMethod: /// PerformActions /// /// If an overridable method called MyMethod exists on <see cref="BaseClassCompilerStep.BaseClass"/>, then /// it is overridden as follows: /// <code> /// public override void MyMethod() { PerformActions(); } /// </code> /// </example> protected override void ExtendBaseClass(Module module, ClassDefinition definition) { List<MethodInfo> methodsThatAreOverridable = new List<MethodInfo>(); MethodInfo[] baseClassMethods = BaseClass.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod); foreach (MethodInfo method in baseClassMethods) { if(method.DeclaringType==typeof(object)) continue; if (method.IsVirtual || method.IsAbstract) methodsThatAreOverridable.Add(method); } MethodSubstitutionTransformer mst = new MethodSubstitutionTransformer(methodsThatAreOverridable.ToArray(), definition); mst.Visit(module); foreach (Statement statement in module.Globals.Statements) { ExpressionStatement es = statement as ExpressionStatement; if (es != null) { BinaryExpression be = es.Expression as BinaryExpression; if (be != null) { if (be.Left.NodeType == NodeType.ReferenceExpression && be.Operator == BinaryOperatorType.Assign) { ReferenceExpression refExp = be.Left as ReferenceExpression; Field field = new Field(refExp.LexicalInfo); field.Name = refExp.Name; field.Initializer = be.Right; definition.Members.Add(field); } } } } if (transformers != null) { foreach (DepthFirstTransformer transformer in transformers) transformer.Visit(module); } }
string GetStringFromModule(Module module, ConverterSettings settings) { if (settings.Errors.Count > 0) { Assert.Fail(settings.Errors.Count.ToString() + " errors: " + settings.Errors[0]); } if (settings.Warnings.Count > 0) { Assert.Fail(settings.Warnings.Count.ToString() + " warnings: " + settings.Warnings[0]); } Assert.IsNotNull(module, "Module is null"); string str = module.ToCodeString(); str = str.Trim().Replace("\r", ""); for (int i = 0; i < 5; i++) { str = str.Replace("\n\n", "\n"); str = str.Replace(" ", " "); } return str; }
public override void OnModule(Module node){ logger.get("comdiv.dsl").Debug("SetupDefaultNamespacesAndReferencesStep on {0} started", node.Name); Console.WriteLine("SetupDefaultNamespacesAndReferencesStep on {0} started", node.Name); if(null==node.Namespace){ node.Namespace = new NamespaceDeclaration(System.IO.Path.GetFileNameWithoutExtension(Context.Parameters.OutputAssembly)); } if (null != namespaces){ foreach (var ns in namespaces){ var import = new Import(); import.Namespace = ns; node.Imports.Add(import); logger.get("comdiv.dsl").Debug("SetupDefaultNamespacesAndReferencesStep on {0} - {1} ns added", node.Name, ns); Console.WriteLine("SetupDefaultNamespacesAndReferencesStep on {0} - {1} ns added", node.Name, ns); } } logger.get("comdiv.dsl").Debug("SetupDefaultNamespacesAndReferencesStep on {0} finished", node.Name); }
public override void OnModule(Module module) { var existingModuleClass = ExistingModuleClassFor(module); var moduleClass = existingModuleClass ?? NewModuleClassFor(module); MoveModuleMembersToModuleClass(module, moduleClass); DetectEntryPoint(module, moduleClass); if (existingModuleClass != null || ForceModuleClass || (moduleClass.Members.Count > 0)) { if (moduleClass != existingModuleClass) { moduleClass.Members.Add(AstUtil.CreateConstructor(module, TypeMemberModifiers.Private)); module.Members.Add(moduleClass); } InitializeModuleClassEntity(module, moduleClass); } }
public override void OnModule(Module node) { for (var i = 0; i < node.Imports.Count; i++) { var import = node.Imports[i]; if (import.Namespace != "tasks") continue; var newImports = ImportTasks(import); node.Imports.RemoveAt(i); var newIndex = i; foreach (var newImport in newImports) { node.Imports.Insert(newIndex, newImport); newIndex += 1; } } base.OnModule(node); }
public virtual void setup() { string code = @"import System.Data class X : def Z() as string : return '' def B() as bool : return false registry['x'] = X if B() : pass"; this.cu = Compile("test",code, getPipeline() , prepareCompiler); Console.WriteLine(cu.Errors); Assert.True(cu.Errors.Count==0); this.srcmodule = cu.CompileUnit.Modules[0].Clone() as Module; Console.WriteLine(srcmodule.ToCodeString()); this.pr = postProcess(); if(pr.ToCodeString()!=srcmodule.ToCodeString()) { Console.WriteLine(pr.ToCodeString()); } }
Module ParseFormAsModule() { // The module is cached while loading so that // determining the localization model and generating the CodeDOM // does not require the code to be parsed twice. if (this.parsedModule != null && lastTextContent == this.Generator.ViewContent.DesignerCodeFileContent) { return this.parsedModule; } lastTextContent = this.Generator.ViewContent.DesignerCodeFileContent; ParseInformation parseInfo = ParserService.ParseFile(this.Generator.ViewContent.DesignerCodeFile.FileName, this.Generator.ViewContent.DesignerCodeFileContent, false); // ensure that there are no syntax errors in the file: Module mainModule = Parse(this.Generator.ViewContent.DesignerCodeFile.FileName, lastTextContent); IClass formClass; bool isFirstClassInFile; IList<IClass> parts = NRefactoryDesignerLoader.FindFormClassParts(parseInfo, out formClass, out isFirstClassInFile); IMethod initMethod = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(formClass); if (initMethod == null) throw new FormsDesignerLoadException("The InitializeComponent method was not found. Designer cannot be loaded."); Module module = new Module(); module.Namespace = new NamespaceDeclaration(formClass.Namespace); ClassDefinition cld = new ClassDefinition(); cld.Name = formClass.Name; module.Members.Add(cld); if (formClass.BaseClass == null) throw new FormsDesignerLoadException("formClass.BaseClass returned null."); cld.BaseTypes.Add(new SimpleTypeReference(formClass.BaseClass.FullyQualifiedName)); System.Diagnostics.Debug.Assert(FileUtility.IsEqualFileName(initMethod.DeclaringType.CompilationUnit.FileName, this.Generator.ViewContent.DesignerCodeFile.FileName)); foreach (IField f in formClass.Fields) { Field field = new Field(); field.Name = f.Name; if (f.ReturnType.IsDefaultReturnType) { field.Type = new SimpleTypeReference(f.ReturnType.FullyQualifiedName); } field.Modifiers = CodeCompletion.ConvertVisitor.ConvertVisibilityBack(f.Modifiers); cld.Members.Add(field); } // Now find InitializeComponent in parsed module and put it into our new module foreach (TypeMember m in mainModule.Members) { TypeDefinition td = m as TypeDefinition; if (td == null) continue; foreach (TypeMember m2 in td.Members) { Method method = m2 as Method; if (method != null && FormsDesignerSecondaryDisplayBinding.IsInitializeComponentsMethodName(method.Name) && method.Parameters.Count == 0) { cld.Members.Add(method); this.parsedModule = module; return module; } } } throw new FormsDesignerLoadException("Could not find InitializeComponent in parsed module."); }
public override void OnModule(Module module) { if (WasVisited(module)) return; MarkVisited(module); _currentModule = module; EnterNamespace(InternalModule.ScopeFor(module)); Visit(module.Members); Visit(module.AssemblyAttributes); LeaveNamespace(); }
public override void Dispose() { base.Dispose(); _currentModule = null; _currentMethod = null; _methodStack = null; _memberStack = null; }