public ImportResult[] AddOrUpdateTranslationUnitsMasked(TranslationUnit[] translationUnits, int[] previousTranslationHashes, ImportSettings settings, bool[] mask)
        {
            var results =
                _fileBasedTranslationProviderLanguageDirection.AddOrUpdateTranslationUnitsMasked(translationUnits,
                    previousTranslationHashes, settings, mask);


            var tmDataAccess = TmDataAccess.OpenConnection(TranslationProvider.Uri);

            for (int i = 0; i < results.Length; i++)
            {
                var result = results[i];
                if (result == null) continue;
                var translationUnit = translationUnits[i];

                if (result.Action == Action.Add || result.Action == Action.Merge || result.Action == Action.Overwrite)
                {
                    var customFieldsValue = new CustomFieldValues
                    {
                        FileNameFullPath = translationUnit.GetFilePath(),
                        ProjectName = translationUnit.GetProjectName()
                    };
                    tmDataAccess.AddOrUpdateCustomFields(result.TuId.Id, customFieldsValue);
                }
            }

            return results;
        }
Ejemplo n.º 2
0
        internal unsafe Results(CodeCompletion.Library.CXCodeCompleteResults* handle, TranslationUnit tu)
        {
            Int64 ii = Library.clang_codeCompleteGetContexts(handle);

            _handleToDispose = handle;
            _handle = *handle;
            _results = new List<Result>();

            bool print = _handle.NumberResults <= 100;
            for(uint i = 0;i < _handle.NumberResults; i++)
            {
                //Library.CXCompletionResult r = _handle.Results[i];
                Result r = new Result(_handle.Results[i]);
                _results.Add(r);
                if(print)
                    System.Diagnostics.Debug.WriteLine(r);
            }
            if(!print)
                System.Diagnostics.Debug.WriteLine("too many results");

          /*  List<LibClang.Diagnostic> diags = new List<Diagnostic>();
            for(uint d = 0; d < Library.clang_codeCompleteGetNumDiagnostics(_handleToDispose); d++)
            {
                Diagnostic diag = new Diagnostic(Library.clang_codeCompleteGetDiagnostic(handle, d), tu.ItemFactory);
                
                System.Diagnostics.Debug.WriteLine(diag + " " + diag.Location);
            }*/
        }
Ejemplo n.º 3
0
 static unsafe internal Results CompleteAt(TranslationUnit tu, string fileName, int line, int col, LibClang.Library.UnsavedFile[] unsaved)
 {
     uint options = CodeCompletion.Library.clang_defaultCodeCompleteOptions();
     CodeCompletion.Library.CXCodeCompleteResults* results = CodeCompletion.Library.clang_codeCompleteAt(tu.Handle, fileName, (uint)line, (uint)col,
                                                                                     unsaved.Length > 0 ? unsaved : null,
                                                                                     (uint)unsaved.Length,
                                                                                     3);/*
                                                                                     CodeCompletion.Library.clang_defaultCodeCompleteOptions());*/
     Int64 p = Library.clang_codeCompleteGetContexts(results);
     if (results != null && results->NumberResults > 0)
     {
         Results rs = new Results(results, tu);
         return rs;
     }
     return null;
 }
