Inheritance: GeneratorContext
Esempio n. 1
0
 public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Wrapper.ActionGroup grp, CodeExpression groupVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
 {
     statements.Add (new CodeCommentStatement ("Action group " + grp.Name));
     GeneratorContext ctx = new ProjectGeneratorContext (cns, type, statements, options);
     ctx.GenerateCreationCode (grp, groupVarExp);
     ctx.EndGeneration ();
     warnings.AddRange (ctx.Warnings);
     return ctx.WidgetMap;
 }
Esempio n. 2
0
 public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Gtk.Widget w, CodeExpression widgetVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
 {
     statements.Add (new CodeCommentStatement ("Widget " + w.Name));
     GeneratorContext ctx = new ProjectGeneratorContext (cns, type, statements, options);
     Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup (w);
     ctx.GenerateCreationCode (ww, widgetVarExp);
     ctx.EndGeneration ();
     warnings.AddRange (ctx.Warnings);
     return ctx.WidgetMap;
 }
Esempio n. 3
0
        public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Wrapper.ActionGroup grp, CodeExpression groupVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
        {
            statements.Add(new CodeCommentStatement("Action group " + grp.Name));
            GeneratorContext ctx = new ProjectGeneratorContext(cns, type, statements, options);

            ctx.GenerateCreationCode(grp, groupVarExp);
            ctx.EndGeneration();
            warnings.AddRange(ctx.Warnings);
            return(ctx.WidgetMap);
        }
Esempio n. 4
0
        public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Gtk.Widget w, CodeExpression widgetVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
        {
            statements.Add(new CodeCommentStatement("Widget " + w.Name));
            GeneratorContext ctx = new ProjectGeneratorContext(cns, type, statements, options);

            Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup(w);
            ctx.GenerateCreationCode(ww, widgetVarExp);
            ctx.EndGeneration();
            warnings.AddRange(ctx.Warnings);
            return(ctx.WidgetMap);
        }
		public static CodeGenerationResult GenerateProjectCode (GenerationOptions options, ProjectBackend[] projects)
		{
			ArrayList warningList = new ArrayList ();
			
			List<SteticCompilationUnit> units = new List<SteticCompilationUnit> ();
			SteticCompilationUnit globalUnit = new SteticCompilationUnit ("");
			units.Add (globalUnit);
			
			if (options == null)
				options = new GenerationOptions ();
			CodeNamespace globalNs = new CodeNamespace (options.GlobalNamespace);
			globalUnit.Namespaces.Add (globalNs);
			
			// Global class
			
			CodeTypeDeclaration globalType = new CodeTypeDeclaration ("Gui");
			globalType.Attributes = MemberAttributes.Private;
			globalType.TypeAttributes = TypeAttributes.NestedAssembly;
			globalNs.Types.Add (globalType);
			
			// Create the project initialization method
			// This method will only be added at the end if there
			// is actually something to initialize
			
			CodeMemberMethod initMethod = new CodeMemberMethod ();
			initMethod.Name = "Initialize";
			initMethod.ReturnType = new CodeTypeReference (typeof(void));
			initMethod.Attributes = MemberAttributes.Assembly | MemberAttributes.Static;
			initMethod.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Gtk.Widget), "iconRenderer"));
			
			GeneratorContext initContext = new ProjectGeneratorContext (globalNs, globalType, initMethod.Statements, options);
			initContext.RootObject = new CodeArgumentReferenceExpression ("iconRenderer");
			
			// Generate icon factory creation

			foreach (ProjectBackend gp in projects) {
				if (gp.IconFactory.Icons.Count > 0)
					gp.IconFactory.GenerateBuildCode (initContext);
			}
			warningList.AddRange (initContext.Warnings);
					
			// Generate the code
			
			if (options.UsePartialClasses)
				CodeGeneratorPartialClass.GenerateProjectGuiCode (globalUnit, globalNs, globalType, options, units, projects, warningList);
			else
				CodeGeneratorInternalClass.GenerateProjectGuiCode (globalUnit, globalNs, globalType, options, units, projects, warningList);

			GenerateProjectActionsCode (globalNs, options, projects);
			
			// Final step. If there is some initialization code, add all needed infrastructure
			
			globalType.Members.Add (initMethod);
			
			CodeMemberField initField = new CodeMemberField (typeof(bool), "initialized");
			initField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
			globalType.Members.Add (initField);
			
			CodeFieldReferenceExpression initVar = new CodeFieldReferenceExpression (
				new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
				"initialized"
			);
			
			CodeConditionStatement initCondition = new CodeConditionStatement ();
			initCondition.Condition = new CodeBinaryOperatorExpression (
				initVar, 
				CodeBinaryOperatorType.IdentityEquality,
				new CodePrimitiveExpression (false)
			);
			initCondition.TrueStatements.Add (new CodeAssignStatement (
				initVar,
				new CodePrimitiveExpression (true)
			));
			initCondition.TrueStatements.AddRange (initMethod.Statements);
			initMethod.Statements.Clear ();
			initMethod.Statements.Add (initCondition);
			
			return new CodeGenerationResult (units.ToArray (), (string[]) warningList.ToArray (typeof(string)));
		}
