Exemplo n.º 1
0
bool Parameter::PerformSema( SemaAnalyzer& sema )
{
    DeclSpecs decl_specs;

    //
    // If there was a problem evaluating the declaration specifiers we can't
    // continue
    //
    if( !decl_specs.AnalyzeDeclSpecs( m_DeclarationSpecifiers, sema ) )
        return false;

    //
    // Check some other things about the specifiers
    //
    if( decl_specs.IsInline() )
        // Don't return here, this is a recoverable error
        sema.Error( "Can't have an 'inline' specifier on a parameter" );

    if( decl_specs.IsStatic() )
        sema.Error( "Can't have a 'static' specifier on a non-global "
                    "variable" );

    if( !decl_specs.IsUniform() )
        decl_specs.SetIsVarying( true );

    if( !(decl_specs.IsIn() || decl_specs.IsOut() ) )
        // parameters are in by default
        decl_specs.SetIsIn( true );

    Type base_type = decl_specs.GetType();
    if( base_type == Type::UNKNOWN )
    {
        sema.Error( "No type in declaration specifier" );
        return false;
    }
    else if( base_type == Type::VOID )
    {
        sema.Error( "Can't declare variables of void type" );
        return false;
    }
    ArrayExtents array_extents =ArraySpecifier::GetArrayExtents(
                                                               m_ArraySpecifers,
                                                               sema );

    if( array_extents.empty() &&
        m_DefaultValue &&
        m_DefaultValue->CanReduceToExpression() )
        m_DefaultValue->ReduceToExpression();

    if( m_DefaultValue )
        m_DefaultValue->PerformSema( sema, CompleteType( base_type,
                                                         array_extents ) );

    if( !decl_specs.IsConst() &&
        base_type == Type::STRING )
        sema.Error( "Variables of type string must be const" );

    if( m_DefaultValue &&
        m_DefaultValue->GetArrayExtents() != array_extents )
        sema.Error( "Default parameter value has mismatching array extents" );

    Semantic semantic = m_SemanticSpecifier ? m_SemanticSpecifier->GetSemantic()
                                            : Semantic();

    m_Variable = std::make_shared<Variable>( CompleteType( base_type,
                                                           array_extents ),
                                             std::move(semantic),
                                             decl_specs.IsConst(),
                                             decl_specs.IsUniform(),
                                             decl_specs.IsVarying(),
                                             decl_specs.IsIn(),
                                             decl_specs.IsOut(),
                                             false, //Isn't global
                                             true,  //Is a param
                                             GenericValue(),
                                             m_Identifier );

    m_Type = CompleteType( base_type,
                           std::move(array_extents) );
    return true;
}
Exemplo n.º 2
0
 GenericValue
 CodeGenContext::runCode()
 {
     // TODO Implementar
     return GenericValue();
 }