Ejemplo n.º 4
0
        private Indexer(TranslationUnit tu)
        {
            unsafe
            {
                _cbs = new Library.IndexerCallbacks();
                _cbs.abortQuery = OnIndexerAbortQuery;
                _cbs.diagnostic = OnIndexerDiagnostic;
                _cbs.enterMainFile = OnIndexerEnteredMainFile;
                _cbs.ppIncludedFile = OnIndexerPPIncludedFile;
                _cbs.astImportFile = OnIndexerImportedASTFile;
                _cbs.startTU = OnIndexerStartTranslationUnit;
                _cbs.index = OnIndexerDeclaration;
                _cbs.entityRef = OnIndexerEntityReference;

                _includeCallback = OnCxxIncludeVisit;
            }
            _translationUnit = tu;
        }
        public ImportResult[] AddOrUpdateTranslationUnits(TranslationUnit[] translationUnits, int[] previousTranslationHashes, ImportSettings settings)
        {
            var results = _fileBasedTranslationProviderLanguageDirection.AddOrUpdateTranslationUnits(translationUnits,
                previousTranslationHashes, settings);
            var tmDataAccess = TmDataAccess.OpenConnection(TranslationProvider.Uri);

            for (int i = 0; i < results.Length; i++)
            {
                var result = results[i];
                if (result == null) continue;
                var translationUnit = translationUnits[i];

                if (result.Action == Action.Add || result.Action == Action.Merge || result.Action == Action.Overwrite)
                {
                    tmDataAccess.AddOrUpdateSourceFile(result.TuId.Id, translationUnit.DocumentProperties.LastOpenedAsPath);
                }
            }

            return results;
        }
        public ImportResult AddTranslationUnit(TranslationUnit translationUnit, ImportSettings settings)
        {
            var result =
                _fileBasedTranslationProviderLanguageDirection.AddTranslationUnit(translationUnit,
                    settings);
            if (result == null) return null;
            var tmDataAccess = TmDataAccess.OpenConnection(TranslationProvider.Uri);



            if (result.Action == Action.Add || result.Action == Action.Merge || result.Action == Action.Overwrite)
            {
                var customFieldsValue = new CustomFieldValues
                {
                    FileNameFullPath = translationUnit.GetFilePath(),
                    ProjectName = translationUnit.GetProjectName()
                };
                tmDataAccess.AddOrUpdateCustomFields(result.TuId.Id, customFieldsValue);
            }

            return result;
        }
 /// <summary>
 /// Not required for this implementation.
 /// </summary>
 /// <param name="translationUnit"></param>
 /// <returns></returns>
 public ImportResult UpdateTranslationUnit(TranslationUnit translationUnit)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public CLISourcesTemplate(Driver driver, TranslationUnit unit)
     : base(driver, unit)
 {
 }
 public SearchResults[] SearchTranslationUnits(SearchSettings settings, TranslationUnit[] translationUnits)
 {
     SearchResults[] results = new SearchResults[translationUnits.Length];
     for (int p = 0; p < translationUnits.Length; ++p)
     {
         //need to use the tu confirmation level in searchsegment method
         inputTu = translationUnits[p];
         results[p] = SearchSegment(settings, translationUnits[p].SourceSegment); //changed this to send whole tu
     }
     return results;
 }
