예제 #1
0
 Create(
     string tokenizedString,
     Module macroSource,
     TokenizedStringArray positionalTokens = null)
 {
     return(CreateInternal(tokenizedString, macroSource, false, positionalTokens, EFlags.None));
 }
예제 #2
0
        CreateInternal(
            string tokenizedString,
            Module macroSource,
            bool verbatim,
            TokenizedStringArray positionalTokens,
            EFlags flags)
        {
            if (null == tokenizedString)
            {
                return(null);
            }

            // strings can be created during the multithreaded phase
            lock (Cache)
            {
                if (0 == (flags & EFlags.NoCache))
                {
                    var search = Cache.Where((ts) =>
                    {
                        // first check the simple states for equivalence
                        if (ts.OriginalString == tokenizedString && ts.ModuleWithMacros == macroSource && ts.Verbatim == verbatim)
                        {
                            // and then check the positional tokens, if they exist
                            var samePosTokenCount = ((null != positionalTokens) && (positionalTokens.Count() == ts.PositionalTokens.Count())) ||
                                                    ((null == positionalTokens) && (0 == ts.PositionalTokens.Count()));
                            if (!samePosTokenCount)
                            {
                                return(false);
                            }
                            for (int i = 0; i < ts.PositionalTokens.Count(); ++i)
                            {
                                // because positional tokens are TokenizedStrings, they will refer to the same object
                                if (ts.PositionalTokens[i] != positionalTokens[i])
                                {
                                    return(false);
                                }
                            }
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    });
                    var foundTS = search.FirstOrDefault();
                    if (null != foundTS)
                    {
                        ++foundTS.RefCount;
                        return(foundTS);
                    }
                }
                var newTS = new TokenizedString(tokenizedString, macroSource, verbatim, positionalTokens, flags);
                Cache.Add(newTS);
                return(newTS);
            }
        }
예제 #3
0
        CreateTokenizedString(
            string format,
            params TokenizedString[] argv)
        {
            if (0 == argv.Length)
            {
                return(TokenizedString.Create(format, this));
            }
            var positionalTokens = new TokenizedStringArray(argv);

            return(TokenizedString.Create(format, this, positionalTokens));
        }
예제 #4
0
 private TokenizedString(
     string original,
     Module moduleWithMacros,
     bool verbatim,
     TokenizedStringArray positionalTokens,
     EFlags flags)
 {
     this.CreationStackTrace = System.Environment.StackTrace;
     this.ModuleWithMacros   = moduleWithMacros;
     if (null != positionalTokens)
     {
         this.PositionalTokens.AddRange(positionalTokens);
     }
     this.Verbatim       = verbatim;
     this.Flags         |= flags;
     this.OriginalString = original;
     if (verbatim)
     {
         this.ParsedString = NormalizeDirectorySeparators(original);
         return;
     }
 }
 configure(
     string architecture)
 {
     // WindowsSDK 10 has a bin folder in different places depending on the version (pre or post VS2017)
     // If the envvar WindowsSdkVerBinPath exists, then the bin folder is versioned (VS2017+)
     // If not, then it's just the bin folder (VS2015)
     if (this.EnvironmentVariables.ContainsKey("WindowsSdkVerBinPath"))
     {
         var tokenised_strings = new Bam.Core.TokenizedStringArray();
         tokenised_strings.AddRangeUnique(this.EnvironmentVariables["WindowsSdkVerBinPath"]);
         this.Macros.Add(
             "CompilerPath",
             Bam.Core.TokenizedString.Create(
                 System.String.Format("$(0)/{0}/rc.exe", architecture),
                 null,
                 tokenised_strings
                 )
             );
     }
     else if (this.EnvironmentVariables.ContainsKey("WindowsSdkDir"))
     {
         var tokenised_strings = new Bam.Core.TokenizedStringArray();
         tokenised_strings.AddRangeUnique(this.EnvironmentVariables["WindowsSdkDir"]);
         this.Macros.Add(
             "CompilerPath",
             Bam.Core.TokenizedString.Create(
                 System.String.Format("$(0)/bin/{0}/rc.exe", architecture),
                 null,
                 tokenised_strings
                 )
             );
     }
     else
     {
         throw new Bam.Core.Exception("Unable to determine resource compiler path, as neither %WindowsSdkVerBinPath% nor %WindowsSdkDir% were defined");
     }
     this.Macros.AddVerbatim("objext", ".res");
 }
 Complement(
     TokenizedStringArray other)
 {
     return(new TokenizedStringArray(base.Complement(other)));
 }
 Intersect(
     TokenizedStringArray other)
 {
     return(new TokenizedStringArray(base.Intersect(other)));
 }
예제 #8
0
        CreateInternal(
            string tokenizedString,
            Module macroSource,
            bool verbatim,
            TokenizedStringArray positionalTokens,
            EFlags flags)
        {
            if (null == tokenizedString)
            {
                return(null);
            }

            // strings can be created during the multithreaded phase, so synchronize on the cache used
            if (verbatim)
            {
                // covers all verbatim strings
                lock (VerbatimCache)
                {
                    if (0 == (flags & EFlags.NoCache))
                    {
                        var foundTS = VerbatimCache.FirstOrDefault((ts) =>
                        {
                            if (ts.OriginalString == tokenizedString)
                            {
                                return(true);
                            }
                            return(false);
                        });
                        if (null != foundTS)
                        {
                            ++foundTS.RefCount;
                            return(foundTS);
                        }
                    }
                    var newTS = new TokenizedString(tokenizedString, macroSource, verbatim, positionalTokens, flags);
                    VerbatimCache.Add(newTS);
                    AllStrings.Add(newTS);
                    return(newTS);
                }
            }
            else
            {
                // covers all strings associated with a module (for macros), or no module but with positional arguments
                var stringCache = (null != macroSource) ? macroSource.TokenizedStringCache : NoModuleCache;
                lock (stringCache)
                {
                    if (0 == (flags & EFlags.NoCache))
                    {
                        var foundTS = stringCache.FirstOrDefault((ts) =>
                        {
                            if (ts.OriginalString == tokenizedString)
                            {
                                // and then check the positional tokens, if they exist
                                var samePosTokenCount = ((null != positionalTokens) && (positionalTokens.Count() == ts.PositionalTokens.Count())) ||
                                                        ((null == positionalTokens) && (0 == ts.PositionalTokens.Count()));
                                if (!samePosTokenCount)
                                {
                                    return(false);
                                }
                                for (int i = 0; i < ts.PositionalTokens.Count(); ++i)
                                {
                                    // because positional tokens are TokenizedStrings, they will refer to the same object
                                    if (ts.PositionalTokens[i] != positionalTokens[i])
                                    {
                                        return(false);
                                    }
                                }
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        });
                        if (null != foundTS)
                        {
                            ++foundTS.RefCount;
                            return(foundTS);
                        }
                    }
                    var newTS = new TokenizedString(tokenizedString, macroSource, verbatim, positionalTokens, flags);
                    stringCache.Add(newTS);
                    AllStrings.Add(newTS);
                    return(newTS);
                }
            }
        }