コード例 #1
0
 private LanguageValueAccess translate_StartAt_DirectSymbol(LanguageSymbol startSymbol)
 {
     return
         (_qualList.ActiveLength == 0
         ? LanguageValueAccess.Create(startSymbol)
         : CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Components not recognized", RootParseNode));
 }
コード例 #2
0
 private string RelativeSymbolAccessName(LanguageSymbol symbol)
 {
     return
         (HasRootSymbol
         ? symbol.SymbolAccessName.Substring(RootSymbolAccessName.Length + 1)
         : symbol.SymbolAccessName);
 }
コード例 #3
0
        public LanguageSymbol ParseClassObjectDeclaration(string line, string originalLine, bool isClass)
        {
            var nameMatch = isClass
                                ? Regex.Match(line, Language.CLASS_NAME_PATTERN, RegexOptions.IgnoreCase)
                                : Regex.Match(line, Language.OBJECT_NAME_PATTERN, RegexOptions.IgnoreCase);

            if (nameMatch.Groups.Count > 1)
            {
                var symbol = new LanguageSymbol();
                symbol.Name = nameMatch.Groups[1].Value;

                if (string.IsNullOrWhiteSpace(symbol.Name))
                {
                    return(null);
                }

                symbol.Type        = isClass ? SymbolKind.Class : SymbolKind.Object;
                symbol.StartColumn = originalLine.IndexOf(symbol.Name);
                symbol.EndColumn   = symbol.StartColumn + symbol.Name.Length;
                symbol.IsContainer = true;
                return(symbol);
            }

            return(null);
        }
コード例 #4
0
        public virtual void Visit(LanguageSymbol langSymbol)
        {
            if (SimpleLoggingEnabled)
            {
                Log.Append(langSymbol.SymbolAccessName);

                return;
            }

            Log.Append("{");

            Log.Append(" <Symbol: " + langSymbol.SymbolAccessName + "> ");

            if (EnableLogObjectClass)
            {
                Log.Append(" <Class: " + langSymbol.GetType().Name + "> ");
            }

            if (EnableLogSymbolRole)
            {
                Log.Append(" <Role: " + langSymbol.SymbolRoleName + "> ");
            }

            Log.Append("} ");
        }
コード例 #5
0
ファイル: LanguageScope.cs プロジェクト: phreed/GMac
        public bool LookupSymbol(string symbolName, IEnumerable <string> roleNames, out LanguageSymbol symbol)
        {
            if (_symbols.TryGetValue(symbolName, out symbol) && roleNames.Contains(symbol.SymbolRoleName))
            {
                return(true);
            }

            symbol = null;
            return(false);
        }
コード例 #6
0
ファイル: LanguageScope.cs プロジェクト: phreed/GMac
        public bool LookupSymbol(string symbolName, string roleName, out LanguageSymbol symbol)
        {
            if (_symbols.TryGetValue(symbolName, out symbol) && (symbol.SymbolRoleName == roleName))
            {
                return(true);
            }

            symbol = null;
            return(false);
        }
コード例 #7
0
        /// <summary>
        /// True if any access-by-symbol step (including the root step) depends on the given symbol
        /// </summary>
        /// <param name="symbol"></param>
        /// <returns></returns>
        public bool HasAccessStepWithSymbol(LanguageSymbol symbol)
        {
            if (RootSymbol.ObjectId == symbol.ObjectId)
            {
                return(true);
            }

            return
                (PartialAccessSymbols
                 .Any(accessStepSymbol => accessStepSymbol.ObjectId == symbol.ObjectId));
        }
コード例 #8
0
ファイル: LlGenerator.cs プロジェクト: cloudRoutine/GMac
        //These methods are inherited from LanguageExpressionEvaluator but never used for low-level code generation
        #region Not Implemented Methods

        protected override ILanguageValue ReadSymbolFullValue(LanguageSymbol symbol)
        {
            throw new NotImplementedException();
            //if (symbol is SymbolNamedValue)
            //    return ((SymbolNamedValue)symbol).AssociatedValue;

            ////if (symbol is SymbolLocalVariable || symbol is SymbolProcedureParameter)
            ////    return this.GetSymbolData((SymbolDataStore)symbol);

            //throw new InvalidOperationException("Invalid symbol type");
        }
コード例 #9
0
        private bool TryAddSymbol(string symbolName, LanguageSymbol langSymbol)
        {
            if (MainSymbols.ContainsKey(symbolName))
            {
                return(false);
            }

            MainSymbols.Add(symbolName, langSymbol);

            return(true);
        }
コード例 #10
0
        /// <summary>
        /// Get a symbol with a given name and having a role name from a given list of role names in any of the scopes of the given list of scopes. If the symbol is not found an error is raised
        /// </summary>
        /// <param name="scopeList">A list of scopes</param>
        /// <param name="symbolName">The name of the symbol</param>
        /// <param name="roleNames">A list of possible role names of the symbol</param>
        /// <returns>A reference to the symbol</returns>
        public static LanguageSymbol GetSymbol(this IEnumerable <LanguageScope> scopeList, string symbolName, IEnumerable <string> roleNames)
        {
            LanguageSymbol symbol = null;

            if (scopeList.Any(scope => scope.LookupSymbol(symbolName, roleNames, out symbol)))
            {
                return(symbol);
            }

            throw new KeyNotFoundException();
        }
コード例 #11
0
        private void AddToSymbolsCache(string symbolName, LanguageSymbol symbol)
        {
            if (_symbolsCache.ContainsKey(symbolName))
            {
                _symbolsCache[symbolName] = symbol;
            }

            else
            {
                _symbolsCache.Add(symbolName, symbol);
            }
        }
コード例 #12
0
        /// <summary>
        /// Returns a list of all partial access-by-symbol steps where the access symbol is identical to the given symbol
        /// </summary>
        /// <param name="symbol"></param>
        /// <returns></returns>
        public IEnumerable <ValueAccessStepByLValue> PartialAccessStepsByLValue(LanguageSymbol symbol)
        {
            for (var i = 1; i < _accessSteps.Count; i++)
            {
                var step = _accessSteps[i] as ValueAccessStepByLValue;

                if (step?.AccessLValue.ObjectId == symbol.ObjectId)
                {
                    yield return(step);
                }
            }
        }
コード例 #13
0
        private bool TryAddAsFrameSubspace(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacFrameSubspace;

            if (symbol == null)
            {
                return(false);
            }

            FrameSubspaces.Add(symbolName, symbol);

            return(true);
        }
コード例 #14
0
        private bool TryAddAsNamedValue(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as SymbolNamedValue;

            if (symbol == null)
            {
                return(false);
            }

            NamedValues.Add(symbolName, symbol);

            return(true);
        }
コード例 #15
0
        private bool TryAddAsTransform(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacMultivectorTransform;

            if (symbol == null)
            {
                return(false);
            }

            Transforms.Add(symbolName, symbol);

            return(true);
        }
コード例 #16
0
        private bool TryAddAsMacro(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacMacro;

            if (symbol == null)
            {
                return(false);
            }

            Macros.Add(symbolName, symbol);

            return(true);
        }
コード例 #17
0
        private void AddToSubDictionary(string symbolName, LanguageSymbol langSymbol)
        {
            if (TryAddAsNamespace(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsFrame(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsFrameBasisVector(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsFrameMultivector(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsFrameSubspace(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsConstant(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsNamedValue(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsStructure(symbolName, langSymbol))
            {
                return;
            }

            if (TryAddAsMacro(symbolName, langSymbol))
            {
                return;
            }

            TryAddAsTransform(symbolName, langSymbol);
        }
コード例 #18
0
        private bool TryAddAsStructure(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacStructure;

            if (symbol == null)
            {
                return(false);
            }

            Structures.Add(symbolName, symbol);

            Types.Add(symbolName, symbol);

            return(true);
        }
コード例 #19
0
        private bool TryAddAsConstant(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacConstant;

            if (symbol == null)
            {
                return(false);
            }

            Constants.Add(symbolName, symbol);

            NamedValues.Add(symbolName, symbol);

            return(true);
        }
コード例 #20
0
        private bool TryAddAsFrameMultivector(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacFrameMultivector;

            if (symbol == null)
            {
                return(false);
            }

            FrameMultivectors.Add(symbolName, symbol);

            Types.Add(symbolName, symbol);

            return(true);
        }
コード例 #21
0
        protected override ILanguageValue ReadSymbolFullValue(LanguageSymbol symbol)
        {
            var symbol1 = symbol as SymbolNamedValue;

            if (symbol1 != null)
            {
                return(symbol1.AssociatedValue);
            }

            if (symbol is SymbolLocalVariable || symbol is SymbolProcedureParameter)
            {
                return(GetSymbolData((SymbolDataStore)symbol));
            }

            throw new InvalidOperationException("Invalid symbol type");
        }
コード例 #22
0
        public LanguageSymbol ParseStructDeclaration(string line, string originalLine)
        {
            var nameMatch = Regex.Match(line, Language.STRUCT_NAME_PATTERN, RegexOptions.IgnoreCase);

            if (nameMatch.Groups.Count > 1)
            {
                var symbol = new LanguageSymbol();
                symbol.Name = nameMatch.Groups[1].Value;

                if (string.IsNullOrWhiteSpace(symbol.Name))
                {
                    return(null);
                }

                symbol.Type        = SymbolKind.Struct;
                symbol.StartColumn = originalLine.IndexOf(symbol.Name);
                symbol.EndColumn   = symbol.StartColumn + symbol.Name.Length;
                return(symbol);
            }

            return(null);
        }
コード例 #23
0
        public bool LookupSymbolInOpenedDistinctScopes(string symbolName, out LanguageSymbol symbol)
        {
            var skipList = new Dictionary <int, int>();

            for (var scope = ActiveParentScope; ReferenceEquals(scope, null) == false; scope = scope.ParentScope)
            {
                if (skipList.ContainsKey(scope.ObjectId) == false)
                {
                    skipList.Add(scope.ObjectId, scope.ObjectId);

                    if (scope.LookupSymbol(symbolName, out symbol))
                    {
                        return(true);
                    }
                }
            }

            foreach (var openedScope in _openedScopes)
            {
                for (var scope = openedScope; ReferenceEquals(scope, null) == false; scope = scope.ParentScope)
                {
                    if (skipList.ContainsKey(scope.ObjectId) == false)
                    {
                        skipList.Add(scope.ObjectId, scope.ObjectId);

                        if (scope.LookupSymbol(symbolName, out symbol))
                        {
                            return(true);
                        }
                    }
                }
            }

            symbol = null;
            return(false);
        }
コード例 #24
0
        public LanguageSymbol ParseProcedureDeclaration(string line, string originalLine, bool isProcedureSet)
        {
            var nameMatch = isProcedureSet
                                ? Regex.Match(line, Language.PROCEDURE_SET_NAME_PATTERN, RegexOptions.IgnoreCase)
                                : Regex.Match(line, Language.PROCEDURE_NAME_PATTERN, RegexOptions.IgnoreCase);

            if (nameMatch.Groups.Count > 1)
            {
                var symbol = new LanguageSymbol();
                symbol.Name = nameMatch.Groups[1].Value;

                if (string.IsNullOrWhiteSpace(symbol.Name))
                {
                    return(null);
                }

                symbol.Type        = SymbolKind.Method;
                symbol.StartColumn = originalLine.IndexOf(symbol.Name);
                symbol.EndColumn   = symbol.StartColumn + symbol.Name.Length;
                return(symbol);
            }

            return(null);
        }
コード例 #25
0
ファイル: LlGenerator.cs プロジェクト: cloudRoutine/GMac
 protected override bool AllowUpdateSymbolValue(LanguageSymbol symbol)
 {
     throw new NotImplementedException();
 }
コード例 #26
0
 protected override bool AllowUpdateSymbolValue(LanguageSymbol symbol)
 {
     return(symbol is SymbolLocalVariable || symbol is SymbolProcedureParameter);
 }
コード例 #27
0
        private LanguageValueAccess(LanguageSymbol rootSymbol)
        {
            var firstAccessStep = ValueAccessStepAsRootSymbol.Create(rootSymbol);

            _accessSteps.Add(firstAccessStep);
        }
コード例 #28
0
        /// <summary>
        /// Replace the root symbol in this value access by the given symbol
        /// for example replacing 'x' in 'x.y.z' by 'a' gives 'a.y.z'
        /// </summary>
        /// <param name="symbol"></param>
        /// <returns></returns>
        public LanguageValueAccess ReplaceRootSymbol(LanguageSymbol symbol)
        {
            ((ValueAccessStepAsRootSymbol)_accessSteps[0]).ReplaceComponentSymbol(symbol);

            return(this);
        }
コード例 #29
0
 public static LanguageValueAccess Create(LanguageSymbol rootSymbol, IEnumerable <ValueAccessStep> accessSteps)
 {
     return((new LanguageValueAccess(rootSymbol)).Append(accessSteps));
 }
コード例 #30
0
        //public void AcceptVisitor(IASTNodeAcyclicVisitor visitor)
        //{
        //    if (visitor is IASTNodeAcyclicVisitor<LanguageValueAccess>)
        //        ((IASTNodeAcyclicVisitor<LanguageValueAccess>)visitor).Visit(this);

        //    //You can write fall back logic here if needed.
        //}

        /// <summary>
        /// Create a new LanguageValueAccess object
        /// </summary>
        /// <param name="rootSymbol"></param>
        /// <returns></returns>
        public static LanguageValueAccess Create(LanguageSymbol rootSymbol)
        {
            return(new LanguageValueAccess(rootSymbol));
        }