예제 #1
0
 public TextAnnotation(string text, FilePosition filePosition, WarningList warnings) : base(text, filePosition)
 {
     if (Value == null)
     {
         warnings.Add(filePosition, WarningType.IncompleteAnnotation,
                      "{0} annotation is missing its value.", Command);
     }
 }
예제 #2
0
 public OptionalInParameterAnnotation(string text, FilePosition filePosition, WarningList warnings)
     : base(text, filePosition, warnings)
 {
     if (Name == null)
     {
         warnings.Add(filePosition, WarningType.IncompleteAnnotation,
                      "{0} annotation with type '{1}' is missing its name (2nd word).", Command, Type);
     }
     // Let's not insist on a description for well-named parameters.
 }
예제 #3
0
 protected FieldAnnotation(string text, FilePosition filePosition, WarningList warnings) : base(text, filePosition)
 {
     if (Name == null)
     {
         warnings.Add(filePosition, WarningType.IncompleteAnnotation,
                      "{0} annotation is missing its name (1st word).", Command);
     }
     if (Description == null)
     {
         warnings.Add(filePosition, WarningType.IncompleteAnnotation,
                      "{0} annotation '{1}' is missing its description (2nd word+).", Command, Name);
     }
 }
예제 #4
0
        protected ParameterAnnotation(string text, FilePosition filePosition, WarningList warnings) : base(text, filePosition)
        {
            if (Type == null)
            {
                warnings.Add(filePosition, WarningType.IncompleteAnnotation,
                             "{0} annotation is missing its type (1st word).", Command);
            }
            // Not all parameter annotations require a type or name.
            // Let the derived classes decide.

            if (Description != null && WhitespaceAfterElements[2] == " ")
            {
                // There is only a single space before the description
                warnings.Add(filePosition, WarningType.HeuristicWarning,
                             "{0} annotation has only a single space between its name ('{1}') and its description ('{2}'). This often indicates that the description is not self-contained.",
                             Command, Name, Description.GetExcerpt());
            }
        }
예제 #5
0
        public static Annotation Create(string text, FilePosition filePosition, WarningList warnings)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentException("text is empty.");
            }

            Match  match   = wordWithWhitespaceRegex.Match(text.Trim());
            string command = match.Groups["word"].Value;

            switch (command)
            {
            case "@lua":
                return(new LuaNameAnnotation(text, filePosition, warnings));

            case "@text":
                return(new TextAnnotation(text, filePosition, warnings));

            case "@const":
                return(new ConstantAnnotation(text, filePosition, warnings));

            case "@flag":
                return(new FlagAnnotation(text, filePosition, warnings));

            case "@attr":
                return(new AttributeAnnotation(text, filePosition, warnings));

            case "@in":
                return(new InParameterAnnotation(text, filePosition, warnings));

            case "@opt":
                return(new OptionalInParameterAnnotation(text, filePosition, warnings));

            case "@out":
                return(new OutParameterAnnotation(text, filePosition, warnings));

            case "@overload":
                return(new OverloadAnnotation(text, filePosition));

            default:
                return(new UnknownAnnotation(text, filePosition));
            }
        }
예제 #6
0
 public OutParameterAnnotation(string text, FilePosition filePosition, WarningList warnings)
     : base(text, filePosition, warnings)
 {
 }
예제 #7
0
 public AttributeAnnotation(string text, FilePosition filePosition, WarningList warnings)
     : base(text, filePosition, warnings)
 {
 }
예제 #8
0
 public ConstantAnnotation(string text, FilePosition filePosition, WarningList warnings)
     : base(text, filePosition, warnings)
 {
 }
예제 #9
0
        public void Parse(DirectoryInfo moaiDirectory)
        {
            // Check that the input directory looks like the Moai main directory
            if (!moaiDirectory.GetDirectoryInfo(@"src\moai-core").Exists)
            {
                throw new PlainTextException(string.Format("Path '{0}' does not appear to be the base directory of a Moai source copy.", moaiDirectory));
            }

            // Initialize warning list
            Warnings = new WarningList();

            // Get Moai version
            MoaiVersionInfo = new MoaiVersionInfo(moaiDirectory);
            statusCallback(string.Format("Found {0}.", MoaiVersionInfo));

            // Initialize type list with primitive types
            types = new TypeCollection(includePrimitives: true, includeVariant: true);

            // Parse Moai classes and store them by class name
            statusCallback("Parsing Moai classes.");
            ParseMoaiCodeFiles(moaiDirectory);



            // Mark registered classes as scriptable
            statusCallback("Checking which classes are registered to be scriptable from Lua.");
            MarkScriptableClasses(moaiDirectory);


            // MOAILuaObject is not documented, probably because it would mess up
            // the Doxygen-generated documentation. Use dummy code instead.
            statusCallback("Adding hard-coded documentation for MOAILuaObject base class.");
            FilePosition dummyFilePosition = new FilePosition(new FileInfo("MOAILuaObject dummy code"));

            FileParser.ParseMoaiCodeFile(MOAILuaObject.DummyCode, dummyFilePosition, types, Warnings);

            // Make sure every class directly or indirectly inherits from MOAILuaObject
            MoaiClass luaObjectClass = (MoaiClass)types.GetOrCreate("MOAILuaObject", null);

            foreach (MoaiClass moaiClass in types.OfType <MoaiClass>().Where(x => x.IsScriptable))
            {
                if (!(moaiClass.AncestorClasses.Contains(luaObjectClass)) && moaiClass != luaObjectClass)
                {
                    moaiClass.BaseClasses.Add(luaObjectClass);
                }
                // Make sure every class has a new
                if (moaiClass.Members.FirstOrDefault(x => x.Name == "new") == null && moaiClass.ClassPosition != null)
                {
                    moaiClass.Members.Add(
                        new Method()
                    {
                        OutParameterSignature = new MoaiParsing.Parameter()
                        {
                            Name = "object", Type = moaiClass.Name
                        },
                        Name           = "new",
                        Description    = "Create new instance of " + moaiClass.Name,
                        OwningClass    = moaiClass,
                        Body           = "",
                        MethodPosition = new MethodPosition(moaiClass.ClassPosition, "_new"),
                        Overloads      = { new MethodOverload()
                                           {
                                               InParameters  =   {                     },
                                               IsStatic      = true,
                                               OutParameters =   { new OutParameter()
                                                                   {
                                                                       Description = "Result", Name = "object", Type = moaiClass
                                                                   } }
                                           } }
                    }
                        );
                }
            }

            // Perform additional checks that do not alter the code graph
            var checks = GetChecks();

            statusCallback(string.Format("Performing {0} additional code checks.", checks.Length));
            PerformChecks(checks, moaiDirectory);
        }