public static CppInclusionContextResult CreateInclusionContextResult(
            CppGlobalSymbolCache cache,
            CppFileLocation rootFile,
            IEnumerable <CppFileLocation> includeLocations,
            FileProcessingOptions options,
            CppCompilationProperties compilationProperties,
            ISymbolScope symbolScope,
            long cacheVersion,
            Lifetime lifetime)
        {
            var languageDialect   = CppProjectConfigurationUtil.GetLanguageDialect(compilationProperties);
            var randomProjectFile = rootFile.GetRandomProjectFile(cache.Solution);
            var inclusionContext  = CppRootInclusionContext.Create(compilationProperties, randomProjectFile.GetProject(),
                                                                   randomProjectFile, cache, rootFile, options.File, languageDialect,
                                                                   cacheVersion, options.AllowPendingActions, options.CollectPPUsages, lifetime, symbolScope);
            var directory = randomProjectFile.Location.Directory;

            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("SHADER_API_D3D11"));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("__RESHARPER__"));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("INTERNAL_DATA= "));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("WorldReflectionVector(data,normal)=data.worldRefl"));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("WorldNormalVector(data,normal)=normal"));
            inclusionContext.PushInclude(rootFile, directory, false);
            foreach (CppFileLocation includeLocation in includeLocations)
            {
                if (includeLocation.IsValid() && !includeLocation.Equals(rootFile))
                {
                    cache.LookupAndProcessTableForFile(rootFile, includeLocation, options, inclusionContext, directory);
                }
            }
            inclusionContext.PopInclude(false);
            return(CppInclusionContextResult.Ok(inclusionContext));
        }
        public static CppInclusionContextResult CreateInclusionContextResult(
            CppGlobalSymbolCache cache,
            CppFileLocation rootFile,
            FileProcessingOptions options,
            CppCompilationProperties compilationProperties,
            ISymbolScope symbolScope,
            long cacheVersion,
            Lifetime lifetime)
        {
            var languageDialect   = CppProjectConfigurationUtil.GetLanguageDialect(compilationProperties);
            var randomProjectFile = rootFile.GetRandomProjectFile(cache.Solution);
            var inclusionContext  = CppRootInclusionContext.Create(compilationProperties, randomProjectFile.GetProject(),
                                                                   randomProjectFile, cache, rootFile, options.File, languageDialect,
                                                                   cacheVersion, options.AllowPendingActions, options.CollectPPUsages, lifetime, symbolScope);
            var directory = randomProjectFile.Location.Directory;

            var shaderCache = cache.Solution.GetComponent <InjectedHlslFileLocationTracker>();

            var(includes, defines) = shaderCache.GetProgramInfo(rootFile);

            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("SHADER_API_D3D11"));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("__RESHARPER__"));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("INTERNAL_DATA= "));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("WorldReflectionVector(data,normal)=data.worldRefl"));
            inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro("WorldNormalVector(data,normal)=normal"));

            foreach (var define in defines)
            {
                inclusionContext.ProcessDefine(CppPPDefineSymbol.ParsePredefinedMacro($"{define.Key}={define.Value}"));
            }

            // TODO 1) is cache ready? what will happen under document transaction? check for bad moment?
            // TODO 2) what will happen under psi transaction? include in cache could be out-of date. Try use include quickfix when cginclude is after cgprogram where QF is used


            inclusionContext.PushInclude(rootFile, directory, false);
            foreach (CppFileLocation includeLocation in includes)
            {
                if (includeLocation.IsValid() && !includeLocation.Equals(rootFile))
                {
                    cache.LookupAndProcessTableForFile(rootFile, includeLocation, options, inclusionContext, directory);
                }
            }
            inclusionContext.PopInclude(false);
            return(CppInclusionContextResult.Ok(inclusionContext));
        }
        public CppCompilationProperties GetCompilationProperties(IProject project, IProjectFile projectFile, CppFileLocation rootFile,
                                                                 CppGlobalSymbolCache globalCache)
        {
            if (project.IsUnityProject() && CppProjectFileType.ALL_HLSL_EXTENSIONS.Contains(rootFile.Location.ExtensionWithDot))
            {
                var properties = new CppCompilationProperties();
                properties.LanguageKind = CppLanguageKind.HLSL;
                var path = CgIncludeDirectoryTracker.GetCgIncludeFolderPath(myUnityVersion);
                if (!path.IsEmpty)
                {
                    properties.IncludePaths.Add(path);
                }

                properties.ForcedIncludes.Add(globalCache.Solution.SolutionDirectory.Combine(Utils.ShaderConfigFile).FullPath);

                properties.PredefinedMacros.Add(CppPPDefineSymbol.ParsePredefinedMacro("SHADER_API_D3D11"));
                properties.IncludePaths.Add(globalCache.Solution.SolutionDirectory);

                return(properties);
            }

            return(null);
        }
