Ejemplo n.º 1
0
        public ClassDefinition(
            Token classToken,
            Token nameToken,
            IList <Token> subclassTokens,
            IList <string> subclassNames,
            TopLevelConstruct owner,
            LibraryMetadata library,
            Token staticToken,
            Token finalToken,
            FileScope fileScope,
            AnnotationCollection annotations)
            : base(classToken, owner, fileScope)
        {
            this.Library = library;
            this.ClassID = ClassDefinition.classIdAlloc++;

            this.NameToken             = nameToken;
            this.BaseClassTokens       = subclassTokens.ToArray();
            this.BaseClassDeclarations = subclassNames.ToArray();
            this.StaticToken           = staticToken;
            this.FinalToken            = finalToken;
            this.annotations           = annotations;

            if (staticToken != null && this.BaseClassTokens.Length > 0)
            {
                throw new ParserException(staticToken, "Class cannot be static and have base classes or interfaces.");
            }
        }
Ejemplo n.º 2
0
        public Namespace(
            Token namespaceToken,
            string name,
            TopLevelConstruct owner,
            LibraryMetadata library,
            FileScope fileScope,
            AnnotationCollection annotations)
            : base(namespaceToken, owner, fileScope)
        {
            this.Library     = library;
            this.DefaultName = name;
            this.FullyQualifiedDefaultName = owner == null
                ? name
                : (((Namespace)owner).FullyQualifiedDefaultName + "." + name);
            this.FullyQualifiedDefaultNameSegments = this.FullyQualifiedDefaultName.Split('.');
            this.DefaultNameSegments = this.DefaultName.Split('.');

            this.NamesByLocale = annotations.GetNamesByLocale(this.DefaultNameSegments.Length)
                                 .ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Split('.'));

            Locale defaultLocale = fileScope.CompilationScope.Locale;

            if (!this.NamesByLocale.ContainsKey(defaultLocale))
            {
                this.NamesByLocale[defaultLocale] = this.DefaultName.Split('.');
            }

            this.NestDepth = this.FullyQualifiedDefaultNameSegments.Length - this.DefaultNameSegments.Length;
        }
Ejemplo n.º 3
0
 public ImportStatement(Token importToken, string path, LibraryMetadata callingLibrary, FileScope fileScope)
     : base(importToken, null, fileScope)
 {
     this.Library    = callingLibrary;
     this.ImportPath = path;
     fileScope.Imports.Add(this);
 }
Ejemplo n.º 4
0
        private LibraryExporter(LibraryMetadata metadata, Platform.AbstractPlatform platform)
        {
            TODO.LibrariesNeedVersionNumber();

            this.Metadata     = metadata;
            this.platformName = platform.Name;

            this.Resources = new LibraryResourceDatabase(this, platform);

            this.CompileTimeConstants = this.LoadFlagsForPlatform(platform);

            this.filepathsByFunctionName = new Dictionary <string, string>();
            // Build a lookup dictionary of all file names that are simple function names e.g. "foo.cry"
            // Then go through and look up all the file names that contain . prefixes with the platform name and
            // overwrite the lookup value for that entry with the more specific path.
            // myFunction.cry
            // android.myFunction.cry
            // on Python, myFunction will be included for lib_foo_myFunction(), but on Android, android.myFunction.cry will be included instead.

            string[] files = new string[0];
            if (FileUtil.DirectoryExists(this.Metadata.Directory + "/translate"))
            {
                files = FileUtil.DirectoryListFileNames(FileUtil.JoinPath(this.Metadata.Directory, "translate"));
            }
            Dictionary <string, string> moreSpecificFiles = new Dictionary <string, string>();

            foreach (string file in files)
            {
                if (file.EndsWith(".pst"))
                {
                    string functionName = file.Substring(0, file.Length - ".pst".Length);
                    if (functionName.Contains('.'))
                    {
                        // Add this file to the more specific lookup, but only if it contains the current platform.
                        if (functionName.StartsWith(platformName + ".") ||
                            functionName.Contains("." + platformName + "."))
                        {
                            string[] parts = functionName.Split('.');
                            moreSpecificFiles[parts[parts.Length - 1]] = file;
                        }
                        else
                        {
                            // just let it get filtered away.
                        }
                    }
                    else
                    {
                        this.filepathsByFunctionName[functionName] = file;
                    }
                }
            }

            foreach (string functionName in moreSpecificFiles.Keys)
            {
                this.filepathsByFunctionName[functionName] = moreSpecificFiles[functionName];
            }
        }
Ejemplo n.º 5
0
        // TODO: this ought to go away and the cache needs to move to some sort of scope whose lifetime is tied to a specific compilation scope.
        public static LibraryExporter Get(LibraryMetadata metadata, Platform.AbstractPlatform platform)
        {
            string key = GetLibKey(metadata, platform);

            if (!libraryCache.ContainsKey(key))
            {
                libraryCache[key] = new LibraryExporter(metadata, platform);
            }
            return(libraryCache[key]);
        }
Ejemplo n.º 6
0
 public ConstStatement(
     Token constToken,
     Token nameToken,
     TopLevelConstruct owner,
     LibraryMetadata library,
     FileScope fileScope,
     AnnotationCollection annotations)
     : base(constToken, owner, fileScope)
 {
     this.Library     = library;
     this.NameToken   = nameToken;
     this.Name        = nameToken.Value;
     this.annotations = annotations;
 }
Ejemplo n.º 7
0
 public EnumDefinition(
     Token enumToken,
     Token nameToken,
     TopLevelConstruct owner,
     LibraryMetadata library,
     FileScope fileScope,
     AnnotationCollection annotations)
     : base(enumToken, owner, fileScope)
 {
     this.Library     = library;
     this.NameToken   = nameToken;
     this.Name        = nameToken.Value;
     this.annotations = annotations;
 }
Ejemplo n.º 8
0
 public FunctionDefinition(
     Token functionToken,
     LibraryMetadata library,
     TopLevelConstruct nullableOwner,
     bool isStaticMethod,
     Token nameToken,
     AnnotationCollection annotations,
     FileScope fileScope)
     : base(functionToken, nullableOwner, fileScope)
 {
     this.Library        = library;
     this.IsStaticMethod = isStaticMethod;
     this.NameToken      = nameToken;
     this.Annotations    = annotations;
     this.MemberID       = -1;
 }
Ejemplo n.º 9
0
 private static string GetLibKey(LibraryMetadata metadata, Platform.AbstractPlatform platform)
 {
     return(metadata.CanonicalKey + "#" + platform.Name);
 }
 public LibraryNativeInvocationTranslator(LibraryMetadata library, LibraryForExport lfe)
 {
     this.library = library;
     this.Library = lfe;
 }