public static string ConvertInstanceValueDeclarationAst(InstanceValueDeclarationAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { // instance of myType as $Alias00000070 // { // Reference = TRUE; // }; var source = new StringBuilder(); // instance of myType as $Alias00000070 source.Append(node.Instance.Extent.Text); source.Append(" "); source.Append(node.Of.Extent.Text); source.Append(" "); source.Append(node.TypeName.Name); if (node.Alias != null) { source.Append(" "); source.Append(node.As.Extent.Text); source.Append(" "); source.Append("$"); source.Append(node.Alias.Name); } source.AppendLine(); // { // Reference = TRUE; // } source.Append(AstMofGenerator.ConvertPropertyValueListAst(node.PropertyValues, quirks, indent)); // ; source.Append(node.StatementEnd.Extent.Text); return(source.ToString()); }
public static string ConvertParameterDeclarationAst(ParameterDeclarationAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.Append(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); source.Append(" "); } source.Append(node.ParameterType.Name); source.Append(" "); if (node.ParameterIsRef) { source.Append(node.ParameterRef.Name); source.Append(" "); } source.Append(node.ParameterName.Name); if (node.ParameterIsArray) { source.Append("[]"); } if (node.DefaultValue != null) { source.Append(" = "); source.Append(AstMofGenerator.ConvertPropertyValueAst(node.DefaultValue, quirks)); } return(source.ToString()); }
public static string ConvertPropertyDeclarationAst(PropertyDeclarationAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.Append(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); source.Append(" "); } source.Append(node.ReturnType.Name); source.Append(" "); if (node.ReturnTypeIsRef) { source.Append(node.ReturnTypeRef.Name); source.Append(" "); } source.Append(node.PropertyName.Name); if (node.ReturnTypeIsArray) { source.Append("[]"); } if (node.Initializer != null) { source.Append(" = "); source.Append(AstMofGenerator.ConvertPropertyValueAst(node.Initializer, quirks)); } source.Append(";"); return(source.ToString()); }
public static string ConvertMofProductionAst(MofProductionAst node, MofQuirks quirks = MofQuirks.None) { switch (node) { case CompilerDirectiveAst ast: return(AstMofGenerator.ConvertCompilerDirectiveAst(ast, quirks)); case StructureDeclarationAst ast: return(AstMofGenerator.ConvertStructureDeclarationAst(ast, quirks)); case ClassDeclarationAst ast: return(AstMofGenerator.ConvertClassDeclarationAst(ast, quirks)); case AssociationDeclarationAst ast: return(AstMofGenerator.ConvertAssociationDeclarationAst(ast, quirks)); case EnumerationDeclarationAst ast: return(AstMofGenerator.ConvertEnumerationDeclarationAst(ast, quirks)); case InstanceValueDeclarationAst ast: return(AstMofGenerator.ConvertInstanceValueDeclarationAst(ast, quirks)); case StructureValueDeclarationAst ast: return(AstMofGenerator.ConvertStructureValueDeclarationAst(ast, quirks)); case QualifierTypeDeclarationAst ast: return(AstMofGenerator.ConvertQualifierTypeDeclarationAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertComplexValueAst(ComplexValueAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { if (node.IsAlias) { return($"${node.Alias.Name}"); } else { var source = new StringBuilder(); // value of GOLF_PhoneNumber source.Append(node.Value.Extent.Text); source.Append(" "); source.Append(node.Of.Extent.Text); source.Append(" "); source.Append(node.TypeName.Name); source.AppendLine(); // { // AreaCode = { "9", "0", "7" }; // Number = { "7", "4", "7", "4", "8", "8", "4" }; // } source.Append(indent); source.Append(AstMofGenerator.ConvertPropertyValueListAst(node.PropertyValues, quirks, indent)); return(source.ToString()); } }
public static string ConvertAssociationDeclarationAst(AssociationDeclarationAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.AppendLine(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); source.Append(indent); } source.Append($"{Constants.ASSOCIATION} {node.AssociationName.Name}"); if (node.SuperAssociation != null) { source.Append($" : {node.SuperAssociation.Name}"); } source.AppendLine(); source.Append(indent); source.AppendLine("{"); foreach (var classFeature in node.ClassFeatures) { source.Append(indent); source.Append("\t"); source.AppendLine(AstMofGenerator.ConvertClassFeatureAst(classFeature, quirks, indent + '\t')); } source.Append(indent); source.Append("};"); return(source.ToString()); }
public static string ConvertEnumerationDeclarationAst(EnumerationDeclarationAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.AppendLine(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); source.Append(indent); } source.Append($"{Constants.ENUMERATION} {node.EnumName.Name}"); source.Append($" : {node.EnumType.Name}"); source.AppendLine(); source.Append(indent); source.AppendLine("{"); for (var i = 0; i < node.EnumElements.Count; i++) { source.Append(indent); source.Append("\t"); source.Append(AstMofGenerator.ConvertEnumElementAst(node.EnumElements[i], quirks)); if (i < (node.EnumElements.Count - 1)) { source.Append(","); } source.AppendLine(); } source.Append(indent); source.Append("};"); return(source.ToString()); }
public static string ConvertStructureValueDeclarationAst(StructureValueDeclarationAst node, MofQuirks quirks = MofQuirks.None) { // value of GOLF_PhoneNumber as $JohnDoesPhoneNo // { // AreaCode = { "9", "0", "7" }; // Number = { "7", "4", "7", "4", "8", "8", "4" }; // }; var source = new StringBuilder(); // value of GOLF_PhoneNumber as $JohnDoesPhoneNo source.Append(node.Value.Extent.Text); source.Append(" "); source.Append(node.Of.Extent.Text); source.Append(" "); source.Append(node.TypeName.Name); if (node.Alias != null) { source.Append(" "); source.Append(node.As.Extent.Text); source.Append(" $"); source.Append(node.Alias.Name); } source.AppendLine(); // { // AreaCode = { "9", "0", "7" }; // Number = { "7", "4", "7", "4", "8", "8", "4" }; // } source.Append(AstMofGenerator.ConvertPropertyValueListAst(node.PropertyValues, quirks)); // ; source.Append(node.StatementEnd.Extent.Text); return(source.ToString()); }
public static string ConvertStructureDeclarationAst(StructureDeclarationAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.AppendLine(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); source.Append(indent); } source.Append($"{Constants.STRUCTURE} {node.StructureName.Name}"); if (node.SuperStructure != null) { source.Append($" : {node.SuperStructure.Name}"); } source.AppendLine(); source.Append(indent); source.AppendLine("{"); foreach (var structureFeature in node.StructureFeatures) { source.Append(indent); source.Append("\t"); source.AppendLine(AstMofGenerator.ConvertStructureFeatureAst(structureFeature, quirks, indent + '\t')); } source.Append(indent); source.Append("};"); return(source.ToString()); }
public static string ConvertQualifierValueAst(QualifierValueAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); source.Append(node.QualifierName.Extent.Text); if (node.Initializer != null) { source.Append(AstMofGenerator.ConvertIQualifierInitializerAst(node.Initializer)); } /// /// 7.4 Qualifiers /// /// NOTE A MOF v2 qualifier declaration has to be converted to MOF v3 qualifierTypeDeclaration because the /// MOF v2 qualifier flavor has been replaced by the MOF v3 qualifierPolicy. /// /// These aren't part of the MOF 3.0.1 spec, but we'll include them anyway for backward compatibility. /// if (node.Flavors.Any()) { source.Append(": "); source.Append( string.Join( " ", node.Flavors.Select(f => f.Name) ) ); } return(source.ToString()); }
public static string ConvertQualifierListAst(QualifierListAst node, MofQuirks quirks = MofQuirks.None) { // [Abstract, OCL] var omitSpacesQuirkEnabled = (quirks & MofQuirks.OmitSpaceBetweenInOutQualifiersForParameterDeclarations) == MofQuirks.OmitSpaceBetweenInOutQualifiersForParameterDeclarations; var source = new StringBuilder(); var lastQualifierName = default(string); source.Append("["); for (var i = 0; i < node.QualifierValues.Count; i++) { var thisQualifierValue = node.QualifierValues[i]; var thisQualifierName = thisQualifierValue.QualifierName.GetNormalizedName(); if (i > 0) { source.Append(","); if (!omitSpacesQuirkEnabled || (lastQualifierName != "in") || (thisQualifierName != "out")) { source.Append(" "); } } source.Append(AstMofGenerator.ConvertQualifierValueAst(thisQualifierValue, quirks)); lastQualifierName = thisQualifierName; } source.Append("]"); return(source.ToString()); }
public static string ConvertStringValueAst(StringValueAst node, MofQuirks quirks = MofQuirks.None) { return(string.Join( " ", node.StringLiteralValues .Select(n => $"\"{AstMofGenerator.EscapeString(n.Value)}\"") )); }
public static string ConvertQualifierValueInitializerAst(QualifierValueInitializerAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); // e.g. // Description("an instance of a class that derives from the GOLF_Base class. ") source.Append("("); source.Append(AstMofGenerator.ConvertLiteralValueAst(node.Value, quirks)); source.Append(")"); return(source.ToString()); }
public static string ConvertCompilerDirectiveAst(CompilerDirectiveAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); source.Append(node.PragmaKeyword.Extent.Text); source.Append(" "); source.Append(node.PragmaName); source.Append(" "); source.Append("("); source.Append(AstMofGenerator.ConvertStringValueAst(node.PragmaParameter)); source.Append(")"); return(source.ToString()); }
public static string ConvertIEnumElementValueAst(IEnumElementValueAst node, MofQuirks quirks = MofQuirks.None) { switch (node) { case IntegerValueAst ast: return(AstMofGenerator.ConvertIntegerValueAst(ast, quirks)); case StringValueAst ast: return(AstMofGenerator.ConvertStringValueAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertClassFeatureAst(IClassFeatureAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { switch (node) { case IStructureFeatureAst ast: return(AstMofGenerator.ConvertStructureFeatureAst(ast, quirks, indent)); case MethodDeclarationAst ast: return(AstMofGenerator.ConvertMethodDeclarationAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertComplexTypeValueAst(ComplexTypeValueAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { switch (node) { case ComplexValueArrayAst ast: return(AstMofGenerator.ConvertComplexValueArrayAst(ast, quirks, indent)); case ComplexValueAst ast: return(AstMofGenerator.ConvertComplexValueAst(ast, quirks, indent)); default: throw new NotImplementedException(); } }
public static string ConvertIQualifierInitializerAst(IQualifierInitializerAst node, MofQuirks quirks = MofQuirks.None) { switch (node) { case QualifierValueInitializerAst ast: return(AstMofGenerator.ConvertQualifierValueInitializerAst(ast, quirks)); case QualifierValueArrayInitializerAst ast: return(AstMofGenerator.ConvertQualifierValueArrayInitializerAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertEnumValueArrayAst(EnumValueArrayAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); source.Append("{"); source.Append( string.Join( ", ", node.Values.Select(v => AstMofGenerator.ConvertEnumValueAst(v, quirks)) ) ); source.Append("}"); return(source.ToString()); }
public static string ConvertEnumTypeValueAst(EnumTypeValueAst node, MofQuirks quirks = MofQuirks.None) { switch (node) { case EnumValueAst ast: return(AstMofGenerator.ConvertEnumValueAst(ast, quirks)); case EnumValueArrayAst ast: return(AstMofGenerator.ConvertEnumValueArrayAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertMofSpecificationAst(MofSpecificationAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); for (var i = 0; i < node.Productions.Count; i++) { if (i > 0) { source.AppendLine(); } source.Append(AstMofGenerator.ConvertMofProductionAst(node.Productions[i], quirks)); } return(source.ToString()); }
public static string ConvertPrimitiveTypeValueAst(PrimitiveTypeValueAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { switch (node) { case LiteralValueAst ast: return(AstMofGenerator.ConvertLiteralValueAst(ast, quirks)); case LiteralValueArrayAst ast: return(AstMofGenerator.ConvertLiteralValueArrayAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertComplexValueArrayAst(ComplexValueArrayAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { var source = new StringBuilder(); source.Append("{"); source.Append( string.Join( ", ", node.Values .Select(n => AstMofGenerator.ConvertComplexValueAst(n, quirks, indent)) ) ); source.Append("}"); return(source.ToString()); }
public static string ConvertStructureFeatureAst(IStructureFeatureAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { switch (node) { case StructureDeclarationAst ast: return(AstMofGenerator.ConvertStructureDeclarationAst(ast, quirks, indent)); case EnumerationDeclarationAst ast: return(AstMofGenerator.ConvertEnumerationDeclarationAst(ast, quirks, indent)); case PropertyDeclarationAst ast: return(AstMofGenerator.ConvertPropertyDeclarationAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertEnumElementAst(EnumElementAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.Append(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); source.Append(" "); } source.Append(node.EnumElementName.Name); if (node.EnumElementValue != null) { source.Append(" = "); source.Append(AstMofGenerator.ConvertIEnumElementValueAst(node.EnumElementValue, quirks)); } return(source.ToString()); }
public static string ConvertPropertyValueAst(PropertyValueAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { switch (node) { case PrimitiveTypeValueAst ast: return(AstMofGenerator.ConvertPrimitiveTypeValueAst(ast, quirks, indent)); case ComplexTypeValueAst ast: return(AstMofGenerator.ConvertComplexTypeValueAst(ast, quirks, indent)); //case ReferenceTypeValueAst ast: case EnumTypeValueAst ast: return(AstMofGenerator.ConvertEnumTypeValueAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertQualifierValueArrayInitializerAst(QualifierValueArrayInitializerAst node, MofQuirks quirks = MofQuirks.None) { var source = new StringBuilder(); // e.g. // OCL{"-- the key property cannot be NULL", "inv: InstanceId.size() = 10"} source.Append("{"); var index = 0; foreach (var value in node.Values) { if (index > 0) { source.Append(", "); } source.Append(AstMofGenerator.ConvertLiteralValueAst(value, quirks)); index++; } source.Append("}"); return(source.ToString()); }
public static string ConvertMethodDeclarationAst(MethodDeclarationAst node, MofQuirks quirks = MofQuirks.None) { var prefixQuirkEnabled = (quirks & MofQuirks.PrefixSpaceBeforeQualifierlessMethodDeclarations) == MofQuirks.PrefixSpaceBeforeQualifierlessMethodDeclarations; var source = new StringBuilder(); if (node.QualifierList.QualifierValues.Any()) { source.Append(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks)); } if (prefixQuirkEnabled || node.QualifierList.QualifierValues.Any()) { source.Append(" "); } source.Append(node.ReturnType.Name); if (node.ReturnTypeIsArray) { source.Append("[]"); } source.Append(" "); source.Append(node.Name.Name); if (node.Parameters.Count == 0) { source.Append("();"); } else { var values = node.Parameters.Select(p => AstMofGenerator.ConvertParameterDeclarationAst(p, quirks)).ToArray(); source.Append("("); source.Append(string.Join(", ", values)); source.Append(");"); } return(source.ToString()); }
public static string ConvertLiteralValueAst(LiteralValueAst node, MofQuirks quirks = MofQuirks.None) { switch (node) { case IntegerValueAst ast: return(AstMofGenerator.ConvertIntegerValueAst(ast, quirks)); case RealValueAst ast: return(AstMofGenerator.ConvertRealValueAst(ast, quirks)); case BooleanValueAst ast: return(AstMofGenerator.ConvertBooleanValueAst(ast, quirks)); case NullValueAst ast: return(AstMofGenerator.ConvertNullValueAst(ast, quirks)); case StringValueAst ast: return(AstMofGenerator.ConvertStringValueAst(ast, quirks)); default: throw new NotImplementedException(); } }
public static string ConvertPropertyValueListAst(PropertyValueListAst node, MofQuirks quirks = MofQuirks.None, string indent = "") { // { var source = new StringBuilder(); source.Append("{"); source.AppendLine(); // Reference = TRUE; foreach (var propertyValue in node.PropertyValues) { source.Append(indent); source.Append("\t"); source.Append(propertyValue.Key); source.Append(" = "); source.Append(AstMofGenerator.ConvertPropertyValueAst(propertyValue.Value, quirks, indent + "\t")); source.Append(";"); source.AppendLine(); } // } source.Append(indent); source.Append("}"); return(source.ToString()); }