Esempio n. 1
0
        private IRValue ASTValueToIR(IRRule rule, ASTRValue astValue)
        {
            if (astValue is ASTConstantValue)
            {
                return(ASTConstantToIR(astValue as ASTConstantValue));
            }
            else if (astValue is ASTLocalVar)
            {
                var astVar = astValue as ASTLocalVar;
                // TODO - compiler error if type resolution fails
                var type = astVar.Type != null?Context.LookupType(astVar.Type) : null;

                var ruleVar = rule.FindOrAddVariable(astVar.Name, type);

                return(new IRVariable
                {
                    Index = ruleVar.Index,
                    Type = type,
                    Location = astValue.Location
                });
            }
            else
            {
                throw new InvalidOperationException("Cannot convert unknown AST value type to IR");
            }
        }
Esempio n. 2
0
        private IRValue ASTValueToIR(IRRule rule, ASTRValue astValue)
        {
            if (astValue is ASTConstantValue)
            {
                return(ASTConstantToIR(astValue as ASTConstantValue));
            }
            else if (astValue is ASTLocalVar)
            {
                var astVar = astValue as ASTLocalVar;
                // TODO - compiler error if type resolution fails
                ValueType type;
                if (astVar.Type != null)
                {
                    type = Context.LookupType(astVar.Type);
                    if (type == null)
                    {
                        Context.Log.Error(astVar.Location, DiagnosticCode.UnresolvedType,
                                          String.Format("Type \"{0}\" does not exist", astVar.Type));
                    }
                }
                else
                {
                    type = null;
                }

                var ruleVar = rule.FindOrAddVariable(astVar.Name, type);

                return(new IRVariable
                {
                    Index = ruleVar.Index,
                    Type = type,
                    Location = astValue.Location
                });
            }
            else
            {
                throw new InvalidOperationException("Cannot convert unknown AST value type to IR");
            }
        }