Ejemplo n.º 10
0
 public static TranslationUnit __CreateInstance(TranslationUnit.Internal native)
 {
     return new TranslationUnit(native);
 }
        //#region Methods abstract

        ///// <summary>
        ///// Performs a segment search.
        ///// </summary>
        ///// <param name="settings">The settings that define the search parameters.</param>
        ///// <param name="segment">The segment to search for.</param>
        ///// <returns>
        ///// A <see cref="T:Sdl.LanguagePlatform.TranslationMemory.SearchResults"/> object containing the results or an empty object if no results were found.
        ///// </returns>
        //public abstract SearchResults SearchSegment(SearchSettings settings, Segment segment);

        ///// <summary>
        ///// Performs a text search.
        ///// </summary>
        ///// <param name="settings">The settings that define the search parameters.</param>
        ///// <param name="segment">The text to search for.</param>
        ///// <returns>
        ///// A <see cref="T:Sdl.LanguagePlatform.TranslationMemory.SearchResults"/> object containing the results or an empty object if no results were found.
        ///// </returns>
        //public abstract SearchResults SearchText(SearchSettings settings, string segment);

        ///// <summary>
        ///// Performs a translation unit search.
        ///// </summary>
        ///// <param name="settings">The settings that define the search parameters.</param>
        ///// <param name="translationUnit">The translation unit to search for.</param>
        ///// <returns>
        ///// A <see cref="T:Sdl.LanguagePlatform.TranslationMemory.SearchResults"/> object containing the results or an empty object if no results were found.
        ///// </returns>
        //public abstract SearchResults SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit);

        //#endregion // Methods abstract

        #region Virtual methods

        #region Methods

        /// <summary>
        /// Performs a segment search.
        /// </summary>
        /// <param name="settings">The settings that define the search parameters.</param>
        /// <param name="segment">The segment to search for.</param>
        /// <returns>
        /// A <see cref="T:Sdl.LanguagePlatform.TranslationMemory.SearchResults"/> object containing the results or an empty object if no results were found.
        /// </returns>
        public virtual SearchResults SearchSegment(SearchSettings settings, Segment segment)
        {
            lock (this.locker)
            {
                string segmentText = SegmentParser.ExtractSegmentText(segment);

                Trados.Interop.TMAccess.SearchResult tradosSegments = GetMatchSegments(settings, segmentText);

                if (tradosSegments == null)
                {
                    return(null);
                }

                var searchResults = new SearchResults
                {
                    SourceSegment = segment.Duplicate(),
                    SourceHash    = segment.GetHashCode(),
                };

                int id = 0;

                foreach (TmMatch match in tradosSegments.TmMatches)
                {
                    // form ScoringResult via applying penalties
                    var scoringResult = new ScoringResult
                    {
                        AppliedPenalties        = new List <AppliedPenalty>(),
                        BaseScore               = match.ScoreValues.GetMatchPercent(),
                        IsStructureContextMatch = false,
                    };
                    this.ApplyPenalties(match, scoringResult, settings);

                    // convert trados 2007 format segments into Studio 2011 ones
                    string translationSource = match.GetSource(settings.IsConcordanceSearch);
                    string translationTarget = match.GetTarget(settings.IsConcordanceSearch);

                    var sourceSegment = SegmentParser.CreateSegment(
                        scoringResult, settings, translationSource, this.SourceLanguage);
                    var targetSegment = SegmentParser.CreateSegment(
                        scoringResult, settings, translationTarget, this.TargetLanguage);

                    // tokenize segments
                    SegmentParser.TokenizeSegment(ref sourceSegment);
                    SegmentParser.TokenizeSegment(ref targetSegment);

                    // create Translation Unit
                    var unit = new TranslationUnit(sourceSegment, targetSegment)
                    {
                        Origin       = TranslationUnitOrigin.TM,
                        Format       = TranslationUnitFormat.TradosTranslatorsWorkbench,
                        SystemFields = new SystemFields(),
                        ResourceId   = new PersistentObjectToken(id++, Guid.NewGuid()),
                    };

                    // set custom attributes
                    this.SetMetaData(match, unit, settings);

                    // form SearchResult
                    var searchResult = new SearchResult(unit)
                    {
                        ScoringResult       = scoringResult,
                        TranslationProposal = unit.Duplicate()
                    };

                    scoringResult.EditDistance = ComputeEditDistance(segment, searchResult, settings);

                    // set "yellow" fileds for concordance
                    if (settings.Mode == SearchMode.ConcordanceSearch || settings.Mode == SearchMode.TargetConcordanceSearch)
                    {
                        this.AnnotateConcordanceHit(segment, searchResult, settings.Mode);
                    }

                    // finally...
                    searchResults.Add(searchResult);
                }


                searchResults.CheckForMultipleTranslations(settings);
                searchResults.RemoveDuplicates();

                //if "Search fo fuzzy matches even if exact match found" is OFF
                //and exact matches are present then also remove fuzzy matches
                //According to LanguagePlatform description for enum SearchMode, exact match should return only exact matches,
                //normal search should return exact matches OR fuzzy matches if no exact matches found
                if (settings.Mode == SearchMode.ExactSearch ||
                    (settings.Mode == SearchMode.NormalSearch && searchResults.Results.Any(i => i.ScoringResult.IsExactMatch)))
                {
                    searchResults.Results.RemoveAll(r => !r.ScoringResult.IsExactMatch);
                }

                //Determine placebles in the searched segment
                if (settings.Mode != SearchMode.TargetConcordanceSearch && !settings.IsConcordanceSearch)
                {
                    searchResults.DocumentPlaceables = PlaceableComputer.ComputePlaceables(searchResults.SourceSegment, null);
                }

                return(searchResults);
            }
        }
Ejemplo n.º 12
0
 internal TranslationUnit(TranslationUnit.Internal* native)
     : this(new global::System.IntPtr(native))
 {
 }
Ejemplo n.º 13
0
 private static void* __CopyValue(TranslationUnit.__Internal native)
 {
     var ret = Marshal.AllocHGlobal(292);
     global::CppSharp.Parser.AST.TranslationUnit.__Internal.cctor_1(ret, new global::System.IntPtr(&native));
     return ret.ToPointer();
 }
Ejemplo n.º 14
0
 public virtual bool VisitTranslationUnit(TranslationUnit unit)
 {
     return(VisitDeclContext(unit));
 }
Ejemplo n.º 15
0
 protected CodeGenerator(BindingContext context, TranslationUnit unit)
     : this(context, new List <TranslationUnit> {
     unit
 })
 {
 }
Ejemplo n.º 16
0
 public override TypePrinterResult VisitTranslationUnit(TranslationUnit unit)
 {
     return(VisitDeclaration(unit));
 }
Ejemplo n.º 17
0
 public static Namespace Namespace(this TranslationUnit unit, string name)
 {
     return(unit.FindNamespace(name));
 }
Ejemplo n.º 18
0
 public override void Process()
 {
     TranslationUnit.Visit(this);
 }
Ejemplo n.º 19
0
 public override bool VisitTranslationUnit(TranslationUnit unit)
 {
     translationUnit = unit;
     return(base.VisitTranslationUnit(unit));
 }
