コード例 #1
0
        private CilSymbol Ensure(CilSymbolRef symbolRef)
        {
            CilSymbol literalDef = ResolveLiteral(symbolRef.Literal);
            CilSymbol typeDef    = ResolveTokenType(symbolRef.Type);
            CilSymbol def        = MergeDefs(literalDef, typeDef);

            if (def == null)
            {
                 def = new CilSymbol();
            }
            else if (symbolRef.Type != null && def.Type != null && def.Type != symbolRef.Type)
            {
                throw new InvalidOperationException("Incompatible symbol constraints.");
            }

            // Add token to a defintion
            if (symbolRef.Type != null)
            {
                def.Type = symbolRef.Type;
            }

            if (symbolRef.HasLiteral)
            {
                def.Literals.Add(symbolRef.Literal);
            }

            // Update index
            foreach (var literal in def.Literals)
            {
                ref2def[literal] = def;
            }

            if (def.Type != null)
            {
                ref2def[def.Type] = def;
            }

            return def;
        }
コード例 #2
0
        private CilSymbol Ensure(CilSymbolRef symbolRef)
        {
            CilSymbol literalDef = ResolveLiteral(symbolRef.Literal);
            CilSymbol typeDef    = ResolveTokenType(symbolRef.Type);
            CilSymbol def        = MergeDefs(literalDef, typeDef);

            if (def == null)
            {
                def = new CilSymbol();
            }
            else if (symbolRef.Type != null && def.Type != null && def.Type != symbolRef.Type)
            {
                throw new InvalidOperationException("Incompatible symbol constraints.");
            }

            // Add token to a defintion
            if (symbolRef.Type != null)
            {
                def.Type = symbolRef.Type;
            }

            if (symbolRef.HasLiteral)
            {
                def.Literals.Add(symbolRef.Literal);
            }

            // Update index
            foreach (var literal in def.Literals)
            {
                ref2def[literal] = def;
            }

            if (def.Type != null)
            {
                ref2def[def.Type] = def;
            }

            return(def);
        }
コード例 #3
0
        private CilSymbol MergeDefs(CilSymbol xDef, CilSymbol yDef)
        {
            if (xDef == null)
            {
                return(yDef);
            }

            if (yDef == null)
            {
                return(xDef);
            }

            if (xDef == yDef)
            {
                return(xDef);
            }

            if (xDef.Type != null &&
                yDef.Type != null &&
                xDef.Type != yDef.Type)
            {
                var msg = string.Format(
                    "Internal error: attemt to identify single token by two types: '{0}' and '{1}'",
                    xDef.Type,
                    yDef.Type);
                throw new InvalidOperationException(msg);
            }

            if (xDef.Type == null)
            {
                xDef.Type = yDef.Type;
            }

            xDef.Literals.UnionWith(yDef.Literals);

            return(xDef);
        }
コード例 #4
0
        private CilSymbol MergeDefs(CilSymbol xDef, CilSymbol yDef)
        {
            if (xDef == null)
            {
                return yDef;
            }

            if (yDef == null)
            {
                return xDef;
            }

            if (xDef == yDef)
            {
                return xDef;
            }

            if (xDef.Type != null
                && yDef.Type != null
                && xDef.Type != yDef.Type)
            {
                var msg = string.Format(
                    "Internal error: attemt to identify single token by two types: '{0}' and '{1}'",
                    xDef.Type,
                    yDef.Type);
                throw new InvalidOperationException(msg);
            }

            if (xDef.Type == null)
            {
                xDef.Type = yDef.Type;
            }

            xDef.Literals.UnionWith(yDef.Literals);

            return xDef;
        }
コード例 #5
0
ファイル: CilGrammar.cs プロジェクト: sucaba/IronTextLibrary
 private static bool IsSpecialSymbol(CilSymbol symbol)
 {
     return(symbol.Type == typeof(Exception));
 }
コード例 #6
0
        public Symbol GetSymbol(CilSymbolRef tid)
        {
            CilSymbol def = Resolve(tid);

            return(def == null ? null : def.Symbol);
        }