Beispiel #1
0
        public Page ParsePage(string name, TextReader reader)
        {
            Console.WriteLine ("parsing page:  {0}", name);
            MingeTokenizer tk = new MingeTokenizer (environment, reader);

            current_page = application.CreatePage (name);

            Token tok = null;
            StringBuilder data = new StringBuilder ();

            while (true) {
                tok = tk.GetNextToken ();

                switch (tok.Type) {
                case TokenType.TOKEN_VARIABLE_BEGIN:
                    FlushData (data);
                    ParseVariable (tk);
                    break;
                case TokenType.TOKEN_COMMENT_BEGIN:
                    FlushData (data);
                    ParseComment (tk);
                    break;
                case TokenType.TOKEN_BLOCK_BEGIN:
                    FlushData (data);
                    ParseControlBlock (tk);
                    break;
                case TokenType.TOKEN_EOF:
                    FlushData (data);
                    current_page.Save ();
                    return current_page;
                default:
                    data.Append (tok.Value);
                    break;
                }
            }

            return null;
        }
Beispiel #2
0
        public override TypeReference ResolveType(Application app, Page page)
        {
            MethodDefinition meth = page.GetMethod (Name);

            ResolvedType = meth.ReturnType;
            return ResolvedType;
        }
Beispiel #3
0
        public void EmitExtends(string base_template)
        {
            if (base_type != null)
                throw new Exception (String.Format ("Multiple extends statements are not allowed. ({0})", base_type));

            base_type = application.LoadPage (base_template);

            if (base_type == null)
                throw new Exception ("Could not find base.");

            Definition.BaseType = base_type.Definition;
            EmitBaseRenderToResponseCall ();
        }
Beispiel #4
0
 public override TypeReference ResolveType(Application app, Page page)
 {
     ResolvedType = app.Assembly.MainModule.Import (typeof (string));
     return ResolvedType;
 }
Beispiel #5
0
        public override void Emit(Application app, Page page, ILProcessor processor)
        {
            MethodDefinition meth = page.GetMethod (Name);

            processor.Emit (OpCodes.Ldarg_0);
            processor.Emit (OpCodes.Ldarg_1);
            processor.Emit (OpCodes.Ldarg_2);

            for (int i = 2; i < meth.Parameters.Count; i++) {
                if (i - 2 < Arguments.Count) {
                    Arguments [i - 2].Emit (app, page, processor);
                    continue;
                }
                ParameterDefinition p = meth.Parameters [i];
                if (!p.HasConstant)
                    throw new Exception ("Illegal invoke statement, incorrect number of parameters.");
                object constant = p.Constant;
                if (constant is string)
                    processor.Emit (OpCodes.Ldstr, (string) constant);
                else if (constant is int)
                    processor.Emit (OpCodes.Ldc_I4, (int) constant);
                else if (constant is double)
                    processor.Emit (OpCodes.Ldc_R4, (double) constant);
                else
                    throw new Exception (String.Format ("Illegal default argument type {0}", constant));
            }

            processor.Emit (OpCodes.Call, meth);
        }
Beispiel #6
0
 public virtual TypeReference ResolveType(Application app, Page page)
 {
     if (filters.Count < 1)
         ResolvedType =  Value.ResolveType (app, page);
     else
         ResolvedType = app.Assembly.MainModule.Import (typeof (string));
     return ResolvedType;
 }
Beispiel #7
0
        public override void Emit(Application app, Page page, ILProcessor processor)
        {
            var filter = MingeFilterManager.GetFilter (Name);

            if (filter == null)
                return;

            for (int i = 0; i < Arguments.Count; i++) {
                Arguments [i].Emit (app, page, processor);
            }

            processor.Emit (OpCodes.Call, app.Assembly.MainModule.Import (filter));
        }
Beispiel #8
0
 public override void Emit(Application app, Page page, ILProcessor processor)
 {
     processor.Emit (OpCodes.Ldstr, Value);
 }
Beispiel #9
0
        public virtual void Emit(Application app, Page page, ILProcessor processor)
        {
            Value.Emit (app, page, processor);

            ResolveType (app, page);

            foreach (Filter filter in filters) {
                filter.Emit (app, page, processor);
            }
        }