Ejemplo n.º 20
0
 public override bool Visit(TranslationUnit node)
 {
     Visit((Declaration)node);
     return(true);
 }
        private SearchResult CreateSearchResult(Segment searchSegment, Segment translation,
            string sourceSegment)
        {
            #region "TranslationUnit"
            TranslationUnit tu = new TranslationUnit();
            tu.SourceSegment = searchSegment.Duplicate();//this makes the original source segment, with tags, appear in the search window
            tu.TargetSegment = translation;
            #endregion

            tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty);

            int score = 0; //score to 0...change if needed to support scoring
            tu.Origin = TranslationUnitOrigin.MachineTranslation;
            SearchResult searchResult = new SearchResult(tu);
            searchResult.ScoringResult = new ScoringResult();
            searchResult.ScoringResult.BaseScore = score;
            tu.ConfirmationLevel = ConfirmationLevel.Draft;

            return searchResult;
        }
Ejemplo n.º 22
0
 public void StoreTranslation(TranslationUnit transunit)
 {
 }
Ejemplo n.º 23
0
 internal TranslationUnit(TranslationUnit.Internal native)
     : this(__CopyValue(native))
 {
 }
Ejemplo n.º 24
0
 public ObjCSources(BindingContext context, Options options,
                    TranslationUnit unit)
     : base(context, options, unit)
 {
 }
 public ImportResult AddTranslationUnit(TranslationUnit translationUnit, ImportSettings settings)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 26
0
 public ClangParser(CompilerContext ctx, CXIndex index, TranslationUnit tu) : base(ctx)
 {
     Index = index;
     TU    = tu;
 }
Ejemplo n.º 27
0
 private TranslationUnit(TranslationUnit.Internal native, bool skipVTables = false)
     : this(__CopyValue(native), skipVTables)
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Ejemplo n.º 28
0
 public virtual bool VisitTranslationUnit(TranslationUnit unit)
 {
     return(VisitNamespace(unit));
 }
