/// <summary> /// Init the global code with the list of global declarations. /// </summary> /// <param name="decls">List of classes and methods in the global code.</param> public GlobalCode(DeclarationsList decls) : base(decls.Position) { Debug.Assert(decls != null); this.Declarations = decls; }
/// <summary> /// Init. /// </summary> /// <param name="declarations"></param> public EmitCodeContext(DeclarationsList declarations, StreamWriter output, string namespaceName, string contextName) { Debug.Assert(declarations != null); Debug.Assert(output != null); this.Output = output; this.Declarations = declarations; this.NamespaceName = namespaceName; this.ContextName = contextName; }
/// <summary> /// Copz Code context with different output. /// </summary> /// <param name="codecontext"></param> /// <param name="output"></param> public EmitCodeContext(EmitCodeContext codecontext, StreamWriter output) { this.Output = output; this.Declarations = codecontext.Declarations; this.Level = codecontext.Level; this.NamespaceName = codecontext.NamespaceName; this.ContextName = codecontext.ContextName; foreach (var x in codecontext.DeclaredLocalVars) { DeclaredLocalVars[x.Key] = x.Value; } }
/// <summary> /// Init declarations list with one class declaration. /// </summary> /// <param name="position"></param> /// <param name="classdecl"></param> public DeclarationsList(ExprPosition position, DeclarationsList decls, ClassDecl classdecl) : this(position) { if (decls != null) { Classes = decls.Classes; Methods.AddRange(decls.Methods); } if (classdecl != null) { Classes.Add(classdecl.ClassName, classdecl); } }
/// <summary> /// Init declarations list with one method declaration. /// </summary> /// <param name="position"></param> /// <param name="methoddecl"></param> public DeclarationsList(ExprPosition position, DeclarationsList decls, MethodDecl methoddecl) : this(position) { if (decls != null) { Classes = decls.Classes; Methods.AddRange(decls.Methods); } if (methoddecl != null) { if (!methoddecl.IsMainMethod) { foreach (var m in Methods) { if (m.DeclMethodName == methoddecl.DeclMethodName) { // arguments must match if (m.MethodArguments.Count != methoddecl.MethodArguments.Count) { throw new GeneratorException(position, "Methods " + methoddecl.DeclMethodName + ": Arguments mishmash."); } for (int arg = 0; arg < m.MethodArguments.Count; ++arg) { if (!m.MethodArguments[arg].VariableType.Equals(methoddecl.MethodArguments[arg].VariableType)) { throw new GeneratorException(position, "Methods " + methoddecl.DeclMethodName + ": Arguments mishmash."); } if (m.MethodArguments[arg].VariableName != methoddecl.MethodArguments[arg].VariableName) { throw new GeneratorException(position, "Methods " + methoddecl.DeclMethodName + ": Arguments mishmash."); } } } } } Methods.Insert(0, methoddecl); } }