Esempio n. 6
0
//		public static void GenerateProjectCode (string file, CodeDomProvider provider, GenerationOptions options, ProjectBackend[] projects)
//		{
//			CodeGenerationResult res = GenerateProjectCode (options, projects);
//
//			string basePath = Path.GetDirectoryName (file);
//
//			foreach (SteticCompilationUnit unit in res.Units) {
//				string fname;
//				if (unit.Name.Length == 0)
//					fname = file;
//				else
//					fname = Path.Combine (basePath, unit.Name);
//				StreamWriter fileStream = new StreamWriter (fname);
//				try {
//					provider.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
//				} finally {
//					fileStream.Close ();
//				}
//			}
//		}

        public static CodeGenerationResult GenerateProjectCode(GenerationOptions options, ProjectBackend[] projects)
        {
            ArrayList warningList = new ArrayList();

            List <SteticCompilationUnit> units = new List <SteticCompilationUnit> ();

//			SteticCompilationUnit globalUnit = new SteticCompilationUnit ("");
//			units.Add (globalUnit);

            if (options == null)
            {
                options = new GenerationOptions();
            }
            CodeNamespace globalNs = new CodeNamespace(options.GlobalNamespace);
//			globalUnit.Namespaces.Add (globalNs);

            // Global class

            CodeTypeDeclaration globalType = new CodeTypeDeclaration("Gui");

            globalType.Attributes     = MemberAttributes.Private;
            globalType.TypeAttributes = TypeAttributes.NestedAssembly;
            globalNs.Types.Add(globalType);

            // Create the project initialization method
            // This method will only be added at the end if there
            // is actually something to initialize

            CodeMemberMethod initMethod = new CodeMemberMethod();

            initMethod.Name       = "Initialize";
            initMethod.ReturnType = new CodeTypeReference(typeof(void));
            initMethod.Attributes = MemberAttributes.Assembly | MemberAttributes.Static;
            initMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Gtk.Widget), "iconRenderer"));

            GeneratorContext initContext = new ProjectGeneratorContext(globalNs, globalType, initMethod.Statements, options);

            initContext.RootObject = new CodeArgumentReferenceExpression("iconRenderer");

            // Generate icon factory creation

            foreach (ProjectBackend gp in projects)
            {
                if (gp.IconFactory.Icons.Count > 0)
                {
                    gp.IconFactory.GenerateBuildCode(initContext);
                }
            }
            warningList.AddRange(initContext.Warnings);

            // Generate the code
            CodeGeneratorPartialClass.GenerateProjectGuiCode(globalNs, globalType, options, units, projects, warningList);

            GenerateProjectActionsCode(globalNs, options, projects);

            // Final step. If there is some initialization code, add all needed infrastructure

            globalType.Members.Add(initMethod);

            CodeMemberField initField = new CodeMemberField(typeof(bool), "initialized");

            initField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
            globalType.Members.Add(initField);

            CodeFieldReferenceExpression initVar = new CodeFieldReferenceExpression(
                new CodeTypeReferenceExpression(globalNs.Name + ".Gui"),
                "initialized"
                );

            CodeConditionStatement initCondition = new CodeConditionStatement();

            initCondition.Condition = new CodeBinaryOperatorExpression(
                initVar,
                CodeBinaryOperatorType.IdentityEquality,
                new CodePrimitiveExpression(false)
                );
            initCondition.TrueStatements.Add(new CodeAssignStatement(
                                                 initVar,
                                                 new CodePrimitiveExpression(true)
                                                 ));
            initCondition.TrueStatements.AddRange(initMethod.Statements);
            initMethod.Statements.Clear();
            initMethod.Statements.Add(initCondition);

            //create separate compilation unit for each type in the global namespace
            //and insert them at the begining of the units list.
            int index = 0;

            foreach (CodeTypeDeclaration type in globalNs.Types)
            {
                SteticCompilationUnit unit = new SteticCompilationUnit(type.Name);
                CodeNamespace         ns   = new CodeNamespace(globalNs.Name);

                ns.Types.Add(type);
                unit.Namespaces.Add(ns);
                units.Insert(index++, unit);
            }

            return(new CodeGenerationResult(units.ToArray(), (string[])warningList.ToArray(typeof(string))));
        }