Ejemplo n.º 29
0
 private TranslationUnit(TranslationUnit.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
 /// <summary>
 /// Not required for this implementation.
 /// </summary>
 /// <param name="translationUnits"></param>
 /// <param name="settings"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 public ImportResult[] AddTranslationUnitsMasked(TranslationUnit[] translationUnits, ImportSettings settings, bool[] mask)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Not required for this implementation.
 /// </summary>
 /// <param name="translationUnits"></param>
 /// <param name="previousTranslationHashes"></param>
 /// <param name="settings"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 public ImportResult[] AddOrUpdateTranslationUnitsMasked(TranslationUnit[] translationUnits, int[] previousTranslationHashes, ImportSettings settings, bool[] mask)
 {
     ImportResult[] result = { AddTranslationUnit(translationUnits[translationUnits.GetLength(0) - 1], settings) };
     return result;
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Build the Clang AST
        /// </summary>
        private TranslationUnit BuildClangAST(Configuration config, CXIndex index)
        {
            CXTranslationUnit tu = null;

            using (var section = CreateSection("Building Clang AST"))
            {
                // Assemble the arguments
                var clangArgs = new List <string>()
                {
                    "-Wno-pragma-once-outside-header"
                };

                switch (config.Clang.Language)
                {
                case LanguageEnum.C99:
                    clangArgs.Add("-xc");
                    clangArgs.Add("-std=c99");
                    break;

                case LanguageEnum.Cpp11:
                    clangArgs.Add("-xc++");
                    clangArgs.Add("-std=c++11");
                    break;

                case LanguageEnum.Cpp14:
                    clangArgs.Add("-xc++");
                    clangArgs.Add("-std=c++14");
                    break;

                case LanguageEnum.Cpp17:
                    clangArgs.Add("-xc++");
                    clangArgs.Add("-std=c++17");
                    break;

                default:
                    throw new Exception($"unknown language {config.Clang.Language}");
                }

                clangArgs.AddRange(GetWinSDKDIncludeArgs(config));
                clangArgs.AddRange(GetCxxSTLIncludeArgs(config));

                clangArgs.AddRange(config.Clang.Includes.Select(i => MakeIncludeArg(i)));
                clangArgs.AddRange(config.Clang.Defines.Select((m, v) => $"-D{m}=\"{v}\""));
                clangArgs.AddRange(config.Clang.Arguments.Split(" "));

                var tuFlags = CXTranslationUnit_Flags.CXTranslationUnit_SkipFunctionBodies;

                // Create the TU source file
                var sourceFiles = new HashSet <string>();
                config.Hook.Descriptions.Values.ToList().ForEach(hook => hook.Input.ForEach(source => sourceFiles.Add(source)));

                var tuFilename = Path.GetFileNameWithoutExtension(string.IsNullOrEmpty(config.Plugin.Name) ? Path.GetTempFileName() : config.Plugin.Name) + ".cpp";
                Logger.Debug($"Clang TU filename: {tuFilename}");

                var tuSource = "#include <" + string.Join(">\n#include <", sourceFiles) + ">";

                Logger.Debug($"Clang TU source:\n  {tuSource.Replace("\n", "\n  ")}");
                using (var tuSourceFile = CXUnsavedFile.Create(tuFilename, tuSource))
                {
                    // Invoke clang to get the TU
                    Logger.Debug($"Clang args: {string.Join(" ", clangArgs)}");
                    var tuError = CXTranslationUnit.TryParse(index, tuSourceFile.FilenameString, clangArgs.ToArray(), new CXUnsavedFile[] { tuSourceFile }, tuFlags, out tu);
                    if (tuError != CXErrorCode.CXError_Success)
                    {
                        throw new Exception($"clang error: failed to generate tanslation unit: {tuError}");
                    }
                }
                section.Done();
            }
            if (tu == null)
            {
                return(null);
            }
            return(TranslationUnit.GetOrCreate(tu));
        }
Ejemplo n.º 33
0
 public CppSources(BindingContext context, TranslationUnit unit)
     : base(context, unit)
 {
 }
Ejemplo n.º 34
0
 public SearchResults SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit)
 {
     return(SearchSegment(settings, translationUnit.SourceSegment));
 }
Ejemplo n.º 35
0
 internal Token(Interop.Token native, TranslationUnit parent) {
     Kind = Interop.clang_getTokenKind(native);
     Location = new SourceLocation(Interop.clang_getTokenLocation(parent.Native, native));
     Extent = new SourceRange(Interop.clang_getTokenExtent(parent.Native, native));
     Spelling = Interop.clang_getTokenSpelling(parent.Native, native).ManagedString; //parent.GetText(Extent);
 }
Ejemplo n.º 36
0
 public Parser(TranslationUnit tu, IAsyncStream <Token> input)
 {
     TranslationUnit = tu;
     InputStream     = input;
 }
 /// <summary>
 /// Not required for this implementation.
 /// </summary>
 /// <param name="translationUnits"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public ImportResult[] AddTranslationUnits(TranslationUnit[] translationUnits, ImportSettings settings)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 38
0
        /// <summary>
        ///     The execute method.
        /// </summary>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public override bool Execute()
        {
            string SntFileName = Path.GetTempPath() + "_TmxUpload.snt";
            string uservalue   = user.ValueString;

            if (uservalue == string.Empty)
            {
                uservalue = "TmxUpload";
            }
            string ratingvalue = rating.ValueString;

            if (ratingvalue == string.Empty)
            {
                ratingvalue = "6";
            }

            TmxFile TmxIn = new TmxFile(this.TmxDocument.ValueString);

            string[] sntFilenames = TmxIn.WriteToSNTFiles(SntFileName);
            if (sntFilenames.Length != 2)
            {
                Logger.WriteLine(LogLevel.Error, "More than 2 languages in the TMX file. Must have exactly 2.");
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            TranslationMemory TM = new TranslationMemory();

            TM.sourceLangID = this.sourceLanguage.ValueString.ToLowerInvariant();
            TM.targetLangID = this.targetLanguage.ValueString.ToLowerInvariant();

            // Read langauge names from Tmx
            string TmxSourceLanguage = Path.GetFileNameWithoutExtension(sntFilenames[0]);

            TmxSourceLanguage = TmxSourceLanguage.Substring(TmxSourceLanguage.LastIndexOf('_') + 1).ToLowerInvariant();
            string TmxTargetLanguage = Path.GetFileNameWithoutExtension(sntFilenames[1]);

            TmxTargetLanguage = TmxTargetLanguage.Substring(TmxTargetLanguage.LastIndexOf('_') + 1).ToLowerInvariant();

            if (TmxSourceLanguage.Substring(0, 2) != TM.sourceLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Source language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.sourceLangID, TmxSourceLanguage);
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            if (TmxTargetLanguage.Substring(0, 2) != TM.targetLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Target language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.targetLangID, TmxTargetLanguage);
                deleteSNTfiles(sntFilenames);
                return(false);
            }


            string[] sntSource = File.ReadAllLines(sntFilenames[0]);
            string[] sntTarget = File.ReadAllLines(sntFilenames[1]);
            if (sntSource.Length != sntTarget.Length)
            {
                Logger.WriteLine(LogLevel.Error, "Unequal number of segments. The TMX must have the same number of segments in the two given languages.");
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            Logger.WriteLine(LogLevel.None, "{0} translation units read.", sntSource.Length);

            TmxWriter ErrorTmx = new TmxWriter(Path.GetFileNameWithoutExtension(this.TmxDocument.ValueString) + ".errors." + TmxSourceLanguage + "_" + TmxTargetLanguage + "." + DateTime.Now.ToString("yyyyMMddThhmmssZ") + ".tmx", TmxSourceLanguage, TmxTargetLanguage);

            //Load into TM and perform error check on each line.
            int ratioViolationCount    = 0; //counts number of ratio violations
            int sntCountViolationCount = 0; //counts number of unequal sentence count violation.

            for (int sntLineIndex = 0; sntLineIndex < sntSource.Length; sntLineIndex++)
            {
                //show a progress message.
                if ((sntLineIndex % 10) == 0)
                {
                    Logger.WriteLine(LogLevel.Debug, "{0} of {1} sentences aligned and error checked.", sntLineIndex, sntSource.Length);
                }

                //Length discrepancy check
                float ratio = Math.Abs(sntSource[sntLineIndex].Length / sntTarget[sntLineIndex].Length);
                if ((ratio > 3) && ((sntSource.Length > 15) || (sntTarget.Length > 15))) //skip the segment, and add to error.tmx
                {
                    Logger.WriteLine(LogLevel.Debug, "Length ratio exceeded. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length)?60:sntSource[sntLineIndex].Length));
                    ratioViolationCount++;
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.lengthratio);

                    if ((ratioViolationCount / sntSource.Length) > 0.10)
                    {
                        Logger.WriteLine(LogLevel.Error, "Length ratio exceeded for 10% of segments. Probably not a translation. Aborting.");
                        deleteSNTfiles(sntFilenames);
                        return(false);
                    }
                    continue;
                }

                //TODO: special handling of bpt/ept
                sntSource[sntLineIndex] = System.Net.WebUtility.HtmlDecode(sntSource[sntLineIndex]);
                sntTarget[sntLineIndex] = System.Net.WebUtility.HtmlDecode(sntTarget[sntLineIndex]);

                //throw away segments with tags
                if ((sntSource[sntLineIndex].Contains("<") && sntSource[sntLineIndex].Contains(">")) && (sntTarget[sntLineIndex].Contains("<") && sntTarget[sntLineIndex].Contains(">")))
                {
                    Logger.WriteLine(LogLevel.Debug, "Tagged segment. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length) ? 60 : sntSource[sntLineIndex].Length));
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.tagging);
                    continue;
                }

                //Encode the remaining <>&
                sntSource[sntLineIndex] = System.Net.WebUtility.HtmlEncode(sntSource[sntLineIndex]);
                sntTarget[sntLineIndex] = System.Net.WebUtility.HtmlEncode(sntTarget[sntLineIndex]);



                int[] sourceSentLengths = TranslationServiceFacade.BreakSentences(sntSource[sntLineIndex], TM.sourceLangID);
                int[] targetSentLengths = TranslationServiceFacade.BreakSentences(sntTarget[sntLineIndex], TM.targetLangID);

                //unequal sentence count violation check
                if (sourceSentLengths.Length != targetSentLengths.Length)
                {
                    sntCountViolationCount++;
                    Logger.WriteLine(LogLevel.Debug, "Unequal number of sentences in segment. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length)?60:sntSource[sntLineIndex].Length));
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.sentencecountmismatch);

                    if ((sntCountViolationCount / sntSource.Length) > 0.10)
                    {
                        Logger.WriteLine(LogLevel.Error, "Unequal sentence count exceeded for 10% of segments. Probably not a translation. Aborting.");
                        deleteSNTfiles(sntFilenames);
                        return(false);
                    }
                    continue;
                }


                //Split multiple sentences
                int startIndexSrc = 0;
                int startIndexTgt = 0;
                for (int j = 0; j < sourceSentLengths.Length; j++)
                {
                    TranslationUnit TU = new TranslationUnit();
                    TU.strSource  = sntSource[sntLineIndex].Substring(startIndexSrc, sourceSentLengths[j]);
                    TU.strTarget  = sntTarget[sntLineIndex].Substring(startIndexTgt, targetSentLengths[j]);
                    startIndexSrc = sourceSentLengths[j];
                    startIndexTgt = targetSentLengths[j];
                    TU.rating     = int.Parse(ratingvalue);
                    TU.user       = uservalue.ToUpperInvariant();
                    TM.Add(TU);
                }
            }
            ErrorTmx.Dispose();


            //Add the whole TM list to CTF, if a CTF write was requested.

            if (boolWrite.ValueString.ToLowerInvariant() == "true")
            {
                int SentenceCount = 0;
                foreach (TranslationUnit TU in TM)
                {
                    TranslationServiceFacade.AddTranslation(TU.strSource, TU.strTarget, TM.sourceLangID, TM.targetLangID, TU.rating, TU.user);
                    if ((SentenceCount % 10) == 0)
                    {
                        Logger.WriteLine(LogLevel.Debug, "{0} of {1} sentences written. Continuing...", SentenceCount, sntSource.Length);
                    }
                    //Do not change the sleep time. This is slow and needs to be slow - the AddTranslation method is designed for interactive use.
                    Thread.Sleep(500);
                    SentenceCount++;
                }
                Logger.WriteLine(LogLevel.Msg, "{0} sentences written to CTF. Write complete. ", SentenceCount);
            }
            else
            {
                //Just list the entire TM on screen.
                foreach (TranslationUnit TU in TM)
                {
                    Logger.WriteLine(LogLevel.None, "{0} || {1}", TU.strSource, TU.strTarget);
                }
            }


            return(true);
        }
 public SearchResults SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit)
 {
     //need to use the tu confirmation level in searchsegment method
     inputTu = translationUnit;
     return SearchSegment(settings, translationUnit.SourceSegment);
 }
Ejemplo n.º 40
0
 public CHeaders(BindingContext context, TranslationUnit unit)
     : base(context, unit)
 {
 }
        public SearchResults[] SearchTranslationUnitsMasked(SearchSettings settings, TranslationUnit[] translationUnits, bool[] mask)
        {
            List<SearchResults> results = new List<SearchResults>();

            List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>();

            int i = 0;
            foreach (var tu in translationUnits)
            {
                if (mask == null || mask[i])
                {
                    var result = SearchTranslationUnit(settings, tu);
                    results.Add(result);
                }
                else
                {
                    results.Add(null);
                }
                i++;
            }

            if (errors.Count > 0)
            {
                string messages = "";
                foreach (KeyValuePair<string, string> pair in errors)
                    messages += pair.Key + ":  " + pair.Value + "\n";
                MessageBox.Show(messages);
            }

            return results.ToArray();
        }
Ejemplo n.º 42
0
 public virtual TypePrinterResult VisitTranslationUnit(TranslationUnit unit)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Not required for this implementation.
 /// </summary>
 /// <param name="translationUnits"></param>
 /// <returns></returns>
 public ImportResult[] UpdateTranslationUnits(TranslationUnit[] translationUnits)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 44
0
 public CLIHeadersTemplate(Driver driver, TranslationUnit unit)
     : base(driver, unit)
 {
 }
 /// <summary>
 /// Not required for this implementation.
 /// </summary>
 /// <param name="translationUnits"></param>
 /// <param name="previousTranslationHashes"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public ImportResult[] AddOrUpdateTranslationUnits(TranslationUnit[] translationUnits, int[] previousTranslationHashes, ImportSettings settings)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 46
0
 public SearchResults SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit)
 {
     return(_fileBasedTranslationProviderLanguageDirection.SearchTranslationUnit(settings, translationUnit));
 }
