Modeling ASTs with FAST (mooseday13)

Modeling ASTs with FAST (mooseday13)

9847702de1f7f19db8c3e158325baa8e?s=128

Yuriy Tymchuk

April 04, 2013
Tweet

Transcript

  1. MODELING ASTS WITH FAST Yuriy “Uko” Tymchuk

  2. MOOSE

  3. FAMIX

  4. FAMIX

  5. FAMIX Access Invocation

  6. PROBLEM? • Calculating metrics • Rule checking • Detecting duplication

    • Representing (eg. visualizing) • Language conversions • And more…
  7. can’t handle that! AST FAMIX we need

  8. FAST

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

  10. FAST

  11. FAST IMPORTERS PetitParser

  12. MODEL

  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
  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
  15. RB CASCADE DESIGN Cascade Message1 arguments… Message2 arguments… Message3 arguments…

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

    arguments…
  17. SMALLTALK / JAVA COMPARISON 0 8 15 23 30 Statements

    Expression Smalltalk Java
  18. http://uko-on-code.blogspot.com

  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
  20. FAST ANALYSES

  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
  22. SYMBOL RESOLUTION b a sum #middleOf:and: b a sum ^st

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

    st := sum + a b / sum 2
  24. RESOLVING SYMBOLS Scope • name-variable dictionary • parent scope •

    owner entity Scope • name-variable dictionary • parent scope • owner entity
  25. CALCULATING METRICS • nodes of a Kind • cyclomatic complexity

    Amount of something in code
  26. CALCULATING METRICS collection inject: initial into: [block] CollectorVisitor newWithSeed: initial

    andBlock: [block]
  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
  28. FAST CONTRIBUTION http://smalltalkhub.com/#!/~YuriyTymchuk/FAST https://github.com/Uko/FAST https://ci.inria.fr/moose/job/FAST-On-Moose

  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.
  30. THANKS Stéphane Ducasse Nicolas Anquetil RMoD team

  31. FAST