Beispiel #10
0
        public override void Emit(Application app, Page page, ILProcessor processor)
        {
            if (page.IsForLoopVariable (Name.Name)) {
                page.EmitForLoopVariableAccess ();
                return;
            }

            if (page.IsBuiltInVariable (Name.Name)) {
                page.EmitBuiltInVariable (Name.Name);
                return;
            }

            ParameterDefinition pvar = page.FindParameter (Name.Name);
            if (pvar != null) {
                ResolvedType = pvar.ParameterType;
                processor.Emit (OpCodes.Ldarg, pvar);
                return;
            }

            VariableDefinition localvar = page.FindLocalVariable (Name.Name);
            if (localvar != null) {
                ResolvedType = localvar.VariableType;
                processor.Emit (OpCodes.Ldloc, localvar);
                return;
            }

            // Attempt to resolve the property on the resolved type
            PropertyDefinition prop = page.Definition.Properties.Where (p => p.Name == Name.Name).FirstOrDefault ();
            if (prop != null) {
                MethodReference get_method = app.Assembly.MainModule.Import (prop.GetMethod);
                processor.Emit (OpCodes.Call, get_method);
                return;
            }

            //
            // Attempt to load it from the supplied type, look for a property
            // on the type with the correct name.
            //

            processor.Emit (OpCodes.Ldarg_2);
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetTypeMethod);
            processor.Emit (OpCodes.Ldstr, Name.Name);

            processor.Emit (OpCodes.Ldc_I4, (int) (System.Reflection.BindingFlags.IgnoreCase |
                    System.Reflection.BindingFlags.Instance |
                        System.Reflection.BindingFlags.Public));
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyMethod);

            processor.Emit (OpCodes.Ldarg_2);
            processor.Emit (OpCodes.Ldnull);
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyValueMethod);

            /*
            ResolvedType = app.Assembly.MainModule.Import (typeof (object));

            processor.Emit (OpCodes.Ldarg_2);
            processor.Emit (OpCodes.Ldstr, Name.Name);
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.ContainsKeyMethod);

            Instruction contains_branch = processor.Emit (OpCodes.Brfalse, processor.Create (OpCodes.Nop));
            processor.Emit (OpCodes.Ldarg_2);
            processor.Emit (OpCodes.Ldstr, Name.Name);
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetArgMethod);

            Instruction gotarg_branch = processor.Emit (OpCodes.Br, processor.Create (OpCodes.Nop));
            Instruction load_empty_target = processor.Emit (OpCodes.Ldsfld, app.CommonMethods.StringEmptyField);
            contains_branch.Operand = load_empty_target;

            Instruction completed_target = processor.Emit (OpCodes.Nop);
            gotarg_branch.Operand = completed_target;
            */
        }
Beispiel #11
0
        public override TypeReference ResolveType(Application app, Page page)
        {
            ParameterDefinition pvar = page.FindParameter (Name.Name);
            if (pvar != null) {
                ResolvedType = pvar.ParameterType;
                return ResolvedType;
            }

            VariableDefinition localvar = page.FindLocalVariable (Name.Name);
            if (localvar != null) {
                ResolvedType = localvar.VariableType;
                return ResolvedType;
            }

            ResolvedType = app.Assembly.MainModule.Import (typeof (object));
            return ResolvedType;
        }
Beispiel #12
0
 public abstract TypeReference ResolveType(Application app, Page page);
Beispiel #13
0
 public abstract void Emit(Application app, Page page, ILProcessor processor);
Beispiel #14
0
        public override TypeReference ResolveType(Application app, Page page)
        {
            PropertyDefinition prop = Target.ResolvedType.Resolve ().Properties.Where (p => p.Name == Property).FirstOrDefault ();
            if (prop != null) {
                MethodReference get_method = app.Assembly.MainModule.Import (prop.GetMethod);
                ResolvedType = prop.PropertyType;
                return ResolvedType;
            }

            ResolvedType = app.Assembly.MainModule.Import (typeof (object));
            return ResolvedType;
        }
Beispiel #15
0
        public override void Emit(Application app, Page page, ILProcessor processor)
        {
            Target.Emit (app, page, processor);

            // Attempt to resolve the property on the resolved type
            PropertyDefinition prop = Target.ResolvedType.Resolve ().Properties.Where (p => p.Name == Property).FirstOrDefault ();
            if (prop != null) {
                MethodReference get_method = app.Assembly.MainModule.Import (prop.GetMethod);
                processor.Emit (OpCodes.Call, get_method);
                return;
            }

            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetTypeMethod);
            processor.Emit (OpCodes.Ldstr, Property);
            processor.Emit (OpCodes.Ldc_I4, (int) (System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public));
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyMethod);
            Target.Emit (app, page, processor);
            processor.Emit (OpCodes.Ldnull);
            processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyValueMethod);
        }
Beispiel #16
0
        public void EmitToString(Application app, Page page, ILProcessor processor, TypeReference resolved)
        {
            if (resolved.FullName == "System.String")
                return;

            if (resolved.FullName == "System.Void") {
                processor.Emit (OpCodes.Ldsfld, application.CommonMethods.StringEmptyField);
                return;
            }

            if (resolved.IsValueType) {
                processor.Emit (OpCodes.Box, app.Assembly.MainModule.Import (resolved));
                processor.Emit (OpCodes.Call, app.Assembly.MainModule.Import (page.ValueToStringMethod));
                return;
            }

            TypeDefinition rtype = resolved.Resolve ();
            MethodReference method = rtype.Methods.Where (m => m.Name == "ToString").First ();

            // Import it so we get a method reference
            method = application.Assembly.MainModule.Import (method);
            Instruction inst = processor.Create (OpCodes.Callvirt, (MethodReference) method);
            processor.Append (inst);
        }