private void SetContext(TrimmedList <string> qualList, GMacSymbolTranslatorContext context, bool isLvalue, bool followScopeChain)
        {
            SetContext(context);

            _isLValue         = isLvalue;
            _followScopeChain = followScopeChain;
            _qualList         = new TrimmedList <string>(qualList);

            _generatedValueAccess = null;
        }
Exemple #2
0
        /// <summary>
        /// Read an identifier qualified list from the given parse tree node
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static TrimmedList <string> Translate_Qualified_Identifier(ParseTreeNode node)
        {
            node.Assert(GMacParseNodeNames.QualifiedIdentifier);

            var identList = new TrimmedList <string>(
                node.ChildNodes.Select(Translate_Identifier)
                );

            identList.ResetActiveRange();

            return(identList);
        }
        public static LanguageSymbol Translate_Direct(GMacSymbolTranslatorContext context, ParseTreeNode node, TrimmedList <string> qualList)
        {
            var valAccess = Translate(context, node, false, qualList);

            return
                (valAccess.IsFullAccess
                ? valAccess.RootSymbol
                : context.CompilationLog.RaiseGeneratorError <LanguageSymbol>("Expecting a direct r-value", node));
        }
        //public static bool TryTranslate_LValue(GMacSymbolTranslatorContext context, ParseTreeNode node, out LanguageValueAccess varAccess)
        //{
        //    var qualList = GenUtils.Translate_Qualified_Identifier(node);

        //    LanguageSymbol symbol;

        //    var flag =
        //        context
        //        .OpenedDistinctScopes()
        //        .LookupSymbol(qualList.FirstItem, out symbol);

        //    if (flag == false || (symbol is SymbolLValue) == false)
        //    {
        //        varAccess = null;
        //        return false;
        //    }

        //    varAccess = LanguageValueAccess.Create(symbol);

        //    return true;
        //}

        public static LanguageValueAccess Translate(GMacSymbolTranslatorContext context, ParseTreeNode node, bool isLvalue, TrimmedList <string> qualList)
        {
            context.PushState(node);

            var translator = new GMacValueAccessGenerator();//new GMacValueAccessGenerator(qualList, context, isLvalue, true);

            translator.SetContext(qualList, context, isLvalue, true);
            translator.Translate();

            context.PopState();

            var result = translator._generatedValueAccess;

            //MasterPool.Release(translator);

            return(result);
        }
        private LanguageValueAccess translate_Qualified_Identifier(ParseTreeNode node)
        {
            //If _QualList is not already filled, translate the current parse node into a list of identifiers
            if (_qualList == null)
            {
                _qualList = GenUtils.Translate_Qualified_Identifier(node);
            }

            //Lookup the first item of the translated list of identifiers within the current context
            LanguageSymbol symbol;

            var flag =
                _followScopeChain
                //? Context.LookupSymbolInOpenedDistinctScopes(_qualList.FirstItem, out symbol)
                ? Context.OpenedDistinctScopes().LookupSymbol(_qualList.FirstItem, out symbol)
                : Context.ActiveParentScope.LookupSymbol(_qualList.FirstItem, out symbol);

            if (flag == false)
            {
                return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Symbol name not recognized", RootParseNode));
            }

            //Ignore the first item from the list
            _qualList.IncreaseActiveStartOffset(1);

            if (_isLValue)
            {
                //This is an l-value
                switch (symbol.SymbolRoleName)
                {
                case RoleNames.StructureDataMember:
                case RoleNames.MacroParameter:
                case RoleNames.LocalVariable:
                    return(translate_StartAt_DataSymbol((SymbolDataStore)symbol));

                default:
                    return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("LValue symbol name not recognized", RootParseNode));
                }
            }

            //This is an r-value
            switch (symbol.SymbolRoleName)
            {
            case RoleNames.MacroParameter:
            case RoleNames.LocalVariable:
            case RoleNames.Constant:
                return(translate_StartAt_DataSymbol((SymbolDataStore)symbol));

            case RoleNames.FrameBasisVector:
            case RoleNames.BuiltinType:
            case RoleNames.FrameMultivector:
            case RoleNames.Structure:
            case RoleNames.Macro:
            case RoleNames.MacroTemplate:
            case RoleNames.Transform:
            case RoleNames.FrameSubspace:
                //case RoleNames.Binding:
                return(translate_StartAt_DirectSymbol(symbol));

            case RoleNames.Frame:
                return(translate_StartAt_FrameDefinition((GMacFrame)symbol));

            case RoleNames.Namespace:
                return(translate_StartAt_NamespaceDefinition((GMacNamespace)symbol));

            default:
                return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("RValue symbol name not recognized", RootParseNode));
            }
        }