Ejemplo n.º 47
0
 private TranslationUnit(TranslationUnit.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
 }
Ejemplo n.º 48
0
 public static string AssemblyId(TranslationUnit unit)
 {
     return(GenId(unit.FileName).Replace('.', '_'));
 }
Ejemplo n.º 49
0
 internal TranslationUnit(TranslationUnit.Internal native)
     : this(&native)
 {
 }
Ejemplo n.º 50
0
 public CCodeGenerator(BindingContext context,
                       TranslationUnit unit) : base(context, unit)
 {
     Unit = unit;
 }
Ejemplo n.º 51
0
 public Indexer(Index idx, TranslationUnit tu)
     : this()
 {
     Index = idx;
     _translationUnit = tu;
 }
Ejemplo n.º 52
0
        public static Enumeration GenerateEnumFromMacros(this ASTContext context, string name,
                                                         params string[] macros)
        {
            var @enum = new Enumeration {
                Name = name
            };

            var regexPattern = string.Join("|", macros.Select(pattern => $"({pattern}$)"));
            var regex        = new Regex(regexPattern);

            int             maxItems     = 0;
            TranslationUnit unitToAttach = null;
            ulong           maxValue     = 0;

            foreach (var unit in context.TranslationUnits)
            {
                int numItems = 0;

                foreach (var macro in unit.PreprocessedEntities.OfType <MacroDefinition>())
                {
                    var match = regex.Match(macro.Name);
                    if (!match.Success)
                    {
                        continue;
                    }

                    if (macro.Enumeration != null)
                    {
                        continue;
                    }

                    // Skip this macro if the enum already has an item with same name.
                    if (@enum.Items.Exists(it => it.Name == macro.Name))
                    {
                        continue;
                    }

                    var item = @enum.GenerateEnumItemFromMacro(macro);
                    @enum.AddItem(item);
                    macro.Enumeration = @enum;

                    maxValue = Math.Max(maxValue, item.Value);
                    numItems++;
                }

                if (numItems > maxItems)
                {
                    maxItems     = numItems;
                    unitToAttach = unit;
                }
            }

            if (@enum.Items.Count > 0)
            {
                @enum.BuiltinType = new BuiltinType(GetUnderlyingTypeForEnumValue(maxValue));
                @enum.Type        = @enum.BuiltinType;
                @enum.Namespace   = unitToAttach;

                unitToAttach.Declarations.Add(@enum);
            }

            return(@enum);
        }
