Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modeling ASTs with FAST (mooseday13)

Modeling ASTs with FAST (mooseday13)

Yuriy Tymchuk

April 04, 2013
Tweet

More Decks by Yuriy Tymchuk

Other Decks in Science

Transcript

  1. MODELING ASTS WITH FAST
    Yuriy “Uko” Tymchuk

    View Slide

  2. MOOSE

    View Slide

  3. FAMIX

    View Slide

  4. FAMIX

    View Slide

  5. FAMIX
    Access
    Invocation

    View Slide

  6. PROBLEM?
    • Calculating metrics
    • Rule checking
    • Detecting duplication
    • Representing (eg. visualizing)
    • Language conversions
    • And more…

    View Slide

  7. can’t handle that!
    AST
    FAMIX
    we need

    View Slide

  8. FAST

    View Slide

  9. FAST
    0%
    25%
    50%
    75%
    100%
    Smalltalk Java

    View Slide

  10. FAST

    View Slide

  11. FAST IMPORTERS
    PetitParser

    View Slide

  12. MODEL

    View Slide

  13. GENERAL FAST DIAGRAM
    FASTBehaviouralEntity
    0..*
    statements
    0..1
    parentStatementBlock
    FASTStatement
    FASTNamedEntity
    name : String
    0..*
    parameters
    0..*
    localVariables
    FAMIXBehaviouralEntity
    0..1
    fastNamedBehaviouralEntity
    0..1
    famixBehaviouralEntity
    FAMIXNamedEntity
    0..*
    fastNamedEntities
    0..1
    famixNamedEntity
    FASTNamedBehaviouralEntity
    name : String
    FASTExpression
    0..1
    parentBehaviouralEntity
    0..1
    parentExpression**
    0..1
    parentStatement**
    FASTStatementBlock
    0..1
    parentBehaviouralEntity
    0..1
    statementBlock
    FASTVariableExpression
    0..1
    parentVariableExpression
    0..1
    variable
    FASTLiteral
    signature : string

    View Slide

  14. SMALLTALK FAST
    DIAGRAM
    FASTBehaviouralEntity
    0..*
    statements
    0..1
    parentStatementBlock
    FASTVariableExpression FASTLiteral
    signature : String
    FASTMessageSend
    kind
    selector
    isUnary()
    isBinary()
    isKey()
    cascaded()
    receiver()
    FASTStatement
    0..1
    parentExpression
    0..*
    arguments
    FASTAssignmentExpression
    0..1
    parentAssignmentExpression
    0..1
    variable
    FASTExpression
    0..1
    parentStatement 0..1
    expression
    FASTArrayExpression FASTCascade
    0..1
    parentCascade
    0..*
    messages
    0..1
    parentExpression
    0..1
    concreteReceiver
    0..1
    parentExpression
    0..1
    block
    FASTSmalltalkReturnStatement
    FASTSmalltalkExpressionStatement
    0..1
    parentStatement 0..1
    expression
    0..1
    parentExpression
    0..1
    expression
    FASTNamedEntity
    name : String
    0..*
    parameters
    0..*
    localVariables
    0..1
    parentVariableExpression
    0..1
    variable
    FASTBlockDefinition
    FAMIXBehaviouralEntity
    0..1
    fastNamedBehaviouralEntity
    0..1
    famixBehaviouralEntity
    FAMIXNamedEntity
    0..*
    fastNamedEntities
    0..1
    famixNamedEntity
    FASTNamedBehaviouralEntity
    name : String
    FASTNumberLiteral
    value : Number
    FASTCharacterLiteral
    value : Object
    FASTStringLiteral
    value : String
    FASTSymbolLiteral
    value : Object
    FASTArrayLiteral FASTByteArrayLiteral
    0..*
    contents
    0..*
    contents
    FASTBlockExpression
    0..1
    parentExpression
    0..*
    contents
    FASTBooleanLiteral
    value : Boolean
    FASTUndefinedLiteral
    0..1
    parentExpression
    0..1
    receiver
    0..1
    parentBehaviouralEntity
    FAMIXInvocation
    0..1
    messageSend
    0..1
    invocation
    FASTStatementBlock
    0..1
    parentBehaviouralEntity
    0..1
    statementBlock

    View Slide

  15. RB CASCADE DESIGN
    Cascade
    Message1 arguments…
    Message2 arguments…
    Message3 arguments…
    RECEIVER

    View Slide

  16. FAST CASCADE DESIGN
    Cascade
    RECEIVER
    Message1 arguments…
    Message2 arguments…
    Message3 arguments…

    View Slide

  17. SMALLTALK / JAVA
    COMPARISON
    0
    8
    15
    23
    30
    Statements
    Expression
    Smalltalk Java

    View Slide

  18. http://uko-on-code.blogspot.com

    View Slide

  19. JAVA FAST DIAGRAM
    FASTBehaviouralEntity
    0..*
    statements
    0..1
    parentStatementBlock
    FASTStatement
    FASTNamedEntity
    name : String
    0..*
    parameters
    0..*
    localVariables
    FAMIXBehaviouralEntity
    0..1
    fastNamedBehaviouralEntity
    0..1
    famixBehaviouralEntity
    FAMIXNamedEntity
    0..*
    fastNamedEntities
    0..1
    famixNamedEntity
    FASTNamedBehaviouralEntity
    name : String
    FASTExpression
    0..1
    parentBehaviouralEntity
    StatementBlock
    0..1
    parentBehaviouralEntity
    0..1
    statementBlock
    FASTVariableExpression
    0..1
    parentVariableExpression
    0..1
    variable
    FASTLiteral
    signature : string
    FASTJavaExpressionStatement
    FASTJavaReturnStatement
    0..1
    parentStatement
    0..1
    expression
    0..1
    parentStatement
    0..1
    expression
    FASTWhileStatement
    0..1
    parentStatement
    0..1
    condition
    0..1
    parentStatement
    0..1
    body
    FASTVariableDeclarationStatement
    FASTVariableDeclarator
    0..1
    parentStatement
    0..*
    declarators
    0..1
    variable
    0..1
    initializer
    FASTJavaIntegerLiteral FASTJavaBooleanLiteral FASTJavaStringLiteral
    FASTInfixOperation 0..1
    parentExpression
    0..1
    leftOperand
    0..1
    parentExpression
    0..1
    rightOperand

    View Slide

  20. FAST ANALYSES

    View Slide

  21. SYMBOL RESOLUTION
    #middleOf:and:
    b
    a
    sum
    ^st
    st
    :=
    sum +
    a b
    /
    sum 2
    middleOf: a and: b
    | sum |
    sum := a + b.
    ^ sum / 2

    View Slide

  22. SYMBOL RESOLUTION
    b
    a
    sum
    #middleOf:and:
    b
    a
    sum
    ^st
    st
    :=
    sum +
    a b
    /
    sum 2

    View Slide

  23. SYMBOL RESOLUTION
    b
    a
    sum
    #middleOf:and:
    b
    a
    sum
    ^st
    st
    :=
    sum +
    a b
    /
    sum 2

    View Slide

  24. RESOLVING SYMBOLS
    Scope
    • name-variable dictionary
    • parent scope
    • owner entity
    Scope
    • name-variable dictionary
    • parent scope
    • owner entity

    View Slide

  25. CALCULATING METRICS
    • nodes of a Kind
    • cyclomatic complexity
    Amount of something in code

    View Slide

  26. CALCULATING METRICS
    collection inject: initial into: [block]
    CollectorVisitor newWithSeed: initial andBlock: [block]

    View Slide

  27. CYCLOMATIC COMPLEXITY
    Each node knows it’s complexity contribution
    • Class = 0
    • ReturnStatement = 0
    • IfStatement = 1
    • WhileStatement = 1
    • MessageSend (#ifTrue:) = 1! ! ! ! calculated at runtime
    • MessageSend (#detect:ifNone:) = 2
    • “for ... else” statement = 2!! ! ! ! python

    View Slide

  28. FAST CONTRIBUTION
    http://smalltalkhub.com/#!/~YuriyTymchuk/FAST
    https://github.com/Uko/FAST
    https://ci.inria.fr/moose/job/FAST-On-Moose

    View Slide

  29. FAST GSOC
    FAST Java Model Tree models visualization
    The idea behind this project is to
    develop an inter active tree
    visualization that will gradually
    improve analysis of the underlying
    model.
    The goal of this project is to create a
    Java version of FAST.

    View Slide

  30. THANKS
    Stéphane Ducasse
    Nicolas Anquetil
    RMoD team

    View Slide

  31. FAST

    View Slide