Пример #1
0
        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());
        }
Пример #2
0
        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());
        }
Пример #3
0
        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());
        }
Пример #4
0
        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());
        }
Пример #5
0
        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());
        }
Пример #6
0
        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());
        }
Пример #7
0
        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());
        }
Пример #8
0
        public static string ConvertToMof(AstNode node, MofQuirks quirks = MofQuirks.None)
        {
            if (node == null)
            {
                return(null);
            }
            switch (node)
            {
            case MofSpecificationAst ast:
                // 7.2 MOF specification
                return(AstMofGenerator.ConvertMofSpecificationAst(ast, quirks));

            case CompilerDirectiveAst ast:
                // 7.3 Compiler directives
                return(AstMofGenerator.ConvertCompilerDirectiveAst(ast, quirks));

            case QualifierTypeDeclarationAst ast:
                // 7.4 Qualifiers
                return(AstMofGenerator.ConvertQualifierTypeDeclarationAst(ast, quirks));

            case QualifierListAst ast:
                // 7.4.1 QualifierList
                return(AstMofGenerator.ConvertQualifierListAst(ast, quirks));

            case ClassDeclarationAst ast:
                // 7.5.2 Class declaration
                return(AstMofGenerator.ConvertClassDeclarationAst(ast, quirks));

            case PropertyDeclarationAst ast:
                // 7.5.5 Property declaration
                return(AstMofGenerator.ConvertPropertyDeclarationAst(ast, quirks));

            case MethodDeclarationAst ast:
                // 7.5.6 Method declaration
                return(AstMofGenerator.ConvertMethodDeclarationAst(ast, quirks));

            case ParameterDeclarationAst ast:
                // 7.5.7 Parameter declaration
                return(AstMofGenerator.ConvertParameterDeclarationAst(ast, quirks));

            case ComplexValueArrayAst ast:
                // 7.5.9 Complex type value
                return(AstMofGenerator.ConvertComplexValueArrayAst(ast, quirks));

            case ComplexValueAst ast:
                // 7.5.9 Complex type value
                return(AstMofGenerator.ConvertComplexValueAst(ast, quirks));

            case PropertyValueListAst ast:
                // 7.5.9 Complex type value
                return(AstMofGenerator.ConvertPropertyValueListAst(ast, quirks));

            case LiteralValueArrayAst ast:
                // 7.6.1 Primitive type value
                return(AstMofGenerator.ConvertLiteralValueArrayAst(ast, quirks));

            case IntegerValueAst ast:
                // 7.6.1.1 Integer value
                return(AstMofGenerator.ConvertIntegerValueAst(ast, quirks));

            case RealValueAst ast:
                // 7.6.1.2 Real value
                return(AstMofGenerator.ConvertRealValueAst(ast, quirks));

            case StringValueAst ast:
                // 7.6.1.3 String values
                return(AstMofGenerator.ConvertStringValueAst(ast, quirks));

            case BooleanValueAst ast:
                // 7.6.1.5 Boolean value
                return(AstMofGenerator.ConvertBooleanValueAst(ast, quirks));

            case NullValueAst ast:
                // 7.6.1.6 Null value
                return(AstMofGenerator.ConvertNullValueAst(ast, quirks));

            case InstanceValueDeclarationAst ast:
                // 7.6.2 Complex type value
                return(AstMofGenerator.ConvertInstanceValueDeclarationAst(ast, quirks));

            case StructureValueDeclarationAst ast:
                // 7.6.2 Complex type value
                return(AstMofGenerator.ConvertStructureValueDeclarationAst(ast, quirks));

            case EnumValueAst ast:
                // 7.6.3 Enum type value
                return(AstMofGenerator.ConvertEnumValueAst(ast, quirks));

            case EnumValueArrayAst ast:
                // 7.6.3 Enum type value
                return(AstMofGenerator.ConvertEnumValueArrayAst(ast, quirks));

            case EnumTypeValueAst ast:
                // 7.6.3 Enum type value
                return(AstMofGenerator.ConvertEnumTypeValueAst(ast, quirks));

            case PropertyValueAst ast:
                // 7.5.9 Complex type value
                return(AstMofGenerator.ConvertPropertyValueAst(ast, quirks));

            default:
                // unknown
                throw new InvalidOperationException(node.GetType().FullName);
            }
        }