Ejemplo n.º 53
0
 public static TranslationUnit __CreateInstance(TranslationUnit.Internal native, bool skipVTables = false)
 {
     return new TranslationUnit(native, skipVTables);
 }
Ejemplo n.º 54
0
        public override void Process()
        {
            GenerateFilePreamble(CommentKind.BCPL);

            PushBlock(BlockKind.Includes);
            {
                WriteInclude("CppSharp_QuickJS.h", CInclude.IncludeKind.Angled);
                WriteInclude("assert.h", CInclude.IncludeKind.Angled);

                foreach (var unit in TranslationUnits)
                {
                    WriteInclude(unit.IncludePath, CInclude.IncludeKind.Angled);
                }

                NewLine();
            }
            PopBlock();

            WriteLine("extern \"C\" {");
            NewLine();

            GenerateExternClassIds();

            var registerGen = new QuickJSRegister(Context, TranslationUnits);

            registerGen.Process();
            WriteLine(registerGen.Generate());

            PushBlock();
            {
                var name = GetTranslationUnitName(TranslationUnit);
                WriteLine($"void register_{name}(JSContext *ctx, JSModuleDef *m, bool set, int phase)");
                WriteOpenBraceAndIndent();

                Block registerBlock;
                PushBlock();
                {
                    WriteLine("if (phase == 0)");

                    WriteOpenBraceAndIndent();
                    {
                        PushBlock();
                        VisitOptions.ClearFlags(VisitFlags.NamespaceClasses);
                        TranslationUnit.Visit(this);
                        registerBlock = PopBlock();
                    }
                    UnindentAndWriteCloseBrace();
                }
                var phase0Block = PopBlock(NewLineKind.IfNotEmpty);
                phase0Block.CheckGenerate = () => !registerBlock.IsEmpty;

                PushBlock();
                {
                    VisitOptions.ResetFlags(VisitFlags.Default);
                    VisitOptions.SetFlags(VisitFlags.NamespaceClasses);
                    TranslationUnit.Visit(this);
                }
                PopBlock(NewLineKind.IfNotEmpty);

                UnindentAndWriteCloseBrace();
            }
            PopBlock(NewLineKind.BeforeNextBlock);
            NewLine();

            WriteLine("} // extern \"C\"");
        }
