internal protected override void Visit(StringBuilder builder, YField field) { StringBuilder b; if (field.Visibility == Public) { b = GetBuilder(Public, Field); } else if (field.Visibility == Private) { b = GetBuilder(Private, Field); } else { throw new TException("Unsupported access"); } b.Append(_typeMapper.ValueOf(field.Type)); b.Append(" " + field.Name); if (field.Value != null) { if (field.Value is YConstExpr) { b.Append("=" + field.Value); } else { throw new TException("Unsupported expr"); } } b.Append(";"); }
protected override void Visit(YField @field) { if (_w.Class.ParentOf(field)) { _w.Visit(_w._builder, @field); } }
internal protected override void Visit(StringBuilder builder, YField field) { base.Visit(builder, field); if (field.Value is YConstExpr) { if (_constructorInited) { _constructor.Append(":"); _constructorInited = false; } else { _constructor.Append(","); } _constructor.Append(field.Name + "{" + field.Value + "}"); } }
protected virtual void Visit(YField @field) { }
internal protected virtual void Visit(StringBuilder builder, YField @field) { }
void ProcessClasses(YNamespace @namespace, NamespaceDeclarationSyntax inputNamespace) { // Classes: foreach (var inputClass in inputNamespace.ChildNodes().OfType <ClassDeclarationSyntax>()) { var className = inputClass.GetName(); if (className == "") { continue; } var @class = new YClass(className); @namespace.AddChild(@class); _generationUnits.Add(new GenerationUnit(@class)); // Fields: foreach (var inputField in inputClass.ChildNodes().OfType <FieldDeclarationSyntax>()) { var declaration = inputField.Declaration; var declarationType = declaration.Type; var variables = declaration.Variables; if (variables.Count == 1) { var variable = variables[0]; var field = new YField() { Type = declarationType.GetYType(), Name = variable.GetName() }; field.Visibility = inputField.Modifiers.GetYVisibility(); // expresions: literal // todo process negative numbers if (variable.Initializer?.Value is LiteralExpressionSyntax) { var literalExperssion = (LiteralExpressionSyntax)variable.Initializer.Value; if (literalExperssion.Token.Value is int) { field.Value = new YConstExpr((int)literalExperssion.Token.Value); } } @class.AddChild(field); } else { throw new TException("Unsupported"); } } // Methods: foreach (var inputMethod in inputClass.ChildNodes().OfType <MethodDeclarationSyntax>()) { var name = inputMethod.Identifier.ToString(); var methodReturnType = inputMethod.ReturnType; var parameterList = inputMethod.ParameterList; YMethod method; // Signature: if (parameterList.Parameters.Count() <= 0) { method = new YMethod(name, inputMethod.ReturnType.GetYType()); } else { var @params = new List <YParameter>(); foreach (var p in parameterList.Parameters) { @params.Add(new YParameter(p.GetName(), p.Type.GetYType())); } method = new YMethod(name, inputMethod.ReturnType.GetYType(), @params.ToArray()); } // Body: method.Visibility = inputMethod.Modifiers.GetYVisibility(); method.Body = ProcessStatement(inputMethod.Body); @class.AddChild(method); } } }