Ejemplo n.º 1
0
        public override void ExitTypeReference([NotNull] SBP.TypeReferenceContext context)
        {
            var typename = context.GetChild(2).GetText();
            var type     = ParseTypeString(typename, false, true, (context.GetChild(2).Payload as Antlr4.Runtime.CommonToken));

            m_expressionData.Push(SBExpressionData.Constant(TypeReference.TypeType, type));
        }
Ejemplo n.º 2
0
 public override void ExitVariableDeclaratorWithoutAssignment([NotNull] SBP.VariableDeclaratorWithoutAssignmentContext context)
 {
     if (m_variableType != null)
     {
         if (m_variableType.Type.IsValueType)
         {
             m_variableInitializer = SBExpressionData.Constant(m_variableType, Activator.CreateInstance(m_variableType.Type));
         }
         else if (m_variableType.Type == typeof(string))
         {
             m_variableInitializer = SBExpressionData.Constant(m_variableType, null);
         }
         else if (m_variableType.Type.IsClass)
         {
             throw new NotImplementedException();
         }
     }
 }
Ejemplo n.º 3
0
 public override void ExitVariableDeclarator([NotNull] SBP.VariableDeclaratorContext context)
 {
     if (m_variableType != null)
     {
         //m_variableInitializer = ResolveIfIdentifier(m_variableInitializer, m_inFunctionScope);
         if (m_variableInitializer.IsError())
         {
             if (m_variableType.Type != typeof(VarSpecifiedType))
             {
                 object def = null;
                 if (m_variableType.Type.IsValueType)
                 {
                     def = Activator.CreateInstance(m_variableType.Type);
                 }
                 m_variableInitializer = SBExpressionData.Constant(m_variableType, def);
             }
             else
             {
                 // Just set the type to 'object' then.
                 m_variableInitializer = SBExpressionData.Constant(TypeReference.TypeObject, null);
             }
         }
         if (m_variableInitializer.IsConstant && m_variableInitializer.Value == null)
         {
             // Convert the null value to the type of the variable
             if (m_variableType.Type == typeof(string))
             {
                 m_variableInitializer = SBExpressionData.Constant(TypeReference.TypeString, null);
             }
         }
         else if (m_variableInitializer.IsAwaitExpression)
         {
             m_variableInitializer = new SBExpressionData(
                 this.MakeAwaitOperation(
                     m_variableInitializer.ExpressionCode, context, true, m_variableType.Type));
         }
         if (m_variableType.Type != typeof(VarSpecifiedType))
         {
             if (m_variableInitializer.IsValueType &&
                 m_variableInitializer.IsConstant &&
                 m_variableInitializer.Value == null)
             {
                 m_variableInitializer.NarrowGetValueType(m_variableType);
             }
             else if (m_variableType != m_variableInitializer.DataType && !m_variableType.Type.IsAssignableFrom(m_variableInitializer.DataType.Type))
             {
                 m_variableInitializer = this.CastProcedureAssignmentArgumentIfNeeded(m_variableType, m_variableInitializer);
                 if (m_variableInitializer.DataType.Type != m_variableType.Type)
                 {
                     if (m_variableInitializer.DataType.Type == typeof(object) && m_variableInitializer.SuggestsAutomaticTypeConversion)
                     {
                         m_variableInitializer = new SBExpressionData(
                             Expression.Convert(m_variableInitializer.ExpressionCode, m_variableType.Type));
                     }
                     else
                     {
                         m_variableInitializer.NarrowGetValueType();
                         if (m_variableInitializer.DataType.Type != m_variableType.Type)
                         {
                             //m_errors.SymanticError(context.Start.Line, context.Start.Column, false, "");
                             throw new ParsingErrorException(context.Start.Line, "Data Type", "Convertion of variable initializer is not implemented.");
                         }
                     }
                 }
             }
         }
         m_variables.Add(
             new NamedData <SBExpressionData>(
                 m_variableName,
                 m_variableInitializer));
         m_variableName        = null;
         m_variableInitializer = null;
     }
 }
 public override void ExitLiteralNull([NotNull] SBP.LiteralNullContext context)
 {
     m_expressionData.Push(SBExpressionData.Constant((TypeReference)typeof(object), null, context.Start));
 }
 public override void ExitLiteralString([NotNull] SBP.LiteralStringContext context)
 {
     m_expressionData.Push(SBExpressionData.Constant(TypeReference.TypeString, ParseStringLiteral(context.GetText(), context), context.Start));
 }