Ejemplo n.º 55
0
 protected TranslationUnit(TranslationUnit.Internal* native, bool skipVTables = false)
     : base((CppSharp.Parser.AST.Namespace.Internal*) null)
 {
     __PointerAdjustment = 0;
     if (native == null)
         return;
     __Instance = new global::System.IntPtr(native);
 }
Ejemplo n.º 56
0
 public bool VisitTranslationUnit(TranslationUnit unit)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 57
0
 private static TranslationUnit.Internal* __CopyValue(TranslationUnit.Internal native)
 {
     var ret = Marshal.AllocHGlobal(448);
     CppSharp.Parser.AST.TranslationUnit.Internal.cctor_2(ret, new global::System.IntPtr(&native));
     return (TranslationUnit.Internal*) ret;
 }
 public SearchResults SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit)
 {
     //need to use the tu confirmation level in searchsegment method
     return(SearchSegment(settings, translationUnit.SourceSegment));
 }
Ejemplo n.º 59
0
 protected TranslationUnit(TranslationUnit.Internal* native, bool isInternalImpl = false)
     : base((CppSharp.Parser.AST.Namespace.Internal*) native)
 {
 }
 public ImportResult UpdateTranslationUnit(TranslationUnit translationUnit)
 {
     throw new NotImplementedException();
 }