Пример #4
0
        public override void Init()
        {
            try
            {
                if (this.MacroCall.MacroReferenceNode != null)
                {
                    CppPPDefineSymbol symbol = this.MacroCall.MacroReferenceNode.GetReferencedSymbol();

                    if (symbol != null)
                    {
                        this.MacroName = symbol.Name;
                    }
                    else
                    {
                        this.MacroName = this.MacroCall.MacroReferenceNode.GetText();
                        //LogManager.Self.Log("PenWebMacroCall() Name is null");
                    }
                }
                else
                {
                    LogManager.Self.Log("PenWebMacroCall() MacroReferenceNode is null");
                }

                base.Init();

                if (!String.IsNullOrWhiteSpace(this.MacroName))
                {
                    this.PenWebMacroType = CppResourceManager.Self.GetMacroType(this.MacroName);
                }

                switch (this.PenWebMacroType)
                {
                case PenWebMacroType.ResourceId:
                    break;

                case PenWebMacroType.ScreenIdDef:
                    break;

                case PenWebMacroType.ListDef:
                    break;

                case PenWebMacroType.EnumDef:
                    break;

                case PenWebMacroType.Unknown:
                    break;

                case PenWebMacroType.MessageMapEntry:
                    this.WalkArguements();
                    break;
                }

                /*
                 * PenWebLiteralExpression penWebLiteralExpression = this.ParentNode.GetChildByType<PenWebLiteralExpression>();
                 *
                 * if (penWebLiteralExpression != null )
                 * {
                 *  PenWebEnumSpecifier penWebEnumeratorSpecifier = this.GetParentByType<PenWebEnumSpecifier>();
                 *
                 *  if (penWebEnumeratorSpecifier != null)
                 *  {
                 *      switch (penWebEnumeratorSpecifier.EnumName)
                 *      {
                 *          case "IDD":
                 *              this.PenWebMacroType = PenWebMacroType.ScreenIdDef;
                 *              this.ParentName = penWebEnumeratorSpecifier.EnumName;
                 *              break;
                 *
                 *          default:
                 *              this.PenWebMacroType = PenWebMacroType.EnumDef;
                 *              break;
                 *      }
                 *  }
                 *  else
                 *  {
                 *      PenWebMacroCall topMacroCall = GetTopParentByType<PenWebMacroCall>(null);
                 *
                 *      if (topMacroCall != null)
                 *      {
                 *          switch (topMacroCall.MacroName)
                 *          {
                 *              case "BEGIN_MESSAGE_MAP":
                 *                  this.PenWebMacroType = PenWebMacroType.MessageMapEntry;
                 *                  break;
                 *
                 *              default:
                 *                  this.PenWebMacroType = PenWebMacroType.ResourceId;
                 *                  break;
                 *          }
                 *      }
                 *      else
                 *      {
                 *          PenWebInitDeclarator penWebInitDeclarator = this.GetParentByType<PenWebInitDeclarator>();
                 *
                 *          if (penWebInitDeclarator != null)
                 *          {
                 *              this.PenWebMacroType = PenWebMacroType.ListDef;
                 *              this.ParentName = penWebInitDeclarator.TypeName;
                 *          }
                 *          else
                 *          {
                 *              this.PenWebMacroType = PenWebMacroType.Unknown;
                 *          }
                 *      }
                 *  }
                 * }
                 */

                switch (this.PenWebMacroType)
                {
                case PenWebMacroType.ListDef:
                    this.CppFunctionCatagory = CppFunctionCatagory.ListDef;
                    this.SaveToJson          = true;
                    break;

                case PenWebMacroType.ScreenIdDef:
                    this.CppFunctionCatagory = CppFunctionCatagory.ScreenDef;
                    this.SaveToJson          = true;
                    break;

                case PenWebMacroType.EnumDef:
                    this.CppFunctionCatagory = CppFunctionCatagory.EnumDef;
                    this.SaveToJson          = true;
                    break;

                case PenWebMacroType.MessageMapEntry:
                    this.CppFunctionCatagory = CppFunctionCatagory.MessageMap;
                    this.SaveToJson          = true;
                    break;

                case PenWebMacroType.ResourceId:
                    break;

                case PenWebMacroType.Unknown:
                    break;
                }
            }
            catch (Exception e)
            {
                LogManager.Self.Log("PenWebMacroCall Exception", e);
            }

            this.MacroCall = null;
        }